blob: 6e9b3db1a4f848d4cd728dd9c57510747461a7a1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
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)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200235# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237#ifdef FEAT_STL_OPT
238# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
239#endif
240#ifdef FEAT_WINDOWS
241# define PV_WFH OPT_WIN(WV_WFH)
242#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000243#ifdef FEAT_VERTSPLIT
244# define PV_WFW OPT_WIN(WV_WFW)
245#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200247#ifdef FEAT_CURSORBIND
248# define PV_CRBIND OPT_WIN(WV_CRBIND)
249#endif
250#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200251# define PV_COCU OPT_WIN(WV_COCU)
252# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000254
255/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256typedef enum
257{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000258 PV_NONE = 0,
259 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260} idopt_T;
261
262/*
263 * Options local to a window have a value local to a buffer and global to all
264 * buffers. Indicate this by setting "var" to VAR_WIN.
265 */
266#define VAR_WIN ((char_u *)-1)
267
268/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000269 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270 * Only to be used in option.c!
271 */
272static int p_ai;
273static int p_bin;
274#ifdef FEAT_MBYTE
275static int p_bomb;
276#endif
277#if defined(FEAT_QUICKFIX)
278static char_u *p_bh;
279static char_u *p_bt;
280#endif
281static int p_bl;
282static int p_ci;
283#ifdef FEAT_CINDENT
284static int p_cin;
285static char_u *p_cink;
286static char_u *p_cino;
287#endif
288#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
289static char_u *p_cinw;
290#endif
291#ifdef FEAT_COMMENTS
292static char_u *p_com;
293#endif
294#ifdef FEAT_FOLDING
295static char_u *p_cms;
296#endif
297#ifdef FEAT_INS_EXPAND
298static char_u *p_cpt;
299#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#ifdef FEAT_COMPL_FUNC
301static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000302static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304static int p_eol;
305static int p_et;
306#ifdef FEAT_MBYTE
307static char_u *p_fenc;
308#endif
309static char_u *p_ff;
310static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000311static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312#ifdef FEAT_AUTOCMD
313static char_u *p_ft;
314#endif
315static long p_iminsert;
316static long p_imsearch;
317#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
318static char_u *p_inex;
319#endif
320#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
321static char_u *p_inde;
322static char_u *p_indk;
323#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000324#if defined(FEAT_EVAL)
325static char_u *p_fex;
326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000327static int p_inf;
328static char_u *p_isk;
329#ifdef FEAT_CRYPT
330static char_u *p_key;
331#endif
332#ifdef FEAT_LISP
333static int p_lisp;
334#endif
335static int p_ml;
336static int p_ma;
337static int p_mod;
338static char_u *p_mps;
339static char_u *p_nf;
340#ifdef FEAT_OSFILETYPE
341static char_u *p_oft;
342#endif
343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
351#ifndef SHORT_FNAME
352static int p_sn;
353#endif
354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
376#ifdef FEAT_KEYMAP
377static char_u *p_keymap;
378#endif
379
380/* Saved values for when 'bin' is set. */
381static int p_et_nobin;
382static int p_ml_nobin;
383static long p_tw_nobin;
384static long p_wm_nobin;
385
386/* Saved values for when 'paste' is set */
387static long p_tw_nopaste;
388static long p_wm_nopaste;
389static long p_sts_nopaste;
390static int p_ai_nopaste;
391
392struct vimoption
393{
394 char *fullname; /* full option name */
395 char *shortname; /* permissible abbreviation */
396 long_u flags; /* see below */
397 char_u *var; /* global option: pointer to variable;
398 * window-local option: VAR_WIN;
399 * buffer-local option: global value */
400 idopt_T indir; /* global option: PV_NONE;
401 * local option: indirect option index */
402 char_u *def_val[2]; /* default values for variable (vi and vim) */
403#ifdef FEAT_EVAL
404 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000405# define SCRIPTID_INIT , 0
406#else
407# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#endif
409};
410
411#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
412#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
413
414/*
415 * Flags
416 */
417#define P_BOOL 0x01 /* the option is boolean */
418#define P_NUM 0x02 /* the option is numeric */
419#define P_STRING 0x04 /* the option is a string */
420#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000421 must use free_string_option() when
422 assigning new value. Not set if default is
423 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
425 never be used for local or hidden options! */
426#define P_NODEFAULT 0x40 /* don't set to default value */
427#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
428 use vim_free() when assigning new value */
429#define P_WAS_SET 0x100 /* option has been set/reset */
430#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
431#define P_VI_DEF 0x400 /* Use Vi default for Vim */
432#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
433
434 /* when option changed, what to display: */
435#define P_RSTAT 0x1000 /* redraw status lines */
436#define P_RWIN 0x2000 /* redraw current window */
437#define P_RBUF 0x4000 /* redraw current buffer */
438#define P_RALL 0x6000 /* redraw all windows */
439#define P_RCLR 0x7000 /* clear and redraw all */
440
441#define P_COMMA 0x8000 /* comma separated list */
442#define P_NODUP 0x10000L/* don't allow duplicate strings */
443#define P_FLAGLIST 0x20000L/* list of single-char flags */
444
445#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x80000L/* expand default value with _() */
447#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000448#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000449#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000450#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
451 side effects) */
Bram Moolenaar865242e2010-07-14 21:12:05 +0200452#define P_NO_ML 0x1000000L/* not allowed in modeline */
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)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200469# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +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 Moolenaar1a384422010-07-14 19:53:30 +0200777 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
778#ifdef FEAT_SYN_HL
779 (char_u *)VAR_WIN, PV_CC,
780#else
781 (char_u *)NULL, PV_NONE,
782#endif
783 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
785 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
788#ifdef FEAT_COMMENTS
789 (char_u *)&p_com, PV_COM,
790 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
791 (char_u *)0L}
792#else
793 (char_u *)NULL, PV_NONE,
794 {(char_u *)0L, (char_u *)0L}
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
798#ifdef FEAT_FOLDING
799 (char_u *)&p_cms, PV_CMS,
800 {(char_u *)"/*%s*/", (char_u *)0L}
801#else
802 (char_u *)NULL, PV_NONE,
803 {(char_u *)0L, (char_u *)0L}
804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000805 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000806 /* P_PRI_MKRC isn't needed here, optval_default()
807 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"compatible", "cp", P_BOOL|P_RALL,
809 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000810 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000811 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
812#ifdef FEAT_INS_EXPAND
813 (char_u *)&p_cpt, PV_CPT,
814 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
815#else
816 (char_u *)NULL, PV_NONE,
817 {(char_u *)0L, (char_u *)0L}
818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000819 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200820 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200821#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200822 (char_u *)VAR_WIN, PV_COCU,
823 {(char_u *)"", (char_u *)NULL}
824#else
825 (char_u *)NULL, PV_NONE,
826 {(char_u *)NULL, (char_u *)0L}
827#endif
828 SCRIPTID_INIT},
829 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
830#ifdef FEAT_CONCEAL
831 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200832#else
833 (char_u *)NULL, PV_NONE,
834#endif
835 {(char_u *)0L, (char_u *)0L}
836 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000837 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
838#ifdef FEAT_COMPL_FUNC
839 (char_u *)&p_cfu, PV_CFU,
840 {(char_u *)"", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000846 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
847#ifdef FEAT_INS_EXPAND
848 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000849 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)0L, (char_u *)0L}
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000855 {"confirm", "cf", P_BOOL|P_VI_DEF,
856#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
857 (char_u *)&p_confirm, PV_NONE,
858#else
859 (char_u *)NULL, PV_NONE,
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 {"conskey", "consk",P_BOOL|P_VI_DEF,
863#ifdef MSDOS
864 (char_u *)&p_consk, PV_NONE,
865#else
866 (char_u *)NULL, PV_NONE,
867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000869 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
870 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000872 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
873 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
875 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200876 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200877#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200878 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200879 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200880#else
881 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200882 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200883#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200884 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000885 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
886#ifdef FEAT_CSCOPE
887 (char_u *)&p_cspc, PV_NONE,
888#else
889 (char_u *)NULL, PV_NONE,
890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
893#ifdef FEAT_CSCOPE
894 (char_u *)&p_csprg, PV_NONE,
895 {(char_u *)"cscope", (char_u *)0L}
896#else
897 (char_u *)NULL, PV_NONE,
898 {(char_u *)0L, (char_u *)0L}
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
902#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
903 (char_u *)&p_csqf, PV_NONE,
904 {(char_u *)"", (char_u *)0L}
905#else
906 (char_u *)NULL, PV_NONE,
907 {(char_u *)0L, (char_u *)0L}
908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
911#ifdef FEAT_CSCOPE
912 (char_u *)&p_cst, PV_NONE,
913#else
914 (char_u *)NULL, PV_NONE,
915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
918#ifdef FEAT_CSCOPE
919 (char_u *)&p_csto, PV_NONE,
920#else
921 (char_u *)NULL, PV_NONE,
922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csverbose, PV_NONE,
927#else
928 (char_u *)NULL, PV_NONE,
929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000930 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200931 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
932#ifdef FEAT_CURSORBIND
933 (char_u *)VAR_WIN, PV_CRBIND,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000938 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
939#ifdef FEAT_SYN_HL
940 (char_u *)VAR_WIN, PV_CUC,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000945 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
946#ifdef FEAT_SYN_HL
947 (char_u *)VAR_WIN, PV_CUL,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"debug", NULL, P_STRING|P_VI_DEF,
953 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
956#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000957 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000958 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959#else
960 (char_u *)NULL, PV_NONE,
961 {(char_u *)NULL, (char_u *)0L}
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
965#ifdef FEAT_MBYTE
966 (char_u *)&p_deco, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
972#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000973 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974#else
975 (char_u *)NULL, PV_NONE,
976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
979#ifdef FEAT_DIFF
980 (char_u *)VAR_WIN, PV_DIFF,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
986#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
987 (char_u *)&p_dex, PV_NONE,
988 {(char_u *)"", (char_u *)0L}
989#else
990 (char_u *)NULL, PV_NONE,
991 {(char_u *)0L, (char_u *)0L}
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
995#ifdef FEAT_DIFF
996 (char_u *)&p_dip, PV_NONE,
997 {(char_u *)"filler", (char_u *)NULL}
998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)"", (char_u *)NULL}
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1004#ifdef FEAT_DIGRAPHS
1005 (char_u *)&p_dg, PV_NONE,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1011 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1014 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"eadirection", "ead", P_STRING|P_VI_DEF,
1017#ifdef FEAT_VERTSPLIT
1018 (char_u *)&p_ead, PV_NONE,
1019 {(char_u *)"both", (char_u *)0L}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)NULL, (char_u *)0L}
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1026 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001028 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029#ifdef FEAT_MBYTE
1030 (char_u *)&p_enc, PV_NONE,
1031 {(char_u *)ENC_DFLT, (char_u *)0L}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)0L, (char_u *)0L}
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1038 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1041 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001044 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1047 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1050#ifdef FEAT_QUICKFIX
1051 (char_u *)&p_ef, PV_NONE,
1052 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)NULL, (char_u *)0L}
1056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1059#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001060 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062#else
1063 (char_u *)NULL, PV_NONE,
1064 {(char_u *)NULL, (char_u *)0L}
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"esckeys", "ek", P_BOOL|P_VIM,
1068 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1071#ifdef FEAT_AUTOCMD
1072 (char_u *)&p_ei, PV_NONE,
1073#else
1074 (char_u *)NULL, PV_NONE,
1075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1078 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1081 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1084#ifdef FEAT_MBYTE
1085 (char_u *)&p_fenc, PV_FENC,
1086 {(char_u *)"", (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1093#ifdef FEAT_MBYTE
1094 (char_u *)&p_fencs, PV_NONE,
1095 {(char_u *)"ucs-bom", (char_u *)0L}
1096#else
1097 (char_u *)NULL, PV_NONE,
1098 {(char_u *)0L, (char_u *)0L}
1099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1102 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1105 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1107 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001108 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_AUTOCMD
1110 (char_u *)&p_ft, PV_FT,
1111 {(char_u *)"", (char_u *)0L}
1112#else
1113 (char_u *)NULL, PV_NONE,
1114 {(char_u *)0L, (char_u *)0L}
1115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1118#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1119 (char_u *)&p_fcs, PV_NONE,
1120 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1121#else
1122 (char_u *)NULL, PV_NONE,
1123 {(char_u *)"", (char_u *)0L}
1124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1127#ifdef FEAT_FKMAP
1128 (char_u *)&p_fkmap, PV_NONE,
1129#else
1130 (char_u *)NULL, PV_NONE,
1131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 {"flash", "fl", P_BOOL|P_VI_DEF,
1134 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#ifdef FEAT_FOLDING
1137 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1138 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1141 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1144 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1147# ifdef FEAT_EVAL
1148 (char_u *)VAR_WIN, PV_FDE,
1149 {(char_u *)"0", (char_u *)NULL}
1150# else
1151 (char_u *)NULL, PV_NONE,
1152 {(char_u *)NULL, (char_u *)0L}
1153# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1156 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1159 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001160 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1162 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1165 P_RWIN|P_COMMA|P_NODUP,
1166 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 {(char_u *)"{{{,}}}", (char_u *)NULL}
1168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1170 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1173 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1176 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1179 (char_u *)&p_fdo, PV_NONE,
1180 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1183# ifdef FEAT_EVAL
1184 (char_u *)VAR_WIN, PV_FDT,
1185 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001186# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001189# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001192 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001193#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001194 (char_u *)&p_fex, PV_FEX,
1195 {(char_u *)"", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)0L, (char_u *)0L}
1199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1202 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1204 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001205 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1206 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1208 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1210 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001212 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1213#ifdef HAVE_FSYNC
1214 (char_u *)&p_fs, PV_NONE,
1215 {(char_u *)TRUE, (char_u *)0L}
1216#else
1217 (char_u *)NULL, PV_NONE,
1218 {(char_u *)FALSE, (char_u *)0L}
1219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1222 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"graphic", "gr", P_BOOL|P_VI_DEF,
1225 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1228#ifdef FEAT_QUICKFIX
1229 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231#else
1232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
1234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1237#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001238 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 {
1240# ifdef WIN3264
1241 /* may be changed to "grep -n" in os_win32.c */
1242 (char_u *)"findstr /n",
1243# else
1244# ifdef UNIX
1245 /* Add an extra file name so that grep will always
1246 * insert a file name in the match line. */
1247 (char_u *)"grep -n $* /dev/null",
1248# else
1249# ifdef VMS
1250 (char_u *)"SEARCH/NUMBERS ",
1251# else
1252 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253# endif
1254# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257#else
1258 (char_u *)NULL, PV_NONE,
1259 {(char_u *)NULL, (char_u *)0L}
1260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001261 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1263#ifdef CURSOR_SHAPE
1264 (char_u *)&p_guicursor, PV_NONE,
1265 {
1266# ifdef FEAT_GUI
1267 (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",
1268# else /* MSDOS or Win32 console */
1269 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1270# endif
1271 (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 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1278#ifdef FEAT_GUI
1279 (char_u *)&p_guifont, 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 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1287#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1288 (char_u *)&p_guifontset, PV_NONE,
1289 {(char_u *)"", (char_u *)0L}
1290#else
1291 (char_u *)NULL, PV_NONE,
1292 {(char_u *)NULL, (char_u *)0L}
1293#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001294 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1296#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1297 (char_u *)&p_guifontwide, PV_NONE,
1298 {(char_u *)"", (char_u *)0L}
1299#else
1300 (char_u *)NULL, PV_NONE,
1301 {(char_u *)NULL, (char_u *)0L}
1302#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001303 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001305#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306 (char_u *)&p_ghr, PV_NONE,
1307#else
1308 (char_u *)NULL, PV_NONE,
1309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001312#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 (char_u *)&p_go, PV_NONE,
1314# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001315 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001317 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318# endif
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)NULL, (char_u *)0L}
1322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324 {"guipty", NULL, P_BOOL|P_VI_DEF,
1325#if defined(FEAT_GUI)
1326 (char_u *)&p_guipty, PV_NONE,
1327#else
1328 (char_u *)NULL, PV_NONE,
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001331 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001332#if defined(FEAT_GUI_TABLINE)
1333 (char_u *)&p_gtl, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001340 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001341#if defined(FEAT_GUI_TABLINE)
1342 (char_u *)&p_gtt, PV_NONE,
1343 {(char_u *)"", (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)NULL, (char_u *)0L}
1347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1350 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1353 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"helpheight", "hh", P_NUM|P_VI_DEF,
1357#ifdef FEAT_WINDOWS
1358 (char_u *)&p_hh, PV_NONE,
1359#else
1360 (char_u *)NULL, PV_NONE,
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1364#ifdef FEAT_MULTI_LANG
1365 (char_u *)&p_hlg, PV_NONE,
1366 {(char_u *)"", (char_u *)0L}
1367#else
1368 (char_u *)NULL, PV_NONE,
1369 {(char_u *)0L, (char_u *)0L}
1370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 {"hidden", "hid", P_BOOL|P_VI_DEF,
1373 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1376 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1378 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"history", "hi", P_NUM|P_VIM,
1380 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001382 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1383#ifdef FEAT_RIGHTLEFT
1384 (char_u *)&p_hkmap, PV_NONE,
1385#else
1386 (char_u *)NULL, PV_NONE,
1387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1390#ifdef FEAT_RIGHTLEFT
1391 (char_u *)&p_hkmapp, PV_NONE,
1392#else
1393 (char_u *)NULL, PV_NONE,
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1397 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001398 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 {"icon", NULL, P_BOOL|P_VI_DEF,
1400#ifdef FEAT_TITLE
1401 (char_u *)&p_icon, PV_NONE,
1402#else
1403 (char_u *)NULL, PV_NONE,
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {"iconstring", NULL, P_STRING|P_VI_DEF,
1407#ifdef FEAT_TITLE
1408 (char_u *)&p_iconstring, PV_NONE,
1409#else
1410 (char_u *)NULL, PV_NONE,
1411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001412 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1414 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001415 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001417#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 (char_u *)&p_imak, PV_NONE,
1419#else
1420 (char_u *)NULL, PV_NONE,
1421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001422 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1424#ifdef USE_IM_CONTROL
1425 (char_u *)&p_imcmdline, PV_NONE,
1426#else
1427 (char_u *)NULL, PV_NONE,
1428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1431#ifdef USE_IM_CONTROL
1432 (char_u *)&p_imdisable, PV_NONE,
1433#else
1434 (char_u *)NULL, PV_NONE,
1435#endif
1436#ifdef __sgi
1437 {(char_u *)TRUE, (char_u *)0L}
1438#else
1439 {(char_u *)FALSE, (char_u *)0L}
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"iminsert", "imi", P_NUM|P_VI_DEF,
1443 (char_u *)&p_iminsert, PV_IMI,
1444#ifdef B_IMODE_IM
1445 {(char_u *)B_IMODE_IM, (char_u *)0L}
1446#else
1447 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"imsearch", "ims", P_NUM|P_VI_DEF,
1451 (char_u *)&p_imsearch, PV_IMS,
1452#ifdef B_IMODE_IM
1453 {(char_u *)B_IMODE_IM, (char_u *)0L}
1454#else
1455 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1459#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001460 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1462#else
1463 (char_u *)NULL, PV_NONE,
1464 {(char_u *)0L, (char_u *)0L}
1465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1468#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1469 (char_u *)&p_inex, PV_INEX,
1470 {(char_u *)"", (char_u *)0L}
1471#else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)0L, (char_u *)0L}
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1477 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1480#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1481 (char_u *)&p_inde, PV_INDE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1489#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1490 (char_u *)&p_indk, PV_INDK,
1491 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)0L, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"infercase", "inf", P_BOOL|P_VI_DEF,
1498 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1501 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1504 (char_u *)&p_isf, PV_NONE,
1505 {
1506#ifdef BACKSLASH_IN_FILENAME
1507 /* Excluded are: & and ^ are special in cmd.exe
1508 * ( and ) are used in text separating fnames */
1509 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1510#else
1511# ifdef AMIGA
1512 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1513# else
1514# ifdef VMS
1515 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1516# else /* UNIX et al. */
1517# ifdef EBCDIC
1518 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1519# else
1520 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1521# endif
1522# endif
1523# endif
1524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001525 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1527 (char_u *)&p_isi, PV_NONE,
1528 {
1529#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1530 (char_u *)"@,48-57,_,128-167,224-235",
1531#else
1532# ifdef EBCDIC
1533 /* TODO: EBCDIC Check this! @ == isalpha()*/
1534 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1535 "112-120,128,140-142,156,158,172,"
1536 "174,186,191,203-207,219-225,235-239,"
1537 "251-254",
1538# else
1539 (char_u *)"@,48-57,_,192-255",
1540# endif
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1544 (char_u *)&p_isk, PV_ISK,
1545 {
1546#ifdef EBCDIC
1547 (char_u *)"@,240-249,_",
1548 /* TODO: EBCDIC Check this! @ == isalpha()*/
1549 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1550 "112-120,128,140-142,156,158,172,"
1551 "174,186,191,203-207,219-225,235-239,"
1552 "251-254",
1553#else
1554 (char_u *)"@,48-57,_",
1555# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1556 (char_u *)"@,48-57,_,128-167,224-235"
1557# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001558 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559# endif
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1563 (char_u *)&p_isp, PV_NONE,
1564 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001565#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1566 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 || defined(VMS)
1568 (char_u *)"@,~-255",
1569#else
1570# ifdef EBCDIC
1571 /* all chars above 63 are printable */
1572 (char_u *)"63-255",
1573# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001574 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575# endif
1576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001577 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1579 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1582#ifdef FEAT_CRYPT
1583 (char_u *)&p_key, PV_KEY,
1584 {(char_u *)"", (char_u *)0L}
1585#else
1586 (char_u *)NULL, PV_NONE,
1587 {(char_u *)0L, (char_u *)0L}
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001590 {"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 +00001591#ifdef FEAT_KEYMAP
1592 (char_u *)&p_keymap, PV_KMAP,
1593 {(char_u *)"", (char_u *)0L}
1594#else
1595 (char_u *)NULL, PV_NONE,
1596 {(char_u *)"", (char_u *)0L}
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1600#ifdef FEAT_VISUAL
1601 (char_u *)&p_km, PV_NONE,
1602#else
1603 (char_u *)NULL, PV_NONE,
1604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001607 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001608 {
1609#if defined(MSDOS) || defined(MSWIN)
1610 (char_u *)":help",
1611#else
1612#ifdef VMS
1613 (char_u *)"help",
1614#else
1615# if defined(OS2)
1616 (char_u *)"view /",
1617# else
1618# ifdef USEMAN_S
1619 (char_u *)"man -s",
1620# else
1621 (char_u *)"man",
1622# endif
1623# endif
1624#endif
1625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001626 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1628#ifdef FEAT_LANGMAP
1629 (char_u *)&p_langmap, PV_NONE,
1630 {(char_u *)"", /* unmatched } */
1631#else
1632 (char_u *)NULL, PV_NONE,
1633 {(char_u *)NULL,
1634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001636 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1638 (char_u *)&p_lm, PV_NONE,
1639#else
1640 (char_u *)NULL, PV_NONE,
1641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1644#ifdef FEAT_WINDOWS
1645 (char_u *)&p_ls, PV_NONE,
1646#else
1647 (char_u *)NULL, PV_NONE,
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1651 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1654#ifdef FEAT_LINEBREAK
1655 (char_u *)VAR_WIN, PV_LBR,
1656#else
1657 (char_u *)NULL, PV_NONE,
1658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1661 (char_u *)&Rows, PV_NONE,
1662 {
1663#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1664 (char_u *)25L,
1665#else
1666 (char_u *)24L,
1667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001668 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1670#ifdef FEAT_GUI
1671 (char_u *)&p_linespace, PV_NONE,
1672#else
1673 (char_u *)NULL, PV_NONE,
1674#endif
1675#ifdef FEAT_GUI_W32
1676 {(char_u *)1L, (char_u *)0L}
1677#else
1678 {(char_u *)0L, (char_u *)0L}
1679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001680 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"lisp", NULL, P_BOOL|P_VI_DEF,
1682#ifdef FEAT_LISP
1683 (char_u *)&p_lisp, PV_LISP,
1684#else
1685 (char_u *)NULL, PV_NONE,
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1689#ifdef FEAT_LISP
1690 (char_u *)&p_lispwords, PV_NONE,
1691 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1692#else
1693 (char_u *)NULL, PV_NONE,
1694 {(char_u *)"", (char_u *)0L}
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1698 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1701 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1704 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001706#ifdef FEAT_GUI_MAC
1707 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1708 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"magic", NULL, P_BOOL|P_VI_DEF,
1712 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001713 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001714 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715#ifdef FEAT_QUICKFIX
1716 (char_u *)&p_mef, PV_NONE,
1717 {(char_u *)"", (char_u *)0L}
1718#else
1719 (char_u *)NULL, PV_NONE,
1720 {(char_u *)NULL, (char_u *)0L}
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1724#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001725 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726# ifdef VMS
1727 {(char_u *)"MMS", (char_u *)0L}
1728# else
1729 {(char_u *)"make", (char_u *)0L}
1730# endif
1731#else
1732 (char_u *)NULL, PV_NONE,
1733 {(char_u *)NULL, (char_u *)0L}
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1737 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"matchtime", "mat", P_NUM|P_VI_DEF,
1741 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001743 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1744#ifdef FEAT_MBYTE
1745 (char_u *)&p_mco, PV_NONE,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1751#ifdef FEAT_EVAL
1752 (char_u *)&p_mfd, PV_NONE,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1758 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {"maxmem", "mm", P_NUM|P_VI_DEF,
1761 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1763 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001764 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1765 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1768 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1770 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 {"menuitems", "mis", P_NUM|P_VI_DEF,
1772#ifdef FEAT_MENU
1773 (char_u *)&p_mis, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"mesg", NULL, P_BOOL|P_VI_DEF,
1779 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001781 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001782#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001783 (char_u *)&p_msm, PV_NONE,
1784 {(char_u *)"460000,2000,500", (char_u *)0L}
1785#else
1786 (char_u *)NULL, PV_NONE,
1787 {(char_u *)0L, (char_u *)0L}
1788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"modeline", "ml", P_BOOL|P_VIM,
1791 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"modelines", "mls", P_NUM|P_VI_DEF,
1794 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1797 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1800 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 {"more", NULL, P_BOOL|P_VIM,
1803 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1806 (char_u *)&p_mouse, PV_NONE,
1807 {
1808#if defined(MSDOS) || defined(WIN3264)
1809 (char_u *)"a",
1810#else
1811 (char_u *)"",
1812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1815#ifdef FEAT_GUI
1816 (char_u *)&p_mousef, PV_NONE,
1817#else
1818 (char_u *)NULL, PV_NONE,
1819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1822#ifdef FEAT_GUI
1823 (char_u *)&p_mh, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1829 (char_u *)&p_mousem, PV_NONE,
1830 {
1831#if defined(MSDOS) || defined(MSWIN)
1832 (char_u *)"popup",
1833#else
1834# if defined(MACOS)
1835 (char_u *)"popup_setpos",
1836# else
1837 (char_u *)"extend",
1838# endif
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1842#ifdef FEAT_MOUSESHAPE
1843 (char_u *)&p_mouseshape, PV_NONE,
1844 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1845#else
1846 (char_u *)NULL, PV_NONE,
1847 {(char_u *)NULL, (char_u *)0L}
1848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1851 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001853 {"mzquantum", "mzq", P_NUM,
1854#ifdef FEAT_MZSCHEME
1855 (char_u *)&p_mzq, PV_NONE,
1856#else
1857 (char_u *)NULL, PV_NONE,
1858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"novice", NULL, P_BOOL|P_VI_DEF,
1861 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1864 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 {(char_u *)"octal,hex", (char_u *)0L}
1866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1868 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001870 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1871#ifdef FEAT_LINEBREAK
1872 (char_u *)VAR_WIN, PV_NUW,
1873#else
1874 (char_u *)NULL, PV_NONE,
1875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001877 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001878#ifdef FEAT_COMPL_FUNC
1879 (char_u *)&p_ofu, PV_OFU,
1880 {(char_u *)"", (char_u *)0L}
1881#else
1882 (char_u *)NULL, PV_NONE,
1883 {(char_u *)0L, (char_u *)0L}
1884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"open", NULL, P_BOOL|P_VI_DEF,
1887 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001889 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1890#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1891 (char_u *)&p_odev, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
1895 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001897 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1898 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"optimize", "opt", P_BOOL|P_VI_DEF,
1901 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1904#ifdef FEAT_OSFILETYPE
1905 (char_u *)&p_oft, PV_OFT,
1906 {(char_u *)DFLT_OFT, (char_u *)0L}
1907#else
1908 (char_u *)NULL, PV_NONE,
1909 {(char_u *)0L, (char_u *)0L}
1910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"paragraphs", "para", P_STRING|P_VI_DEF,
1913 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001914 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001916 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1920 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1923#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1924 (char_u *)&p_pex, PV_NONE,
1925 {(char_u *)"", (char_u *)0L}
1926#else
1927 (char_u *)NULL, PV_NONE,
1928 {(char_u *)0L, (char_u *)0L}
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001931 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001935 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {
1937#if defined AMIGA || defined MSDOS || defined MSWIN
1938 (char_u *)".,,",
1939#else
1940# if defined(__EMX__)
1941 (char_u *)".,/emx/include,,",
1942# else /* Unix, probably */
1943 (char_u *)".,/usr/include,,",
1944# endif
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1948 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001950 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1952 (char_u *)&p_pvh, PV_NONE,
1953#else
1954 (char_u *)NULL, PV_NONE,
1955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1958#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1959 (char_u *)VAR_WIN, PV_PVW,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001964 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965#ifdef FEAT_PRINTER
1966 (char_u *)&p_pdev, 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 {"printencoding", "penc", P_STRING|P_VI_DEF,
1974#ifdef FEAT_POSTSCRIPT
1975 (char_u *)&p_penc, PV_NONE,
1976 {(char_u *)"", (char_u *)0L}
1977#else
1978 (char_u *)NULL, PV_NONE,
1979 {(char_u *)NULL, (char_u *)0L}
1980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1983#ifdef FEAT_POSTSCRIPT
1984 (char_u *)&p_pexpr, PV_NONE,
1985 {(char_u *)"", (char_u *)0L}
1986#else
1987 (char_u *)NULL, PV_NONE,
1988 {(char_u *)NULL, (char_u *)0L}
1989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"printfont", "pfn", P_STRING|P_VI_DEF,
1992#ifdef FEAT_PRINTER
1993 (char_u *)&p_pfn, PV_NONE,
1994 {
1995# ifdef MSWIN
1996 (char_u *)"Courier_New:h10",
1997# else
1998 (char_u *)"courier",
1999# endif
2000 (char_u *)0L}
2001#else
2002 (char_u *)NULL, PV_NONE,
2003 {(char_u *)NULL, (char_u *)0L}
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2007#ifdef FEAT_PRINTER
2008 (char_u *)&p_header, PV_NONE,
2009 {(char_u *)N_("%<%f%h%m%=Page %N"), (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 Moolenaar8299df92004-07-10 09:47:34 +00002015 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2016#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2017 (char_u *)&p_pmcs, 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 Moolenaar8299df92004-07-10 09:47:34 +00002024 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2025#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2026 (char_u *)&p_pmfn, PV_NONE,
2027 {(char_u *)"", (char_u *)0L}
2028#else
2029 (char_u *)NULL, PV_NONE,
2030 {(char_u *)NULL, (char_u *)0L}
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2034#ifdef FEAT_PRINTER
2035 (char_u *)&p_popt, PV_NONE,
2036 {(char_u *)"", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002043 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002045 {"pumheight", "ph", P_NUM|P_VI_DEF,
2046#ifdef FEAT_INS_EXPAND
2047 (char_u *)&p_ph, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002052 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2053#ifdef FEAT_TEXTOBJ
2054 (char_u *)&p_qe, PV_QE,
2055 {(char_u *)"\\", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)NULL, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2062 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"redraw", NULL, P_BOOL|P_VI_DEF,
2065 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002067 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2068#ifdef FEAT_RELTIME
2069 (char_u *)&p_rdt, PV_NONE,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002074 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2075 (char_u *)VAR_WIN, PV_RNU,
2076 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"remap", NULL, P_BOOL|P_VI_DEF,
2078 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"report", NULL, P_NUM|P_VI_DEF,
2081 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2084#ifdef WIN3264
2085 (char_u *)&p_rs, PV_NONE,
2086#else
2087 (char_u *)NULL, PV_NONE,
2088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2091#ifdef FEAT_RIGHTLEFT
2092 (char_u *)&p_ri, PV_NONE,
2093#else
2094 (char_u *)NULL, PV_NONE,
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2098#ifdef FEAT_RIGHTLEFT
2099 (char_u *)VAR_WIN, PV_RL,
2100#else
2101 (char_u *)NULL, PV_NONE,
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2105#ifdef FEAT_RIGHTLEFT
2106 (char_u *)VAR_WIN, PV_RLC,
2107 {(char_u *)"search", (char_u *)NULL}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2114#ifdef FEAT_CMDL_INFO
2115 (char_u *)&p_ru, PV_NONE,
2116#else
2117 (char_u *)NULL, PV_NONE,
2118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2121#ifdef FEAT_STL_OPT
2122 (char_u *)&p_ruf, PV_NONE,
2123#else
2124 (char_u *)NULL, PV_NONE,
2125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2128 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2132 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2135#ifdef FEAT_SCROLLBIND
2136 (char_u *)VAR_WIN, PV_SCBIND,
2137#else
2138 (char_u *)NULL, PV_NONE,
2139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002140 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2142 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2145 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2148#ifdef FEAT_SCROLLBIND
2149 (char_u *)&p_sbo, PV_NONE,
2150 {(char_u *)"ver,jump", (char_u *)0L}
2151#else
2152 (char_u *)NULL, PV_NONE,
2153 {(char_u *)0L, (char_u *)0L}
2154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"sections", "sect", P_STRING|P_VI_DEF,
2157 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2159 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2161 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163 {"selection", "sel", P_STRING|P_VI_DEF,
2164#ifdef FEAT_VISUAL
2165 (char_u *)&p_sel, PV_NONE,
2166#else
2167 (char_u *)NULL, PV_NONE,
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 {(char_u *)"inclusive", (char_u *)0L}
2170 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2172#ifdef FEAT_VISUAL
2173 (char_u *)&p_slm, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2179#ifdef FEAT_SESSION
2180 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002181 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)0L, (char_u *)0L}
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2189 (char_u *)&p_sh, PV_NONE,
2190 {
2191#ifdef VMS
2192 (char_u *)"-",
2193#else
2194# if defined(MSDOS)
2195 (char_u *)"command",
2196# else
2197# if defined(WIN16)
2198 (char_u *)"command.com",
2199# else
2200# if defined(WIN3264)
2201 (char_u *)"", /* set in set_init_1() */
2202# else
2203# if defined(OS2)
2204 (char_u *)"cmd.exe",
2205# else
2206# if defined(ARCHIE)
2207 (char_u *)"gos",
2208# else
2209 (char_u *)"sh",
2210# endif
2211# endif
2212# endif
2213# endif
2214# endif
2215#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_shcf, PV_NONE,
2219 {
2220#if defined(MSDOS) || defined(MSWIN)
2221 (char_u *)"/c",
2222#else
2223# if defined(OS2)
2224 (char_u *)"/c",
2225# else
2226 (char_u *)"-c",
2227# endif
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2231#ifdef FEAT_QUICKFIX
2232 (char_u *)&p_sp, PV_NONE,
2233 {
2234#if defined(UNIX) || defined(OS2)
2235# ifdef ARCHIE
2236 (char_u *)"2>",
2237# else
2238 (char_u *)"| tee",
2239# endif
2240#else
2241 (char_u *)">",
2242#endif
2243 (char_u *)0L}
2244#else
2245 (char_u *)NULL, PV_NONE,
2246 {(char_u *)0L, (char_u *)0L}
2247#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002249 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2250 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2253 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2256#ifdef BACKSLASH_IN_FILENAME
2257 (char_u *)&p_ssl, PV_NONE,
2258#else
2259 (char_u *)NULL, PV_NONE,
2260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002262 {"shelltemp", "stmp", P_BOOL,
2263 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"shelltype", "st", P_NUM|P_VI_DEF,
2266#ifdef AMIGA
2267 (char_u *)&p_st, PV_NONE,
2268#else
2269 (char_u *)NULL, PV_NONE,
2270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2273 (char_u *)&p_sxq, PV_NONE,
2274 {
2275#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2276 (char_u *)"\"",
2277#else
2278 (char_u *)"",
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2282 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2285 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2288 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)"", (char_u *)"filnxtToO"}
2290 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shortname", "sn", P_BOOL|P_VI_DEF,
2292#ifdef SHORT_FNAME
2293 (char_u *)NULL, PV_NONE,
2294#else
2295 (char_u *)&p_sn, PV_SN,
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2299#ifdef FEAT_LINEBREAK
2300 (char_u *)&p_sbr, PV_NONE,
2301#else
2302 (char_u *)NULL, PV_NONE,
2303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"showcmd", "sc", P_BOOL|P_VIM,
2306#ifdef FEAT_CMDL_INFO
2307 (char_u *)&p_sc, PV_NONE,
2308#else
2309 (char_u *)NULL, PV_NONE,
2310#endif
2311 {(char_u *)FALSE,
2312#ifdef UNIX
2313 (char_u *)FALSE
2314#else
2315 (char_u *)TRUE
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2319 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2322 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"showmode", "smd", P_BOOL|P_VIM,
2325 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002327 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2328#ifdef FEAT_WINDOWS
2329 (char_u *)&p_stal, PV_NONE,
2330#else
2331 (char_u *)NULL, PV_NONE,
2332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2335 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2338 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2341 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2344 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2347#ifdef FEAT_SMARTINDENT
2348 (char_u *)&p_si, PV_SI,
2349#else
2350 (char_u *)NULL, PV_NONE,
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2354 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2357 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2360 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002362 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002363#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002364 (char_u *)VAR_WIN, PV_SPELL,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002369 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002370#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002371 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002372 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +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 Moolenaar0d9c26d2005-07-02 23:19:16 +00002378 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002379#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002380 (char_u *)&p_spf, PV_SPF,
2381 {(char_u *)"", (char_u *)0L}
2382#else
2383 (char_u *)NULL, PV_NONE,
2384 {(char_u *)0L, (char_u *)0L}
2385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002386 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002387 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002388#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002389 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002390 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002391#else
2392 (char_u *)NULL, PV_NONE,
2393 {(char_u *)0L, (char_u *)0L}
2394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002396 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002397#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002398 (char_u *)&p_sps, PV_NONE,
2399 {(char_u *)"best", (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2406#ifdef FEAT_WINDOWS
2407 (char_u *)&p_sb, PV_NONE,
2408#else
2409 (char_u *)NULL, PV_NONE,
2410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"splitright", "spr", P_BOOL|P_VI_DEF,
2413#ifdef FEAT_VERTSPLIT
2414 (char_u *)&p_spr, PV_NONE,
2415#else
2416 (char_u *)NULL, PV_NONE,
2417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2420 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2423#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002424 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425#else
2426 (char_u *)NULL, PV_NONE,
2427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2430 (char_u *)&p_su, PV_NONE,
2431 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002434#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)&p_sua, PV_SUA,
2436 {(char_u *)"", (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 Moolenaar071d4272004-06-13 20:20:40 +00002442 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2443 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"swapsync", "sws", P_STRING|P_VI_DEF,
2446 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2449 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002451 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2452#ifdef FEAT_SYN_HL
2453 (char_u *)&p_smc, PV_SMC,
2454 {(char_u *)3000L, (char_u *)0L}
2455#else
2456 (char_u *)NULL, PV_NONE,
2457 {(char_u *)0L, (char_u *)0L}
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002460 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461#ifdef FEAT_SYN_HL
2462 (char_u *)&p_syn, PV_SYN,
2463 {(char_u *)"", (char_u *)0L}
2464#else
2465 (char_u *)NULL, PV_NONE,
2466 {(char_u *)0L, (char_u *)0L}
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002469 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2470#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002471 (char_u *)&p_tal, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002476 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2477#ifdef FEAT_WINDOWS
2478 (char_u *)&p_tpm, PV_NONE,
2479#else
2480 (char_u *)NULL, PV_NONE,
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2484 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2487 (char_u *)&p_tbs, PV_NONE,
2488#ifdef VMS /* binary searching doesn't appear to work on VMS */
2489 {(char_u *)0L, (char_u *)0L}
2490#else
2491 {(char_u *)TRUE, (char_u *)0L}
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"taglength", "tl", P_NUM|P_VI_DEF,
2495 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"tagrelative", "tr", P_BOOL|P_VIM,
2498 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002501 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {
2503#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2504 (char_u *)"./tags,./TAGS,tags,TAGS",
2505#else
2506 (char_u *)"./tags,tags",
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2510 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2513 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2516#ifdef FEAT_ARABIC
2517 (char_u *)&p_tbidi, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2523#ifdef FEAT_MBYTE
2524 (char_u *)&p_tenc, PV_NONE,
2525 {(char_u *)"", (char_u *)0L}
2526#else
2527 (char_u *)NULL, PV_NONE,
2528 {(char_u *)0L, (char_u *)0L}
2529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"terse", NULL, P_BOOL|P_VI_DEF,
2532 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"textauto", "ta", P_BOOL|P_VIM,
2535 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2537 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2539 (char_u *)&p_tx, PV_TX,
2540 {
2541#ifdef USE_CRNL
2542 (char_u *)TRUE,
2543#else
2544 (char_u *)FALSE,
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002547 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2551#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002552 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553#else
2554 (char_u *)NULL, PV_NONE,
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2558 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"timeout", "to", P_BOOL|P_VI_DEF,
2561 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2564 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"title", NULL, P_BOOL|P_VI_DEF,
2567#ifdef FEAT_TITLE
2568 (char_u *)&p_title, PV_NONE,
2569#else
2570 (char_u *)NULL, PV_NONE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"titlelen", NULL, P_NUM|P_VI_DEF,
2574#ifdef FEAT_TITLE
2575 (char_u *)&p_titlelen, PV_NONE,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002580 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581#ifdef FEAT_TITLE
2582 (char_u *)&p_titleold, PV_NONE,
2583 {(char_u *)N_("Thanks for flying Vim"),
2584 (char_u *)0L}
2585#else
2586 (char_u *)NULL, PV_NONE,
2587 {(char_u *)0L, (char_u *)0L}
2588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"titlestring", NULL, P_STRING|P_VI_DEF,
2591#ifdef FEAT_TITLE
2592 (char_u *)&p_titlestring, PV_NONE,
2593#else
2594 (char_u *)NULL, PV_NONE,
2595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2598 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2599 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)"icons,tooltips", (char_u *)0L}
2601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002603#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2605 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607#endif
2608 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2609 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2612 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2615 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2618 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2621#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2622 (char_u *)&p_ttym, PV_NONE,
2623#else
2624 (char_u *)NULL, PV_NONE,
2625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2628 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2631 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002633 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2634#ifdef FEAT_PERSISTENT_UNDO
2635 (char_u *)&p_udir, PV_NONE,
2636 {(char_u *)".", (char_u *)0L}
2637#else
2638 (char_u *)NULL, PV_NONE,
2639 {(char_u *)0L, (char_u *)0L}
2640#endif
2641 SCRIPTID_INIT},
2642 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2643#ifdef FEAT_PERSISTENT_UNDO
2644 (char_u *)&p_udf, PV_UDF,
2645#else
2646 (char_u *)NULL, PV_NONE,
2647#endif
2648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"undolevels", "ul", P_NUM|P_VI_DEF,
2650 (char_u *)&p_ul, PV_NONE,
2651 {
2652#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2653 (char_u *)1000L,
2654#else
2655 (char_u *)100L,
2656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002658 {"undoreload", "ur", P_NUM|P_VI_DEF,
2659 (char_u *)&p_ur, PV_NONE,
2660 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"updatecount", "uc", P_NUM|P_VI_DEF,
2662 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"updatetime", "ut", P_NUM|P_VI_DEF,
2665 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"verbose", "vbs", P_NUM|P_VI_DEF,
2668 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002670 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2671 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2674#ifdef FEAT_SESSION
2675 (char_u *)&p_vdir, PV_NONE,
2676 {(char_u *)DFLT_VDIR, (char_u *)0L}
2677#else
2678 (char_u *)NULL, PV_NONE,
2679 {(char_u *)0L, (char_u *)0L}
2680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2683#ifdef FEAT_SESSION
2684 (char_u *)&p_vop, PV_NONE,
2685 {(char_u *)"folds,options,cursor", (char_u *)0L}
2686#else
2687 (char_u *)NULL, PV_NONE,
2688 {(char_u *)0L, (char_u *)0L}
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2692#ifdef FEAT_VIMINFO
2693 (char_u *)&p_viminfo, PV_NONE,
2694#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002695 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696#else
2697# ifdef AMIGA
2698 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002699 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002701 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702# endif
2703#endif
2704#else
2705 (char_u *)NULL, PV_NONE,
2706 {(char_u *)0L, (char_u *)0L}
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2710#ifdef FEAT_VIRTUALEDIT
2711 (char_u *)&p_ve, PV_NONE,
2712 {(char_u *)"", (char_u *)""}
2713#else
2714 (char_u *)NULL, PV_NONE,
2715 {(char_u *)0L, (char_u *)0L}
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2719 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"w300", NULL, P_NUM|P_VI_DEF,
2722 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"w1200", NULL, P_NUM|P_VI_DEF,
2725 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {"w9600", NULL, P_NUM|P_VI_DEF,
2728 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"warn", NULL, P_BOOL|P_VI_DEF,
2731 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2734 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2737 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"wildchar", "wc", P_NUM|P_VIM,
2740 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2742 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002743 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002745 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2747#ifdef FEAT_WILDIGN
2748 (char_u *)&p_wig, PV_NONE,
2749#else
2750 (char_u *)NULL, PV_NONE,
2751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002753 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2754 (char_u *)&p_wic, PV_NONE,
2755 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2757#ifdef FEAT_WILDMENU
2758 (char_u *)&p_wmnu, PV_NONE,
2759#else
2760 (char_u *)NULL, PV_NONE,
2761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2764 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002766 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2767#ifdef FEAT_CMDL_COMPL
2768 (char_u *)&p_wop, PV_NONE,
2769 {(char_u *)"", (char_u *)0L}
2770#else
2771 (char_u *)NULL, PV_NONE,
2772 {(char_u *)NULL, (char_u *)0L}
2773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2776#ifdef FEAT_WAK
2777 (char_u *)&p_wak, PV_NONE,
2778 {(char_u *)"menu", (char_u *)0L}
2779#else
2780 (char_u *)NULL, PV_NONE,
2781 {(char_u *)NULL, (char_u *)0L}
2782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002785 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"winheight", "wh", P_NUM|P_VI_DEF,
2788#ifdef FEAT_WINDOWS
2789 (char_u *)&p_wh, PV_NONE,
2790#else
2791 (char_u *)NULL, PV_NONE,
2792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002795#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 (char_u *)VAR_WIN, PV_WFH,
2797#else
2798 (char_u *)NULL, PV_NONE,
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002801 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2802#ifdef FEAT_VERTSPLIT
2803 (char_u *)VAR_WIN, PV_WFW,
2804#else
2805 (char_u *)NULL, PV_NONE,
2806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2809#ifdef FEAT_WINDOWS
2810 (char_u *)&p_wmh, PV_NONE,
2811#else
2812 (char_u *)NULL, PV_NONE,
2813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2816#ifdef FEAT_VERTSPLIT
2817 (char_u *)&p_wmw, PV_NONE,
2818#else
2819 (char_u *)NULL, PV_NONE,
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2823#ifdef FEAT_VERTSPLIT
2824 (char_u *)&p_wiw, PV_NONE,
2825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2830 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2833 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2836 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"write", NULL, P_BOOL|P_VI_DEF,
2839 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"writeany", "wa", P_BOOL|P_VI_DEF,
2842 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2845 (char_u *)&p_wb, PV_NONE,
2846 {
2847#ifdef FEAT_WRITEBACKUP
2848 (char_u *)TRUE,
2849#else
2850 (char_u *)FALSE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"writedelay", "wd", P_NUM|P_VI_DEF,
2854 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856
2857/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002858#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861
2862 p_term("t_AB", T_CAB)
2863 p_term("t_AF", T_CAF)
2864 p_term("t_AL", T_CAL)
2865 p_term("t_al", T_AL)
2866 p_term("t_bc", T_BC)
2867 p_term("t_cd", T_CD)
2868 p_term("t_ce", T_CE)
2869 p_term("t_cl", T_CL)
2870 p_term("t_cm", T_CM)
2871 p_term("t_Co", T_CCO)
2872 p_term("t_CS", T_CCS)
2873 p_term("t_cs", T_CS)
2874#ifdef FEAT_VERTSPLIT
2875 p_term("t_CV", T_CSV)
2876#endif
2877 p_term("t_ut", T_UT)
2878 p_term("t_da", T_DA)
2879 p_term("t_db", T_DB)
2880 p_term("t_DL", T_CDL)
2881 p_term("t_dl", T_DL)
2882 p_term("t_fs", T_FS)
2883 p_term("t_IE", T_CIE)
2884 p_term("t_IS", T_CIS)
2885 p_term("t_ke", T_KE)
2886 p_term("t_ks", T_KS)
2887 p_term("t_le", T_LE)
2888 p_term("t_mb", T_MB)
2889 p_term("t_md", T_MD)
2890 p_term("t_me", T_ME)
2891 p_term("t_mr", T_MR)
2892 p_term("t_ms", T_MS)
2893 p_term("t_nd", T_ND)
2894 p_term("t_op", T_OP)
2895 p_term("t_RI", T_CRI)
2896 p_term("t_RV", T_CRV)
2897 p_term("t_Sb", T_CSB)
2898 p_term("t_Sf", T_CSF)
2899 p_term("t_se", T_SE)
2900 p_term("t_so", T_SO)
2901 p_term("t_sr", T_SR)
2902 p_term("t_ts", T_TS)
2903 p_term("t_te", T_TE)
2904 p_term("t_ti", T_TI)
2905 p_term("t_ue", T_UE)
2906 p_term("t_us", T_US)
2907 p_term("t_vb", T_VB)
2908 p_term("t_ve", T_VE)
2909 p_term("t_vi", T_VI)
2910 p_term("t_vs", T_VS)
2911 p_term("t_WP", T_CWP)
2912 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002913 p_term("t_SI", T_CSI)
2914 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 p_term("t_xs", T_XS)
2916 p_term("t_ZH", T_CZH)
2917 p_term("t_ZR", T_CZR)
2918
2919/* terminal key codes are not in here */
2920
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 /* end marker */
2922 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923};
2924
2925#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2926
2927#ifdef FEAT_MBYTE
2928static char *(p_ambw_values[]) = {"single", "double", NULL};
2929#endif
2930static char *(p_bg_values[]) = {"light", "dark", NULL};
2931static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2932static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002933#ifdef FEAT_CRYPT
2934static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2935#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002936#ifdef FEAT_CMDL_COMPL
2937static char *(p_wop_values[]) = {"tagfile", NULL};
2938#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939#ifdef FEAT_WAK
2940static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2941#endif
2942static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2943#ifdef FEAT_VISUAL
2944static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2945static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2946#endif
2947#ifdef FEAT_VISUAL
2948static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2949#endif
2950#ifdef FEAT_BROWSE
2951static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2952#endif
2953#ifdef FEAT_SCROLLBIND
2954static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2955#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002956static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957#ifdef FEAT_VERTSPLIT
2958static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2959#endif
2960#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002961# ifdef FEAT_AUTOCMD
2962static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2963# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2967#endif
2968static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2969#ifdef FEAT_FOLDING
2970static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002971# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002973# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 NULL};
2975static char *(p_fcl_values[]) = {"all", NULL};
2976#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002977#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002978static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980
2981static void set_option_default __ARGS((int, int opt_flags, int compatible));
2982static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002983static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002984static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985static char_u *illegal_char __ARGS((char_u *, int));
2986static int string_to_key __ARGS((char_u *arg));
2987#ifdef FEAT_CMDWIN
2988static char_u *check_cedit __ARGS((void));
2989#endif
2990#ifdef FEAT_TITLE
2991static void did_set_title __ARGS((int icon));
2992#endif
2993static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2994static void didset_options __ARGS((void));
2995static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002996#if defined(FEAT_EVAL) || defined(PROTO)
2997static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2998#else
2999# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
3002static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
3003static 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));
3004static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003005#ifdef FEAT_SYN_HL
3006static int int_cmp __ARGS((const void *a, const void *b));
3007#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008#ifdef FEAT_CLIPBOARD
3009static char_u *check_clipboard_option __ARGS((void));
3010#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003011#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003012static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003013#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003014#ifdef FEAT_EVAL
3015static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003018static 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 +00003019static void check_redraw __ARGS((long_u flags));
3020static int findoption __ARGS((char_u *));
3021static int find_key_option __ARGS((char_u *));
3022static void showoptions __ARGS((int all, int opt_flags));
3023static int optval_default __ARGS((struct vimoption *, char_u *varp));
3024static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3025static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3026static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3027static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3028static int istermoption __ARGS((struct vimoption *));
3029static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3030static char_u *get_varp __ARGS((struct vimoption *));
3031static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3032static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3033#ifdef FEAT_LANGMAP
3034static void langmap_init __ARGS((void));
3035static void langmap_set __ARGS((void));
3036#endif
3037static void paste_option_changed __ARGS((void));
3038static void compatible_set __ARGS((void));
3039#ifdef FEAT_LINEBREAK
3040static void fill_breakat_flags __ARGS((void));
3041#endif
3042static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3043static int check_opt_strings __ARGS((char_u *val, char **values, int));
3044static int check_opt_wim __ARGS((void));
3045
3046/*
3047 * Initialize the options, first part.
3048 *
3049 * Called only once from main(), just after creating the first buffer.
3050 */
3051 void
3052set_init_1()
3053{
3054 char_u *p;
3055 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003056 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057
3058#ifdef FEAT_LANGMAP
3059 langmap_init();
3060#endif
3061
3062 /* Be Vi compatible by default */
3063 p_cp = TRUE;
3064
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003065 /* Use POSIX compatibility when $VIM_POSIX is set. */
3066 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003067 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003068 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003069 set_string_default("shm", (char_u *)"A");
3070 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003071
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 /*
3073 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003074 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003076 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3078# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003079 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003081 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003083 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084# endif
3085#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003086 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 set_string_default("sh", p);
3088
3089#ifdef FEAT_WILDIGN
3090 /*
3091 * Set the default for 'backupskip' to include environment variables for
3092 * temp files.
3093 */
3094 {
3095# ifdef UNIX
3096 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3097# else
3098 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3099# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003100 int len;
3101 garray_T ga;
3102 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104 ga_init2(&ga, 1, 100);
3105 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3106 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003107 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108# ifdef UNIX
3109 if (*names[n] == NUL)
3110 p = (char_u *)"/tmp";
3111 else
3112# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003113 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 if (p != NULL && *p != NUL)
3115 {
3116 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003117 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 if (ga_grow(&ga, len) == OK)
3119 {
3120 if (ga.ga_len > 0)
3121 STRCAT(ga.ga_data, ",");
3122 STRCAT(ga.ga_data, p);
3123 add_pathsep(ga.ga_data);
3124 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 ga.ga_len += len;
3126 }
3127 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003128 if (mustfree)
3129 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 }
3131 if (ga.ga_data != NULL)
3132 {
3133 set_string_default("bsk", ga.ga_data);
3134 vim_free(ga.ga_data);
3135 }
3136 }
3137#endif
3138
3139 /*
3140 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3141 */
3142 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003143 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003145#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3146 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3147#endif
3148 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003150 /* Use amount of memory available at this moment. */
3151 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152#else
3153# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003154 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003155 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003157 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158# endif
3159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003161 opt_idx = findoption((char_u *)"maxmem");
3162 if (opt_idx >= 0)
3163 {
3164#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3165 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3166 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3167#endif
3168 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3169 }
3170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 }
3172
3173#ifdef FEAT_GUI_W32
3174 /* force 'shortname' for Win32s */
3175 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003176 {
3177 opt_idx = findoption((char_u *)"shortname");
3178 if (opt_idx >= 0)
3179 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181#endif
3182
3183#ifdef FEAT_SEARCHPATH
3184 {
3185 char_u *cdpath;
3186 char_u *buf;
3187 int i;
3188 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003189 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190
3191 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003192 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 if (cdpath != NULL)
3194 {
3195 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3196 if (buf != NULL)
3197 {
3198 buf[0] = ','; /* start with ",", current dir first */
3199 j = 1;
3200 for (i = 0; cdpath[i] != NUL; ++i)
3201 {
3202 if (vim_ispathlistsep(cdpath[i]))
3203 buf[j++] = ',';
3204 else
3205 {
3206 if (cdpath[i] == ' ' || cdpath[i] == ',')
3207 buf[j++] = '\\';
3208 buf[j++] = cdpath[i];
3209 }
3210 }
3211 buf[j] = NUL;
3212 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003213 if (opt_idx >= 0)
3214 {
3215 options[opt_idx].def_val[VI_DEFAULT] = buf;
3216 options[opt_idx].flags |= P_DEF_ALLOCED;
3217 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003218 else
3219 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003221 if (mustfree)
3222 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 }
3224 }
3225#endif
3226
3227#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3228 /* Set print encoding on platforms that don't default to latin1 */
3229 set_string_default("penc",
3230# if defined(MSWIN) || defined(OS2)
3231 (char_u *)"cp1252"
3232# else
3233# ifdef VMS
3234 (char_u *)"dec-mcs"
3235# else
3236# ifdef EBCDIC
3237 (char_u *)"ebcdic-uk"
3238# else
3239# ifdef MAC
3240 (char_u *)"mac-roman"
3241# else /* HPUX */
3242 (char_u *)"hp-roman8"
3243# endif
3244# endif
3245# endif
3246# endif
3247 );
3248#endif
3249
3250#ifdef FEAT_POSTSCRIPT
3251 /* 'printexpr' must be allocated to be able to evaluate it. */
3252 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003253# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3254 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255# else
3256# ifdef VMS
3257 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3258
3259# else
3260 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3261# endif
3262# endif
3263 );
3264#endif
3265
3266 /*
3267 * Set all the options (except the terminal options) to their default
3268 * value. Also set the global value for local options.
3269 */
3270 set_options_default(0);
3271
3272#ifdef FEAT_GUI
3273 if (found_reverse_arg)
3274 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3275#endif
3276
3277 curbuf->b_p_initialized = TRUE;
3278 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3279 check_buf_options(curbuf);
3280 check_win_options(curwin);
3281 check_options();
3282
3283 /* Must be before option_expand(), because that one needs vim_isIDc() */
3284 didset_options();
3285
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003286#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003287 /* Use the current chartab for the generic chartab. */
3288 init_spell_chartab();
3289#endif
3290
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#ifdef FEAT_LINEBREAK
3292 /*
3293 * initialize the table for 'breakat'.
3294 */
3295 fill_breakat_flags();
3296#endif
3297
3298 /*
3299 * Expand environment variables and things like "~" for the defaults.
3300 * If option_expand() returns non-NULL the variable is expanded. This can
3301 * only happen for non-indirect options.
3302 * Also set the default to the expanded value, so ":set" does not list
3303 * them.
3304 * Don't set the P_ALLOCED flag, because we don't want to free the
3305 * default.
3306 */
3307 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3308 {
3309 if ((options[opt_idx].flags & P_GETTEXT)
3310 && options[opt_idx].var != NULL)
3311 p = (char_u *)_(*(char **)options[opt_idx].var);
3312 else
3313 p = option_expand(opt_idx, NULL);
3314 if (p != NULL && (p = vim_strsave(p)) != NULL)
3315 {
3316 *(char_u **)options[opt_idx].var = p;
3317 /* VIMEXP
3318 * Defaults for all expanded options are currently the same for Vi
3319 * and Vim. When this changes, add some code here! Also need to
3320 * split P_DEF_ALLOCED in two.
3321 */
3322 if (options[opt_idx].flags & P_DEF_ALLOCED)
3323 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3324 options[opt_idx].def_val[VI_DEFAULT] = p;
3325 options[opt_idx].flags |= P_DEF_ALLOCED;
3326 }
3327 }
3328
3329 /* Initialize the highlight_attr[] table. */
3330 highlight_changed();
3331
3332 save_file_ff(curbuf); /* Buffer is unchanged */
3333
3334 /* Parse default for 'wildmode' */
3335 check_opt_wim();
3336
3337#if defined(FEAT_ARABIC)
3338 /* Detect use of mlterm.
3339 * Mlterm is a terminal emulator akin to xterm that has some special
3340 * abilities (bidi namely).
3341 * NOTE: mlterm's author is being asked to 'set' a variable
3342 * instead of an environment variable due to inheritance.
3343 */
3344 if (mch_getenv((char_u *)"MLTERM") != NULL)
3345 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3346#endif
3347
3348#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3349 /* Parse default for 'fillchars'. */
3350 (void)set_chars_option(&p_fcs);
3351#endif
3352
3353#ifdef FEAT_CLIPBOARD
3354 /* Parse default for 'clipboard' */
3355 (void)check_clipboard_option();
3356#endif
3357
3358#ifdef FEAT_MBYTE
3359# if defined(WIN3264) && defined(FEAT_GETTEXT)
3360 /*
3361 * If $LANG isn't set, try to get a good value for it. This makes the
3362 * right language be used automatically. Don't do this for English.
3363 */
3364 if (mch_getenv((char_u *)"LANG") == NULL)
3365 {
3366 char buf[20];
3367
3368 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3369 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3370 * only the first two. */
3371 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3372 (LPTSTR)buf, 20);
3373 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3374 {
3375 /* There are a few exceptions (probably more) */
3376 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3377 STRCPY(buf, "zh_TW");
3378 else if (STRNICMP(buf, "chs", 3) == 0
3379 || STRNICMP(buf, "zhc", 3) == 0)
3380 STRCPY(buf, "zh_CN");
3381 else if (STRNICMP(buf, "jp", 2) == 0)
3382 STRCPY(buf, "ja");
3383 else
3384 buf[2] = NUL; /* truncate to two-letter code */
3385 vim_setenv("LANG", buf);
3386 }
3387 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003388# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003389# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003390 /* Moved to os_mac_conv.c to avoid dependency problems. */
3391 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003392# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393# endif
3394
3395 /* enc_locale() will try to find the encoding of the current locale. */
3396 p = enc_locale();
3397 if (p != NULL)
3398 {
3399 char_u *save_enc;
3400
3401 /* Try setting 'encoding' and check if the value is valid.
3402 * If not, go back to the default "latin1". */
3403 save_enc = p_enc;
3404 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003405 if (STRCMP(p_enc, "gb18030") == 0)
3406 {
3407 /* We don't support "gb18030", but "cp936" is a good substitute
3408 * for practical purposes, thus use that. It's not an alias to
3409 * still support conversion between gb18030 and utf-8. */
3410 p_enc = vim_strsave((char_u *)"cp936");
3411 vim_free(p);
3412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 if (mb_init() == NULL)
3414 {
3415 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416 if (opt_idx >= 0)
3417 {
3418 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3419 options[opt_idx].flags |= P_DEF_ALLOCED;
3420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003422#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3423 || defined(VMS)
3424 if (STRCMP(p_enc, "latin1") == 0
3425# ifdef FEAT_MBYTE
3426 || enc_utf8
3427# endif
3428 )
3429 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003430 /* Adjust the default for 'isprint' and 'iskeyword' to match
3431 * latin1. Also set the defaults for when 'nocompatible' is
3432 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003433 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003434 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003435 set_string_option_direct((char_u *)"isk", -1,
3436 ISK_LATIN1, OPT_FREE, SID_NONE);
3437 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 if (opt_idx >= 0)
3439 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003440 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003441 if (opt_idx >= 0)
3442 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003443 (void)init_chartab();
3444 }
3445#endif
3446
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447# if defined(WIN3264) && !defined(FEAT_GUI)
3448 /* Win32 console: When GetACP() returns a different value from
3449 * GetConsoleCP() set 'termencoding'. */
3450 if (GetACP() != GetConsoleCP())
3451 {
3452 char buf[50];
3453
3454 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3455 p_tenc = vim_strsave((char_u *)buf);
3456 if (p_tenc != NULL)
3457 {
3458 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003459 if (opt_idx >= 0)
3460 {
3461 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3462 options[opt_idx].flags |= P_DEF_ALLOCED;
3463 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 convert_setup(&input_conv, p_tenc, p_enc);
3465 convert_setup(&output_conv, p_enc, p_tenc);
3466 }
3467 else
3468 p_tenc = empty_option;
3469 }
3470# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003471# if defined(WIN3264) && defined(FEAT_MBYTE)
3472 /* $HOME may have characters in active code page. */
3473 init_homedir();
3474# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 }
3476 else
3477 {
3478 vim_free(p_enc);
3479 p_enc = save_enc;
3480 }
3481 }
3482#endif
3483
3484#ifdef FEAT_MULTI_LANG
3485 /* Set the default for 'helplang'. */
3486 set_helplang_default(get_mess_lang());
3487#endif
3488}
3489
3490/*
3491 * Set an option to its default value.
3492 * This does not take care of side effects!
3493 */
3494 static void
3495set_option_default(opt_idx, opt_flags, compatible)
3496 int opt_idx;
3497 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3498 int compatible; /* use Vi default value */
3499{
3500 char_u *varp; /* pointer to variable for current option */
3501 int dvi; /* index in def_val[] */
3502 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003503 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3505
3506 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3507 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003508 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 {
3510 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3511 if (flags & P_STRING)
3512 {
3513 /* Use set_string_option_direct() for local options to handle
3514 * freeing and allocating the value. */
3515 if (options[opt_idx].indir != PV_NONE)
3516 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003517 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518 else
3519 {
3520 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3521 free_string_option(*(char_u **)(varp));
3522 *(char_u **)varp = options[opt_idx].def_val[dvi];
3523 options[opt_idx].flags &= ~P_ALLOCED;
3524 }
3525 }
3526 else if (flags & P_NUM)
3527 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003528 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 win_comp_scroll(curwin);
3530 else
3531 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003532 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 /* May also set global value for local option. */
3534 if (both)
3535 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3536 *(long *)varp;
3537 }
3538 }
3539 else /* P_BOOL */
3540 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003541 /* the cast to long is required for Manx C, long_i is needed for
3542 * MSVC */
3543 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003544#ifdef UNIX
3545 /* 'modeline' defaults to off for root */
3546 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3547 *(int *)varp = FALSE;
3548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549 /* May also set global value for local option. */
3550 if (both)
3551 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3552 *(int *)varp;
3553 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003554
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003555 /* The default value is not insecure. */
3556 flagsp = insecure_flag(opt_idx, opt_flags);
3557 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 }
3559
3560#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003561 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003562#endif
3563}
3564
3565/*
3566 * Set all options (except terminal options) to their default value.
3567 */
3568 static void
3569set_options_default(opt_flags)
3570 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3571{
3572 int i;
3573#ifdef FEAT_WINDOWS
3574 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003575 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576#endif
3577
3578 for (i = 0; !istermoption(&options[i]); i++)
3579 if (!(options[i].flags & P_NODEFAULT))
3580 set_option_default(i, opt_flags, p_cp);
3581
3582#ifdef FEAT_WINDOWS
3583 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003584 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 win_comp_scroll(wp);
3586#else
3587 win_comp_scroll(curwin);
3588#endif
3589}
3590
3591/*
3592 * Set the Vi-default value of a string option.
3593 * Used for 'sh', 'backupskip' and 'term'.
3594 */
3595 void
3596set_string_default(name, val)
3597 char *name;
3598 char_u *val;
3599{
3600 char_u *p;
3601 int opt_idx;
3602
3603 p = vim_strsave(val);
3604 if (p != NULL) /* we don't want a NULL */
3605 {
3606 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003607 if (opt_idx >= 0)
3608 {
3609 if (options[opt_idx].flags & P_DEF_ALLOCED)
3610 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3611 options[opt_idx].def_val[VI_DEFAULT] = p;
3612 options[opt_idx].flags |= P_DEF_ALLOCED;
3613 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 }
3615}
3616
3617/*
3618 * Set the Vi-default value of a number option.
3619 * Used for 'lines' and 'columns'.
3620 */
3621 void
3622set_number_default(name, val)
3623 char *name;
3624 long val;
3625{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003626 int opt_idx;
3627
3628 opt_idx = findoption((char_u *)name);
3629 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003630 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631}
3632
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003633#if defined(EXITFREE) || defined(PROTO)
3634/*
3635 * Free all options.
3636 */
3637 void
3638free_all_options()
3639{
3640 int i;
3641
3642 for (i = 0; !istermoption(&options[i]); i++)
3643 {
3644 if (options[i].indir == PV_NONE)
3645 {
3646 /* global option: free value and default value. */
3647 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3648 free_string_option(*(char_u **)options[i].var);
3649 if (options[i].flags & P_DEF_ALLOCED)
3650 free_string_option(options[i].def_val[VI_DEFAULT]);
3651 }
3652 else if (options[i].var != VAR_WIN
3653 && (options[i].flags & P_STRING))
3654 /* buffer-local option: free global value */
3655 free_string_option(*(char_u **)options[i].var);
3656 }
3657}
3658#endif
3659
3660
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661/*
3662 * Initialize the options, part two: After getting Rows and Columns and
3663 * setting 'term'.
3664 */
3665 void
3666set_init_2()
3667{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003668 int idx;
3669
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670 /*
3671 * 'scroll' defaults to half the window height. Note that this default is
3672 * wrong when the window height changes.
3673 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003674 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003675 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003676 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003677 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 comp_col();
3679
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003680 /*
3681 * 'window' is only for backwards compatibility with Vi.
3682 * Default is Rows - 1.
3683 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003684 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003685 p_window = Rows - 1;
3686 set_number_default("window", Rows - 1);
3687
Bram Moolenaarf740b292006-02-16 22:11:02 +00003688 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003690 /*
3691 * If 'background' wasn't set by the user, try guessing the value,
3692 * depending on the terminal name. Only need to check for terminals
3693 * with a dark background, that can handle color.
3694 */
3695 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003696 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3697 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003699 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003700 /* don't mark it as set, when starting the GUI it may be
3701 * changed again */
3702 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 }
3704#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003705
3706#ifdef CURSOR_SHAPE
3707 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3708#endif
3709#ifdef FEAT_MOUSESHAPE
3710 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3711#endif
3712#ifdef FEAT_PRINTER
3713 (void)parse_printoptions(); /* parse 'printoptions' default value */
3714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715}
3716
3717/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003718 * Return "dark" or "light" depending on the kind of terminal.
3719 * This is just guessing! Recognized are:
3720 * "linux" Linux console
3721 * "screen.linux" Linux console with screen
3722 * "cygwin" Cygwin shell
3723 * "putty" Putty program
3724 * We also check the COLORFGBG environment variable, which is set by
3725 * rxvt and derivatives. This variable contains either two or three
3726 * values separated by semicolons; we want the last value in either
3727 * case. If this value is 0-6 or 8, our background is dark.
3728 */
3729 static char_u *
3730term_bg_default()
3731{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003732#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3733 /* DOS console nearly always black */
3734 return (char_u *)"dark";
3735#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003736 char_u *p;
3737
Bram Moolenaarf740b292006-02-16 22:11:02 +00003738 if (STRCMP(T_NAME, "linux") == 0
3739 || STRCMP(T_NAME, "screen.linux") == 0
3740 || STRCMP(T_NAME, "cygwin") == 0
3741 || STRCMP(T_NAME, "putty") == 0
3742 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3743 && (p = vim_strrchr(p, ';')) != NULL
3744 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3745 && p[2] == NUL))
3746 return (char_u *)"dark";
3747 return (char_u *)"light";
3748#endif
3749}
3750
3751/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752 * Initialize the options, part three: After reading the .vimrc
3753 */
3754 void
3755set_init_3()
3756{
3757#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3758/*
3759 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3760 * This is done after other initializations, where 'shell' might have been
3761 * set, but only if they have not been set before.
3762 */
3763 char_u *p;
3764 int idx_srr;
3765 int do_srr;
3766#ifdef FEAT_QUICKFIX
3767 int idx_sp;
3768 int do_sp;
3769#endif
3770
3771 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003772 if (idx_srr < 0)
3773 do_srr = FALSE;
3774 else
3775 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776#ifdef FEAT_QUICKFIX
3777 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003778 if (idx_sp < 0)
3779 do_sp = FALSE;
3780 else
3781 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782#endif
3783
3784 /*
3785 * Isolate the name of the shell:
3786 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3787 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003788 * But don't allow a space in the path, so that this works:
3789 * "/usr/bin/csh --rcfile ~/.cshrc"
3790 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003792#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 p = gettail(p_sh);
3794 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003795#else
3796 p = skiptowhite(p_sh);
3797 if (*p == NUL)
3798 {
3799 /* No white space, use the tail. */
3800 p = vim_strsave(gettail(p_sh));
3801 }
3802 else
3803 {
3804 char_u *p1, *p2;
3805
3806 /* Find the last path separator before the space. */
3807 p1 = p_sh;
3808 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3809 if (vim_ispathsep(*p2))
3810 p1 = p2 + 1;
3811 p = vim_strnsave(p1, (int)(p - p1));
3812 }
3813#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 if (p != NULL)
3815 {
3816 /*
3817 * Default for p_sp is "| tee", for p_srr is ">".
3818 * For known shells it is changed here to include stderr.
3819 */
3820 if ( fnamecmp(p, "csh") == 0
3821 || fnamecmp(p, "tcsh") == 0
3822# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3823 || fnamecmp(p, "csh.exe") == 0
3824 || fnamecmp(p, "tcsh.exe") == 0
3825# endif
3826 )
3827 {
3828#if defined(FEAT_QUICKFIX)
3829 if (do_sp)
3830 {
3831# ifdef WIN3264
3832 p_sp = (char_u *)">&";
3833# else
3834 p_sp = (char_u *)"|& tee";
3835# endif
3836 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3837 }
3838#endif
3839 if (do_srr)
3840 {
3841 p_srr = (char_u *)">&";
3842 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3843 }
3844 }
3845 else
3846# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3847 if ( fnamecmp(p, "sh") == 0
3848 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003849 || fnamecmp(p, "mksh") == 0
3850 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003852 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 || fnamecmp(p, "bash") == 0
3854# ifdef WIN3264
3855 || fnamecmp(p, "cmd") == 0
3856 || fnamecmp(p, "sh.exe") == 0
3857 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003858 || fnamecmp(p, "mksh.exe") == 0
3859 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003861 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 || fnamecmp(p, "bash.exe") == 0
3863 || fnamecmp(p, "cmd.exe") == 0
3864# endif
3865 )
3866# endif
3867 {
3868#if defined(FEAT_QUICKFIX)
3869 if (do_sp)
3870 {
3871# ifdef WIN3264
3872 p_sp = (char_u *)">%s 2>&1";
3873# else
3874 p_sp = (char_u *)"2>&1| tee";
3875# endif
3876 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3877 }
3878#endif
3879 if (do_srr)
3880 {
3881 p_srr = (char_u *)">%s 2>&1";
3882 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3883 }
3884 }
3885 vim_free(p);
3886 }
3887#endif
3888
3889#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3890 /*
3891 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3892 * This is done after other initializations, where 'shell' might have been
3893 * set, but only if they have not been set before. Default for p_shcf is
3894 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3895 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3896 * command.com. And for Win32 we need to set p_sxq instead.
3897 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003898 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 {
3900 int idx3;
3901
3902 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003903 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 {
3905 p_shcf = (char_u *)"-c";
3906 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3907 }
3908
3909# ifndef DJGPP
3910# ifdef WIN3264
3911 /* Somehow Win32 requires the quotes around the redirection too */
3912 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003913 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 {
3915 p_sxq = (char_u *)"\"";
3916 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3917 }
3918# else
3919 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003920 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 {
3922 p_shq = (char_u *)"\"";
3923 options[idx3].def_val[VI_DEFAULT] = p_shq;
3924 }
3925# endif
3926# endif
3927 }
3928#endif
3929
3930#ifdef FEAT_TITLE
3931 set_title_defaults();
3932#endif
3933}
3934
3935#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3936/*
3937 * When 'helplang' is still at its default value, set it to "lang".
3938 * Only the first two characters of "lang" are used.
3939 */
3940 void
3941set_helplang_default(lang)
3942 char_u *lang;
3943{
3944 int idx;
3945
3946 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3947 return;
3948 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003949 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 {
3951 if (options[idx].flags & P_ALLOCED)
3952 free_string_option(p_hlg);
3953 p_hlg = vim_strsave(lang);
3954 if (p_hlg == NULL)
3955 p_hlg = empty_option;
3956 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003957 {
3958 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3959 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3960 {
3961 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3962 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003965 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 options[idx].flags |= P_ALLOCED;
3967 }
3968}
3969#endif
3970
3971#ifdef FEAT_GUI
3972static char_u *gui_bg_default __ARGS((void));
3973
3974 static char_u *
3975gui_bg_default()
3976{
3977 if (gui_get_lightness(gui.back_pixel) < 127)
3978 return (char_u *)"dark";
3979 return (char_u *)"light";
3980}
3981
3982/*
3983 * Option initializations that can only be done after opening the GUI window.
3984 */
3985 void
3986init_gui_options()
3987{
3988 /* Set the 'background' option according to the lightness of the
3989 * background color, unless the user has set it already. */
3990 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3991 {
3992 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3993 highlight_changed();
3994 }
3995}
3996#endif
3997
3998#ifdef FEAT_TITLE
3999/*
4000 * 'title' and 'icon' only default to true if they have not been set or reset
4001 * in .vimrc and we can read the old value.
4002 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4003 * they can be reset. This reduces startup time when using X on a remote
4004 * machine.
4005 */
4006 void
4007set_title_defaults()
4008{
4009 int idx1;
4010 long val;
4011
4012 /*
4013 * If GUI is (going to be) used, we can always set the window title and
4014 * icon name. Saves a bit of time, because the X11 display server does
4015 * not need to be contacted.
4016 */
4017 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004018 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 {
4020#ifdef FEAT_GUI
4021 if (gui.starting || gui.in_use)
4022 val = TRUE;
4023 else
4024#endif
4025 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004026 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027 p_title = val;
4028 }
4029 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004030 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 {
4032#ifdef FEAT_GUI
4033 if (gui.starting || gui.in_use)
4034 val = TRUE;
4035 else
4036#endif
4037 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004038 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 p_icon = val;
4040 }
4041}
4042#endif
4043
4044/*
4045 * Parse 'arg' for option settings.
4046 *
4047 * 'arg' may be IObuff, but only when no errors can be present and option
4048 * does not need to be expanded with option_expand().
4049 * "opt_flags":
4050 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004051 * OPT_GLOBAL for ":setglobal"
4052 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004054 * OPT_WINONLY to only set window-local options
4055 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 *
4057 * returns FAIL if an error is detected, OK otherwise
4058 */
4059 int
4060do_set(arg, opt_flags)
4061 char_u *arg; /* option string (may be written to!) */
4062 int opt_flags;
4063{
4064 int opt_idx;
4065 char_u *errmsg;
4066 char_u errbuf[80];
4067 char_u *startarg;
4068 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4069 int nextchar; /* next non-white char after option name */
4070 int afterchar; /* character just after option name */
4071 int len;
4072 int i;
4073 long value;
4074 int key;
4075 long_u flags; /* flags for current option */
4076 char_u *varp = NULL; /* pointer to variable for current option */
4077 int did_show = FALSE; /* already showed one value */
4078 int adding; /* "opt+=arg" */
4079 int prepending; /* "opt^=arg" */
4080 int removing; /* "opt-=arg" */
4081 int cp_val = 0;
4082 char_u key_name[2];
4083
4084 if (*arg == NUL)
4085 {
4086 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004087 did_show = TRUE;
4088 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 }
4090
4091 while (*arg != NUL) /* loop to process all options */
4092 {
4093 errmsg = NULL;
4094 startarg = arg; /* remember for error message */
4095
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004096 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4097 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 {
4099 /*
4100 * ":set all" show all options.
4101 * ":set all&" set all options to their default value.
4102 */
4103 arg += 3;
4104 if (*arg == '&')
4105 {
4106 ++arg;
4107 /* Only for :set command set global value of local options. */
4108 set_options_default(OPT_FREE | opt_flags);
4109 }
4110 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004111 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004113 did_show = TRUE;
4114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004116 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 {
4118 showoptions(2, opt_flags);
4119 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004120 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 arg += 7;
4122 }
4123 else
4124 {
4125 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004126 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 prefix = 0;
4129 arg += 2;
4130 }
4131 else if (STRNCMP(arg, "inv", 3) == 0)
4132 {
4133 prefix = 2;
4134 arg += 3;
4135 }
4136
4137 /* find end of name */
4138 key = 0;
4139 if (*arg == '<')
4140 {
4141 nextchar = 0;
4142 opt_idx = -1;
4143 /* look out for <t_>;> */
4144 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4145 len = 5;
4146 else
4147 {
4148 len = 1;
4149 while (arg[len] != NUL && arg[len] != '>')
4150 ++len;
4151 }
4152 if (arg[len] != '>')
4153 {
4154 errmsg = e_invarg;
4155 goto skip;
4156 }
4157 arg[len] = NUL; /* put NUL after name */
4158 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4159 opt_idx = findoption(arg + 1);
4160 arg[len++] = '>'; /* restore '>' */
4161 if (opt_idx == -1)
4162 key = find_key_option(arg + 1);
4163 }
4164 else
4165 {
4166 len = 0;
4167 /*
4168 * The two characters after "t_" may not be alphanumeric.
4169 */
4170 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4171 len = 4;
4172 else
4173 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4174 ++len;
4175 nextchar = arg[len];
4176 arg[len] = NUL; /* put NUL after name */
4177 opt_idx = findoption(arg);
4178 arg[len] = nextchar; /* restore nextchar */
4179 if (opt_idx == -1)
4180 key = find_key_option(arg);
4181 }
4182
4183 /* remember character after option name */
4184 afterchar = arg[len];
4185
4186 /* skip white space, allow ":set ai ?" */
4187 while (vim_iswhite(arg[len]))
4188 ++len;
4189
4190 adding = FALSE;
4191 prepending = FALSE;
4192 removing = FALSE;
4193 if (arg[len] != NUL && arg[len + 1] == '=')
4194 {
4195 if (arg[len] == '+')
4196 {
4197 adding = TRUE; /* "+=" */
4198 ++len;
4199 }
4200 else if (arg[len] == '^')
4201 {
4202 prepending = TRUE; /* "^=" */
4203 ++len;
4204 }
4205 else if (arg[len] == '-')
4206 {
4207 removing = TRUE; /* "-=" */
4208 ++len;
4209 }
4210 }
4211 nextchar = arg[len];
4212
4213 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4214 {
4215 errmsg = (char_u *)N_("E518: Unknown option");
4216 goto skip;
4217 }
4218
4219 if (opt_idx >= 0)
4220 {
4221 if (options[opt_idx].var == NULL) /* hidden option: skip */
4222 {
4223 /* Only give an error message when requesting the value of
4224 * a hidden option, ignore setting it. */
4225 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4226 && (!(options[opt_idx].flags & P_BOOL)
4227 || nextchar == '?'))
4228 errmsg = (char_u *)N_("E519: Option not supported");
4229 goto skip;
4230 }
4231
4232 flags = options[opt_idx].flags;
4233 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4234 }
4235 else
4236 {
4237 flags = P_STRING;
4238 if (key < 0)
4239 {
4240 key_name[0] = KEY2TERMCAP0(key);
4241 key_name[1] = KEY2TERMCAP1(key);
4242 }
4243 else
4244 {
4245 key_name[0] = KS_KEY;
4246 key_name[1] = (key & 0xff);
4247 }
4248 }
4249
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004250 /* Skip all options that are not window-local (used when showing
4251 * an already loaded buffer in a window). */
4252 if ((opt_flags & OPT_WINONLY)
4253 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4254 goto skip;
4255
Bram Moolenaara3227e22006-03-08 21:32:40 +00004256 /* Skip all options that are window-local (used for :vimgrep). */
4257 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4258 && options[opt_idx].var == VAR_WIN)
4259 goto skip;
4260
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004261 /* Disallow changing some options from modelines. */
4262 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004263 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004264 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004265 {
4266 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4267 goto skip;
4268 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004269#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004270 /* In diff mode some options are overruled. This avoids that
4271 * 'foldmethod' becomes "marker" instead of "diff" and that
4272 * "wrap" gets set. */
4273 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004274 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004275 && (options[opt_idx].indir == PV_FDM
4276 || options[opt_idx].indir == PV_WRAP))
4277 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 }
4280
4281#ifdef HAVE_SANDBOX
4282 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004283 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 {
4285 errmsg = (char_u *)_(e_sandbox);
4286 goto skip;
4287 }
4288#endif
4289
4290 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4291 {
4292 arg += len;
4293 cp_val = p_cp;
4294 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4295 {
4296 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4297 {
4298 cp_val = FALSE;
4299 arg += 3;
4300 }
4301 else /* "opt&vi": set to Vi default */
4302 {
4303 cp_val = TRUE;
4304 arg += 2;
4305 }
4306 }
4307 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4308 && arg[1] != NUL && !vim_iswhite(arg[1]))
4309 {
4310 errmsg = e_trailing;
4311 goto skip;
4312 }
4313 }
4314
4315 /*
4316 * allow '=' and ':' as MSDOS command.com allows only one
4317 * '=' character per "set" command line. grrr. (jw)
4318 */
4319 if (nextchar == '?'
4320 || (prefix == 1
4321 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4322 && !(flags & P_BOOL)))
4323 {
4324 /*
4325 * print value
4326 */
4327 if (did_show)
4328 msg_putchar('\n'); /* cursor below last one */
4329 else
4330 {
4331 gotocmdline(TRUE); /* cursor at status line */
4332 did_show = TRUE; /* remember that we did a line */
4333 }
4334 if (opt_idx >= 0)
4335 {
4336 showoneopt(&options[opt_idx], opt_flags);
4337#ifdef FEAT_EVAL
4338 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004339 {
4340 /* Mention where the option was last set. */
4341 if (varp == options[opt_idx].var)
4342 last_set_msg(options[opt_idx].scriptID);
4343 else if ((int)options[opt_idx].indir & PV_WIN)
4344 last_set_msg(curwin->w_p_scriptID[
4345 (int)options[opt_idx].indir & PV_MASK]);
4346 else if ((int)options[opt_idx].indir & PV_BUF)
4347 last_set_msg(curbuf->b_p_scriptID[
4348 (int)options[opt_idx].indir & PV_MASK]);
4349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004350#endif
4351 }
4352 else
4353 {
4354 char_u *p;
4355
4356 p = find_termcode(key_name);
4357 if (p == NULL)
4358 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004359 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 goto skip;
4361 }
4362 else
4363 (void)show_one_termcode(key_name, p, TRUE);
4364 }
4365 if (nextchar != '?'
4366 && nextchar != NUL && !vim_iswhite(afterchar))
4367 errmsg = e_trailing;
4368 }
4369 else
4370 {
4371 if (flags & P_BOOL) /* boolean */
4372 {
4373 if (nextchar == '=' || nextchar == ':')
4374 {
4375 errmsg = e_invarg;
4376 goto skip;
4377 }
4378
4379 /*
4380 * ":set opt!": invert
4381 * ":set opt&": reset to default value
4382 * ":set opt<": reset to global value
4383 */
4384 if (nextchar == '!')
4385 value = *(int *)(varp) ^ 1;
4386 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004387 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 ((flags & P_VI_DEF) || cp_val)
4389 ? VI_DEFAULT : VIM_DEFAULT];
4390 else if (nextchar == '<')
4391 {
4392 /* For 'autoread' -1 means to use global value. */
4393 if ((int *)varp == &curbuf->b_p_ar
4394 && opt_flags == OPT_LOCAL)
4395 value = -1;
4396 else
4397 value = *(int *)get_varp_scope(&(options[opt_idx]),
4398 OPT_GLOBAL);
4399 }
4400 else
4401 {
4402 /*
4403 * ":set invopt": invert
4404 * ":set opt" or ":set noopt": set or reset
4405 */
4406 if (nextchar != NUL && !vim_iswhite(afterchar))
4407 {
4408 errmsg = e_trailing;
4409 goto skip;
4410 }
4411 if (prefix == 2) /* inv */
4412 value = *(int *)(varp) ^ 1;
4413 else
4414 value = prefix;
4415 }
4416
4417 errmsg = set_bool_option(opt_idx, varp, (int)value,
4418 opt_flags);
4419 }
4420 else /* numeric or string */
4421 {
4422 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4423 || prefix != 1)
4424 {
4425 errmsg = e_invarg;
4426 goto skip;
4427 }
4428
4429 if (flags & P_NUM) /* numeric */
4430 {
4431 /*
4432 * Different ways to set a number option:
4433 * & set to default value
4434 * < set to global value
4435 * <xx> accept special key codes for 'wildchar'
4436 * c accept any non-digit for 'wildchar'
4437 * [-]0-9 set number
4438 * other error
4439 */
4440 ++arg;
4441 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004442 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443 ((flags & P_VI_DEF) || cp_val)
4444 ? VI_DEFAULT : VIM_DEFAULT];
4445 else if (nextchar == '<')
4446 value = *(long *)get_varp_scope(&(options[opt_idx]),
4447 OPT_GLOBAL);
4448 else if (((long *)varp == &p_wc
4449 || (long *)varp == &p_wcm)
4450 && (*arg == '<'
4451 || *arg == '^'
4452 || ((!arg[1] || vim_iswhite(arg[1]))
4453 && !VIM_ISDIGIT(*arg))))
4454 {
4455 value = string_to_key(arg);
4456 if (value == 0 && (long *)varp != &p_wcm)
4457 {
4458 errmsg = e_invarg;
4459 goto skip;
4460 }
4461 }
4462 /* allow negative numbers (for 'undolevels') */
4463 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4464 {
4465 i = 0;
4466 if (*arg == '-')
4467 i = 1;
4468#ifdef HAVE_STRTOL
4469 value = strtol((char *)arg, NULL, 0);
4470 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4471 i += 2;
4472#else
4473 value = atol((char *)arg);
4474#endif
4475 while (VIM_ISDIGIT(arg[i]))
4476 ++i;
4477 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4478 {
4479 errmsg = e_invarg;
4480 goto skip;
4481 }
4482 }
4483 else
4484 {
4485 errmsg = (char_u *)N_("E521: Number required after =");
4486 goto skip;
4487 }
4488
4489 if (adding)
4490 value = *(long *)varp + value;
4491 if (prepending)
4492 value = *(long *)varp * value;
4493 if (removing)
4494 value = *(long *)varp - value;
4495 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004496 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004497 }
4498 else if (opt_idx >= 0) /* string */
4499 {
4500 char_u *save_arg = NULL;
4501 char_u *s = NULL;
4502 char_u *oldval; /* previous value if *varp */
4503 char_u *newval;
4504 char_u *origval;
4505 unsigned newlen;
4506 int comma;
4507 int bs;
4508 int new_value_alloced; /* new string option
4509 was allocated */
4510
4511 /* When using ":set opt=val" for a global option
4512 * with a local value the local value will be
4513 * reset, use the global value here. */
4514 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004515 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 varp = options[opt_idx].var;
4517
4518 /* The old value is kept until we are sure that the
4519 * new value is valid. */
4520 oldval = *(char_u **)varp;
4521 if (nextchar == '&') /* set to default val */
4522 {
4523 newval = options[opt_idx].def_val[
4524 ((flags & P_VI_DEF) || cp_val)
4525 ? VI_DEFAULT : VIM_DEFAULT];
4526 if ((char_u **)varp == &p_bg)
4527 {
4528 /* guess the value of 'background' */
4529#ifdef FEAT_GUI
4530 if (gui.in_use)
4531 newval = gui_bg_default();
4532 else
4533#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004534 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004535 }
4536
4537 /* expand environment variables and ~ (since the
4538 * default value was already expanded, only
4539 * required when an environment variable was set
4540 * later */
4541 if (newval == NULL)
4542 newval = empty_option;
4543 else
4544 {
4545 s = option_expand(opt_idx, newval);
4546 if (s == NULL)
4547 s = newval;
4548 newval = vim_strsave(s);
4549 }
4550 new_value_alloced = TRUE;
4551 }
4552 else if (nextchar == '<') /* set to global val */
4553 {
4554 newval = vim_strsave(*(char_u **)get_varp_scope(
4555 &(options[opt_idx]), OPT_GLOBAL));
4556 new_value_alloced = TRUE;
4557 }
4558 else
4559 {
4560 ++arg; /* jump to after the '=' or ':' */
4561
4562 /*
4563 * Set 'keywordprg' to ":help" if an empty
4564 * value was passed to :set by the user.
4565 * Misuse errbuf[] for the resulting string.
4566 */
4567 if (varp == (char_u *)&p_kp
4568 && (*arg == NUL || *arg == ' '))
4569 {
4570 STRCPY(errbuf, ":help");
4571 save_arg = arg;
4572 arg = errbuf;
4573 }
4574 /*
4575 * Convert 'whichwrap' number to string, for
4576 * backwards compatibility with Vim 3.0.
4577 * Misuse errbuf[] for the resulting string.
4578 */
4579 else if (varp == (char_u *)&p_ww
4580 && VIM_ISDIGIT(*arg))
4581 {
4582 *errbuf = NUL;
4583 i = getdigits(&arg);
4584 if (i & 1)
4585 STRCAT(errbuf, "b,");
4586 if (i & 2)
4587 STRCAT(errbuf, "s,");
4588 if (i & 4)
4589 STRCAT(errbuf, "h,l,");
4590 if (i & 8)
4591 STRCAT(errbuf, "<,>,");
4592 if (i & 16)
4593 STRCAT(errbuf, "[,],");
4594 if (*errbuf != NUL) /* remove trailing , */
4595 errbuf[STRLEN(errbuf) - 1] = NUL;
4596 save_arg = arg;
4597 arg = errbuf;
4598 }
4599 /*
4600 * Remove '>' before 'dir' and 'bdir', for
4601 * backwards compatibility with version 3.0
4602 */
4603 else if ( *arg == '>'
4604 && (varp == (char_u *)&p_dir
4605 || varp == (char_u *)&p_bdir))
4606 {
4607 ++arg;
4608 }
4609
4610 /* When setting the local value of a global
4611 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004612 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 && (opt_flags & OPT_LOCAL))
4614 origval = *(char_u **)get_varp(
4615 &options[opt_idx]);
4616 else
4617 origval = oldval;
4618
4619 /*
4620 * Copy the new string into allocated memory.
4621 * Can't use set_string_option_direct(), because
4622 * we need to remove the backslashes.
4623 */
4624 /* get a bit too much */
4625 newlen = (unsigned)STRLEN(arg) + 1;
4626 if (adding || prepending || removing)
4627 newlen += (unsigned)STRLEN(origval) + 1;
4628 newval = alloc(newlen);
4629 if (newval == NULL) /* out of mem, don't change */
4630 break;
4631 s = newval;
4632
4633 /*
4634 * Copy the string, skip over escaped chars.
4635 * For MS-DOS and WIN32 backslashes before normal
4636 * file name characters are not removed, and keep
4637 * backslash at start, for "\\machine\path", but
4638 * do remove it for "\\\\machine\\path".
4639 * The reverse is found in ExpandOldSetting().
4640 */
4641 while (*arg && !vim_iswhite(*arg))
4642 {
4643 if (*arg == '\\' && arg[1] != NUL
4644#ifdef BACKSLASH_IN_FILENAME
4645 && !((flags & P_EXPAND)
4646 && vim_isfilec(arg[1])
4647 && (arg[1] != '\\'
4648 || (s == newval
4649 && arg[2] != '\\')))
4650#endif
4651 )
4652 ++arg; /* remove backslash */
4653#ifdef FEAT_MBYTE
4654 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004655 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004656 {
4657 /* copy multibyte char */
4658 mch_memmove(s, arg, (size_t)i);
4659 arg += i;
4660 s += i;
4661 }
4662 else
4663#endif
4664 *s++ = *arg++;
4665 }
4666 *s = NUL;
4667
4668 /*
4669 * Expand environment variables and ~.
4670 * Don't do it when adding without inserting a
4671 * comma.
4672 */
4673 if (!(adding || prepending || removing)
4674 || (flags & P_COMMA))
4675 {
4676 s = option_expand(opt_idx, newval);
4677 if (s != NULL)
4678 {
4679 vim_free(newval);
4680 newlen = (unsigned)STRLEN(s) + 1;
4681 if (adding || prepending || removing)
4682 newlen += (unsigned)STRLEN(origval) + 1;
4683 newval = alloc(newlen);
4684 if (newval == NULL)
4685 break;
4686 STRCPY(newval, s);
4687 }
4688 }
4689
4690 /* locate newval[] in origval[] when removing it
4691 * and when adding to avoid duplicates */
4692 i = 0; /* init for GCC */
4693 if (removing || (flags & P_NODUP))
4694 {
4695 i = (int)STRLEN(newval);
4696 bs = 0;
4697 for (s = origval; *s; ++s)
4698 {
4699 if ((!(flags & P_COMMA)
4700 || s == origval
4701 || (s[-1] == ',' && !(bs & 1)))
4702 && STRNCMP(s, newval, i) == 0
4703 && (!(flags & P_COMMA)
4704 || s[i] == ','
4705 || s[i] == NUL))
4706 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004707 /* Count backslashes. Only a comma with an
4708 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 * recognized as a separator */
4710 if (s > origval && s[-1] == '\\')
4711 ++bs;
4712 else
4713 bs = 0;
4714 }
4715
4716 /* do not add if already there */
4717 if ((adding || prepending) && *s)
4718 {
4719 prepending = FALSE;
4720 adding = FALSE;
4721 STRCPY(newval, origval);
4722 }
4723 }
4724
4725 /* concatenate the two strings; add a ',' if
4726 * needed */
4727 if (adding || prepending)
4728 {
4729 comma = ((flags & P_COMMA) && *origval != NUL
4730 && *newval != NUL);
4731 if (adding)
4732 {
4733 i = (int)STRLEN(origval);
4734 mch_memmove(newval + i + comma, newval,
4735 STRLEN(newval) + 1);
4736 mch_memmove(newval, origval, (size_t)i);
4737 }
4738 else
4739 {
4740 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004741 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 }
4743 if (comma)
4744 newval[i] = ',';
4745 }
4746
4747 /* Remove newval[] from origval[]. (Note: "i" has
4748 * been set above and is used here). */
4749 if (removing)
4750 {
4751 STRCPY(newval, origval);
4752 if (*s)
4753 {
4754 /* may need to remove a comma */
4755 if (flags & P_COMMA)
4756 {
4757 if (s == origval)
4758 {
4759 /* include comma after string */
4760 if (s[i] == ',')
4761 ++i;
4762 }
4763 else
4764 {
4765 /* include comma before string */
4766 --s;
4767 ++i;
4768 }
4769 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004770 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 }
4772 }
4773
4774 if (flags & P_FLAGLIST)
4775 {
4776 /* Remove flags that appear twice. */
4777 for (s = newval; *s; ++s)
4778 if ((!(flags & P_COMMA) || *s != ',')
4779 && vim_strchr(s + 1, *s) != NULL)
4780 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004781 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004782 --s;
4783 }
4784 }
4785
4786 if (save_arg != NULL) /* number for 'whichwrap' */
4787 arg = save_arg;
4788 new_value_alloced = TRUE;
4789 }
4790
4791 /* Set the new value. */
4792 *(char_u **)(varp) = newval;
4793
4794 /* Handle side effects, and set the global value for
4795 * ":set" on local options. */
4796 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4797 new_value_alloced, oldval, errbuf, opt_flags);
4798
4799 /* If error detected, print the error message. */
4800 if (errmsg != NULL)
4801 goto skip;
4802 }
4803 else /* key code option */
4804 {
4805 char_u *p;
4806
4807 if (nextchar == '&')
4808 {
4809 if (add_termcap_entry(key_name, TRUE) == FAIL)
4810 errmsg = (char_u *)N_("E522: Not found in termcap");
4811 }
4812 else
4813 {
4814 ++arg; /* jump to after the '=' or ':' */
4815 for (p = arg; *p && !vim_iswhite(*p); ++p)
4816 if (*p == '\\' && p[1] != NUL)
4817 ++p;
4818 nextchar = *p;
4819 *p = NUL;
4820 add_termcode(key_name, arg, FALSE);
4821 *p = nextchar;
4822 }
4823 if (full_screen)
4824 ttest(FALSE);
4825 redraw_all_later(CLEAR);
4826 }
4827 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004828
Bram Moolenaar071d4272004-06-13 20:20:40 +00004829 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004830 did_set_option(opt_idx, opt_flags,
4831 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 }
4833
4834skip:
4835 /*
4836 * Advance to next argument.
4837 * - skip until a blank found, taking care of backslashes
4838 * - skip blanks
4839 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4840 */
4841 for (i = 0; i < 2 ; ++i)
4842 {
4843 while (*arg != NUL && !vim_iswhite(*arg))
4844 if (*arg++ == '\\' && *arg != NUL)
4845 ++arg;
4846 arg = skipwhite(arg);
4847 if (*arg != '=')
4848 break;
4849 }
4850 }
4851
4852 if (errmsg != NULL)
4853 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004854 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004855 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004856 if (i + (arg - startarg) < IOSIZE)
4857 {
4858 /* append the argument with the error */
4859 STRCAT(IObuff, ": ");
4860 mch_memmove(IObuff + i, startarg, (arg - startarg));
4861 IObuff[i + (arg - startarg)] = NUL;
4862 }
4863 /* make sure all characters are printable */
4864 trans_characters(IObuff, IOSIZE);
4865
4866 ++no_wait_return; /* wait_return done later */
4867 emsg(IObuff); /* show error highlighted */
4868 --no_wait_return;
4869
4870 return FAIL;
4871 }
4872
4873 arg = skipwhite(arg);
4874 }
4875
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004876theend:
4877 if (silent_mode && did_show)
4878 {
4879 /* After displaying option values in silent mode. */
4880 silent_mode = FALSE;
4881 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4882 msg_putchar('\n');
4883 cursor_on(); /* msg_start() switches it off */
4884 out_flush();
4885 silent_mode = TRUE;
4886 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4887 }
4888
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 return OK;
4890}
4891
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004892/*
4893 * Call this when an option has been given a new value through a user command.
4894 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4895 */
4896 static void
4897did_set_option(opt_idx, opt_flags, new_value)
4898 int opt_idx;
4899 int opt_flags; /* possibly with OPT_MODELINE */
4900 int new_value; /* value was replaced completely */
4901{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004902 long_u *p;
4903
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004904 options[opt_idx].flags |= P_WAS_SET;
4905
4906 /* When an option is set in the sandbox, from a modeline or in secure mode
4907 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004908 * flag. */
4909 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004910 if (secure
4911#ifdef HAVE_SANDBOX
4912 || sandbox != 0
4913#endif
4914 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004915 *p = *p | P_INSECURE;
4916 else if (new_value)
4917 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004918}
4919
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 static char_u *
4921illegal_char(errbuf, c)
4922 char_u *errbuf;
4923 int c;
4924{
4925 if (errbuf == NULL)
4926 return (char_u *)"";
4927 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004928 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 return errbuf;
4930}
4931
4932/*
4933 * Convert a key name or string into a key value.
4934 * Used for 'wildchar' and 'cedit' options.
4935 */
4936 static int
4937string_to_key(arg)
4938 char_u *arg;
4939{
4940 if (*arg == '<')
4941 return find_key_option(arg + 1);
4942 if (*arg == '^')
4943 return Ctrl_chr(arg[1]);
4944 return *arg;
4945}
4946
4947#ifdef FEAT_CMDWIN
4948/*
4949 * Check value of 'cedit' and set cedit_key.
4950 * Returns NULL if value is OK, error message otherwise.
4951 */
4952 static char_u *
4953check_cedit()
4954{
4955 int n;
4956
4957 if (*p_cedit == NUL)
4958 cedit_key = -1;
4959 else
4960 {
4961 n = string_to_key(p_cedit);
4962 if (vim_isprintc(n))
4963 return e_invarg;
4964 cedit_key = n;
4965 }
4966 return NULL;
4967}
4968#endif
4969
4970#ifdef FEAT_TITLE
4971/*
4972 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4973 * maketitle() to create and display it.
4974 * When switching the title or icon off, call mch_restore_title() to get
4975 * the old value back.
4976 */
4977 static void
4978did_set_title(icon)
4979 int icon; /* Did set icon instead of title */
4980{
4981 if (starting != NO_SCREEN
4982#ifdef FEAT_GUI
4983 && !gui.starting
4984#endif
4985 )
4986 {
4987 maketitle();
4988 if (icon)
4989 {
4990 if (!p_icon)
4991 mch_restore_title(2);
4992 }
4993 else
4994 {
4995 if (!p_title)
4996 mch_restore_title(1);
4997 }
4998 }
4999}
5000#endif
5001
5002/*
5003 * set_options_bin - called when 'bin' changes value.
5004 */
5005 void
5006set_options_bin(oldval, newval, opt_flags)
5007 int oldval;
5008 int newval;
5009 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5010{
5011 /*
5012 * The option values that are changed when 'bin' changes are
5013 * copied when 'bin is set and restored when 'bin' is reset.
5014 */
5015 if (newval)
5016 {
5017 if (!oldval) /* switched on */
5018 {
5019 if (!(opt_flags & OPT_GLOBAL))
5020 {
5021 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5022 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5023 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5024 curbuf->b_p_et_nobin = curbuf->b_p_et;
5025 }
5026 if (!(opt_flags & OPT_LOCAL))
5027 {
5028 p_tw_nobin = p_tw;
5029 p_wm_nobin = p_wm;
5030 p_ml_nobin = p_ml;
5031 p_et_nobin = p_et;
5032 }
5033 }
5034
5035 if (!(opt_flags & OPT_GLOBAL))
5036 {
5037 curbuf->b_p_tw = 0; /* no automatic line wrap */
5038 curbuf->b_p_wm = 0; /* no automatic line wrap */
5039 curbuf->b_p_ml = 0; /* no modelines */
5040 curbuf->b_p_et = 0; /* no expandtab */
5041 }
5042 if (!(opt_flags & OPT_LOCAL))
5043 {
5044 p_tw = 0;
5045 p_wm = 0;
5046 p_ml = FALSE;
5047 p_et = FALSE;
5048 p_bin = TRUE; /* needed when called for the "-b" argument */
5049 }
5050 }
5051 else if (oldval) /* switched off */
5052 {
5053 if (!(opt_flags & OPT_GLOBAL))
5054 {
5055 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5056 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5057 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5058 curbuf->b_p_et = curbuf->b_p_et_nobin;
5059 }
5060 if (!(opt_flags & OPT_LOCAL))
5061 {
5062 p_tw = p_tw_nobin;
5063 p_wm = p_wm_nobin;
5064 p_ml = p_ml_nobin;
5065 p_et = p_et_nobin;
5066 }
5067 }
5068}
5069
5070#ifdef FEAT_VIMINFO
5071/*
5072 * Find the parameter represented by the given character (eg ', :, ", or /),
5073 * and return its associated value in the 'viminfo' string.
5074 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005075 * If the parameter is not specified in the string or there is no following
5076 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 */
5078 int
5079get_viminfo_parameter(type)
5080 int type;
5081{
5082 char_u *p;
5083
5084 p = find_viminfo_parameter(type);
5085 if (p != NULL && VIM_ISDIGIT(*p))
5086 return atoi((char *)p);
5087 return -1;
5088}
5089
5090/*
5091 * Find the parameter represented by the given character (eg ''', ':', '"', or
5092 * '/') in the 'viminfo' option and return a pointer to the string after it.
5093 * Return NULL if the parameter is not specified in the string.
5094 */
5095 char_u *
5096find_viminfo_parameter(type)
5097 int type;
5098{
5099 char_u *p;
5100
5101 for (p = p_viminfo; *p; ++p)
5102 {
5103 if (*p == type)
5104 return p + 1;
5105 if (*p == 'n') /* 'n' is always the last one */
5106 break;
5107 p = vim_strchr(p, ','); /* skip until next ',' */
5108 if (p == NULL) /* hit the end without finding parameter */
5109 break;
5110 }
5111 return NULL;
5112}
5113#endif
5114
5115/*
5116 * Expand environment variables for some string options.
5117 * These string options cannot be indirect!
5118 * If "val" is NULL expand the current value of the option.
5119 * Return pointer to NameBuff, or NULL when not expanded.
5120 */
5121 static char_u *
5122option_expand(opt_idx, val)
5123 int opt_idx;
5124 char_u *val;
5125{
5126 /* if option doesn't need expansion nothing to do */
5127 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5128 return NULL;
5129
5130 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5131 * expand_env() would truncate the string. */
5132 if (val != NULL && STRLEN(val) > MAXPATHL)
5133 return NULL;
5134
5135 if (val == NULL)
5136 val = *(char_u **)options[opt_idx].var;
5137
5138 /*
5139 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5140 * Escape spaces when expanding 'tags', they are used to separate file
5141 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005142 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 */
5144 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005145 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005146#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005147 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5148#endif
5149 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005150 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5151 return NULL;
5152
5153 return NameBuff;
5154}
5155
5156/*
5157 * After setting various option values: recompute variables that depend on
5158 * option values.
5159 */
5160 static void
5161didset_options()
5162{
5163 /* initialize the table for 'iskeyword' et.al. */
5164 (void)init_chartab();
5165
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005166#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5170#ifdef FEAT_SESSION
5171 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5172 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5173#endif
5174#ifdef FEAT_FOLDING
5175 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5176#endif
5177 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5178#ifdef FEAT_VIRTUALEDIT
5179 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5180#endif
5181#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5182 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5183#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005184#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005185 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005186 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005187 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5190 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5191#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005192#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5194#endif
5195#ifdef FEAT_CMDWIN
5196 /* set cedit_key */
5197 (void)check_cedit();
5198#endif
5199}
5200
5201/*
5202 * Check for string options that are NULL (normally only termcap options).
5203 */
5204 void
5205check_options()
5206{
5207 int opt_idx;
5208
5209 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5210 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5211 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5212}
5213
5214/*
5215 * Check string options in a buffer for NULL value.
5216 */
5217 void
5218check_buf_options(buf)
5219 buf_T *buf;
5220{
5221#if defined(FEAT_QUICKFIX)
5222 check_string_option(&buf->b_p_bh);
5223 check_string_option(&buf->b_p_bt);
5224#endif
5225#ifdef FEAT_MBYTE
5226 check_string_option(&buf->b_p_fenc);
5227#endif
5228 check_string_option(&buf->b_p_ff);
5229#ifdef FEAT_FIND_ID
5230 check_string_option(&buf->b_p_def);
5231 check_string_option(&buf->b_p_inc);
5232# ifdef FEAT_EVAL
5233 check_string_option(&buf->b_p_inex);
5234# endif
5235#endif
5236#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5237 check_string_option(&buf->b_p_inde);
5238 check_string_option(&buf->b_p_indk);
5239#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005240#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5241 check_string_option(&buf->b_p_bexpr);
5242#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005243#if defined(FEAT_CRYPT)
5244 check_string_option(&buf->b_p_cm);
5245#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005246#if defined(FEAT_EVAL)
5247 check_string_option(&buf->b_p_fex);
5248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249#ifdef FEAT_CRYPT
5250 check_string_option(&buf->b_p_key);
5251#endif
5252 check_string_option(&buf->b_p_kp);
5253 check_string_option(&buf->b_p_mps);
5254 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005255 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256 check_string_option(&buf->b_p_isk);
5257#ifdef FEAT_COMMENTS
5258 check_string_option(&buf->b_p_com);
5259#endif
5260#ifdef FEAT_FOLDING
5261 check_string_option(&buf->b_p_cms);
5262#endif
5263 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005264#ifdef FEAT_TEXTOBJ
5265 check_string_option(&buf->b_p_qe);
5266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267#ifdef FEAT_SYN_HL
5268 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005269#endif
5270#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005271 check_string_option(&buf->b_s.b_p_spc);
5272 check_string_option(&buf->b_s.b_p_spf);
5273 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274#endif
5275#ifdef FEAT_SEARCHPATH
5276 check_string_option(&buf->b_p_sua);
5277#endif
5278#ifdef FEAT_CINDENT
5279 check_string_option(&buf->b_p_cink);
5280 check_string_option(&buf->b_p_cino);
5281#endif
5282#ifdef FEAT_AUTOCMD
5283 check_string_option(&buf->b_p_ft);
5284#endif
5285#ifdef FEAT_OSFILETYPE
5286 check_string_option(&buf->b_p_oft);
5287#endif
5288#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5289 check_string_option(&buf->b_p_cinw);
5290#endif
5291#ifdef FEAT_INS_EXPAND
5292 check_string_option(&buf->b_p_cpt);
5293#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005294#ifdef FEAT_COMPL_FUNC
5295 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005296 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298#ifdef FEAT_KEYMAP
5299 check_string_option(&buf->b_p_keymap);
5300#endif
5301#ifdef FEAT_QUICKFIX
5302 check_string_option(&buf->b_p_gp);
5303 check_string_option(&buf->b_p_mp);
5304 check_string_option(&buf->b_p_efm);
5305#endif
5306 check_string_option(&buf->b_p_ep);
5307 check_string_option(&buf->b_p_path);
5308 check_string_option(&buf->b_p_tags);
5309#ifdef FEAT_INS_EXPAND
5310 check_string_option(&buf->b_p_dict);
5311 check_string_option(&buf->b_p_tsr);
5312#endif
5313}
5314
5315/*
5316 * Free the string allocated for an option.
5317 * Checks for the string being empty_option. This may happen if we're out of
5318 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5319 * check_options().
5320 * Does NOT check for P_ALLOCED flag!
5321 */
5322 void
5323free_string_option(p)
5324 char_u *p;
5325{
5326 if (p != empty_option)
5327 vim_free(p);
5328}
5329
5330 void
5331clear_string_option(pp)
5332 char_u **pp;
5333{
5334 if (*pp != empty_option)
5335 vim_free(*pp);
5336 *pp = empty_option;
5337}
5338
5339 static void
5340check_string_option(pp)
5341 char_u **pp;
5342{
5343 if (*pp == NULL)
5344 *pp = empty_option;
5345}
5346
5347/*
5348 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5349 */
5350 void
5351set_term_option_alloced(p)
5352 char_u **p;
5353{
5354 int opt_idx;
5355
5356 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5357 if (options[opt_idx].var == (char_u *)p)
5358 {
5359 options[opt_idx].flags |= P_ALLOCED;
5360 return;
5361 }
5362 return; /* cannot happen: didn't find it! */
5363}
5364
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005365#if defined(FEAT_EVAL) || defined(PROTO)
5366/*
5367 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5368 * Return FALSE when it wasn't.
5369 * Return -1 for an unknown option.
5370 */
5371 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005372was_set_insecurely(opt, opt_flags)
5373 char_u *opt;
5374 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005375{
5376 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005377 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005378
5379 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005380 {
5381 flagp = insecure_flag(idx, opt_flags);
5382 return (*flagp & P_INSECURE) != 0;
5383 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005384 EMSG2(_(e_intern2), "was_set_insecurely()");
5385 return -1;
5386}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005387
5388/*
5389 * Get a pointer to the flags used for the P_INSECURE flag of option
5390 * "opt_idx". For some local options a local flags field is used.
5391 */
5392 static long_u *
5393insecure_flag(opt_idx, opt_flags)
5394 int opt_idx;
5395 int opt_flags;
5396{
5397 if (opt_flags & OPT_LOCAL)
5398 switch ((int)options[opt_idx].indir)
5399 {
5400#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005401 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005402#endif
5403#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005404# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005405 case PV_FDE: return &curwin->w_p_fde_flags;
5406 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005407# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005408# ifdef FEAT_BEVAL
5409 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5410# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005411# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005412 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005413# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005414 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005415# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005416 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005417# endif
5418#endif
5419 }
5420
5421 /* Nothing special, return global flags field. */
5422 return &options[opt_idx].flags;
5423}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005424#endif
5425
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005426#ifdef FEAT_TITLE
5427static void redraw_titles __ARGS((void));
5428
5429/*
5430 * Redraw the window title and/or tab page text later.
5431 */
5432static void redraw_titles()
5433{
5434 need_maketitle = TRUE;
5435# ifdef FEAT_WINDOWS
5436 redraw_tabline = TRUE;
5437# endif
5438}
5439#endif
5440
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441/*
5442 * Set a string option to a new value (without checking the effect).
5443 * The string is copied into allocated memory.
5444 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005445 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005446 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005447 */
5448 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005449set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450 char_u *name;
5451 int opt_idx;
5452 char_u *val;
5453 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005454 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005455{
5456 char_u *s;
5457 char_u **varp;
5458 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005459 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460
Bram Moolenaar89d40322006-08-29 15:30:07 +00005461 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005463 idx = findoption(name);
5464 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005465 {
5466 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469 }
5470
Bram Moolenaar89d40322006-08-29 15:30:07 +00005471 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 return;
5473
5474 s = vim_strsave(val);
5475 if (s != NULL)
5476 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005477 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005479 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480 free_string_option(*varp);
5481 *varp = s;
5482
5483 /* For buffer/window local option may also set the global value. */
5484 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005485 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486
Bram Moolenaar89d40322006-08-29 15:30:07 +00005487 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488
5489 /* When setting both values of a global option with a local value,
5490 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005491 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 {
5493 free_string_option(*varp);
5494 *varp = empty_option;
5495 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005496# ifdef FEAT_EVAL
5497 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005498 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005499 set_sid == 0 ? current_SID : set_sid);
5500# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501 }
5502}
5503
5504/*
5505 * Set global value for string option when it's a local option.
5506 */
5507 static void
5508set_string_option_global(opt_idx, varp)
5509 int opt_idx; /* option index */
5510 char_u **varp; /* pointer to option variable */
5511{
5512 char_u **p, *s;
5513
5514 /* the global value is always allocated */
5515 if (options[opt_idx].var == VAR_WIN)
5516 p = (char_u **)GLOBAL_WO(varp);
5517 else
5518 p = (char_u **)options[opt_idx].var;
5519 if (options[opt_idx].indir != PV_NONE
5520 && p != varp
5521 && (s = vim_strsave(*varp)) != NULL)
5522 {
5523 free_string_option(*p);
5524 *p = s;
5525 }
5526}
5527
5528/*
5529 * Set a string option to a new value, and handle the effects.
5530 */
5531 static void
5532set_string_option(opt_idx, value, opt_flags)
5533 int opt_idx;
5534 char_u *value;
5535 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5536{
5537 char_u *s;
5538 char_u **varp;
5539 char_u *oldval;
5540
5541 if (options[opt_idx].var == NULL) /* don't set hidden option */
5542 return;
5543
5544 s = vim_strsave(value);
5545 if (s != NULL)
5546 {
5547 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5548 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005549 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 ? OPT_GLOBAL : OPT_LOCAL)
5551 : opt_flags);
5552 oldval = *varp;
5553 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005554 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5555 opt_flags) == NULL)
5556 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557 }
5558}
5559
5560/*
5561 * Handle string options that need some action to perform when changed.
5562 * Returns NULL for success, or an error message for an error.
5563 */
5564 static char_u *
5565did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5566 opt_flags)
5567 int opt_idx; /* index in options[] table */
5568 char_u **varp; /* pointer to the option variable */
5569 int new_value_alloced; /* new value was allocated */
5570 char_u *oldval; /* previous value of the option */
5571 char_u *errbuf; /* buffer for errors, or NULL */
5572 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5573{
5574 char_u *errmsg = NULL;
5575 char_u *s, *p;
5576 int did_chartab = FALSE;
5577 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005578 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005579#ifdef FEAT_GUI
5580 /* set when changing an option that only requires a redraw in the GUI */
5581 int redraw_gui_only = FALSE;
5582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583
5584 /* Get the global option to compare with, otherwise we would have to check
5585 * two values for all local options. */
5586 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5587
5588 /* Disallow changing some options from secure mode */
5589 if ((secure
5590#ifdef HAVE_SANDBOX
5591 || sandbox != 0
5592#endif
5593 ) && (options[opt_idx].flags & P_SECURE))
5594 {
5595 errmsg = e_secure;
5596 }
5597
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005598 /* Check for a "normal" file name in some options. Disallow a path
5599 * separator (slash and/or backslash), wildcards and characters that are
5600 * often illegal in a file name. */
5601 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005602 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005603 {
5604 errmsg = e_invarg;
5605 }
5606
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607 /* 'term' */
5608 else if (varp == &T_NAME)
5609 {
5610 if (T_NAME[0] == NUL)
5611 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5612#ifdef FEAT_GUI
5613 if (gui.in_use)
5614 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5615 else if (term_is_gui(T_NAME))
5616 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5617#endif
5618 else if (set_termname(T_NAME) == FAIL)
5619 errmsg = (char_u *)N_("E522: Not found in termcap");
5620 else
5621 /* Screen colors may have changed. */
5622 redraw_later_clear();
5623 }
5624
5625 /* 'backupcopy' */
5626 else if (varp == &p_bkc)
5627 {
5628 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5629 errmsg = e_invarg;
5630 if (((bkc_flags & BKC_AUTO) != 0)
5631 + ((bkc_flags & BKC_YES) != 0)
5632 + ((bkc_flags & BKC_NO) != 0) != 1)
5633 {
5634 /* Must have exactly one of "auto", "yes" and "no". */
5635 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5636 errmsg = e_invarg;
5637 }
5638 }
5639
5640 /* 'backupext' and 'patchmode' */
5641 else if (varp == &p_bex || varp == &p_pm)
5642 {
5643 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5644 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5645 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5646 }
5647
5648 /*
5649 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5650 * If the new option is invalid, use old value. 'lisp' option: refill
5651 * chartab[] for '-' char
5652 */
5653 else if ( varp == &p_isi
5654 || varp == &(curbuf->b_p_isk)
5655 || varp == &p_isp
5656 || varp == &p_isf)
5657 {
5658 if (init_chartab() == FAIL)
5659 {
5660 did_chartab = TRUE; /* need to restore it below */
5661 errmsg = e_invarg; /* error in value */
5662 }
5663 }
5664
5665 /* 'helpfile' */
5666 else if (varp == &p_hf)
5667 {
5668 /* May compute new values for $VIM and $VIMRUNTIME */
5669 if (didset_vim)
5670 {
5671 vim_setenv((char_u *)"VIM", (char_u *)"");
5672 didset_vim = FALSE;
5673 }
5674 if (didset_vimruntime)
5675 {
5676 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5677 didset_vimruntime = FALSE;
5678 }
5679 }
5680
Bram Moolenaar1a384422010-07-14 19:53:30 +02005681#ifdef FEAT_SYN_HL
5682 /* 'colorcolumn' */
5683 else if (varp == &curwin->w_p_cc)
5684 errmsg = check_colorcolumn(curwin);
5685#endif
5686
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687#ifdef FEAT_MULTI_LANG
5688 /* 'helplang' */
5689 else if (varp == &p_hlg)
5690 {
5691 /* Check for "", "ab", "ab,cd", etc. */
5692 for (s = p_hlg; *s != NUL; s += 3)
5693 {
5694 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5695 {
5696 errmsg = e_invarg;
5697 break;
5698 }
5699 if (s[2] == NUL)
5700 break;
5701 }
5702 }
5703#endif
5704
5705 /* 'highlight' */
5706 else if (varp == &p_hl)
5707 {
5708 if (highlight_changed() == FAIL)
5709 errmsg = e_invarg; /* invalid flags */
5710 }
5711
5712 /* 'nrformats' */
5713 else if (gvarp == &p_nf)
5714 {
5715 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5716 errmsg = e_invarg;
5717 }
5718
5719#ifdef FEAT_SESSION
5720 /* 'sessionoptions' */
5721 else if (varp == &p_ssop)
5722 {
5723 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5724 errmsg = e_invarg;
5725 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5726 {
5727 /* Don't allow both "sesdir" and "curdir". */
5728 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5729 errmsg = e_invarg;
5730 }
5731 }
5732 /* 'viewoptions' */
5733 else if (varp == &p_vop)
5734 {
5735 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5736 errmsg = e_invarg;
5737 }
5738#endif
5739
5740 /* 'scrollopt' */
5741#ifdef FEAT_SCROLLBIND
5742 else if (varp == &p_sbo)
5743 {
5744 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5745 errmsg = e_invarg;
5746 }
5747#endif
5748
5749 /* 'ambiwidth' */
5750#ifdef FEAT_MBYTE
5751 else if (varp == &p_ambw)
5752 {
5753 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5754 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005755 else if (set_chars_option(&p_lcs) != NULL)
5756 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5757# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5758 else if (set_chars_option(&p_fcs) != NULL)
5759 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5760# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761 }
5762#endif
5763
5764 /* 'background' */
5765 else if (varp == &p_bg)
5766 {
5767 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5768 {
5769#ifdef FEAT_EVAL
5770 int dark = (*p_bg == 'd');
5771#endif
5772
5773 init_highlight(FALSE, FALSE);
5774
5775#ifdef FEAT_EVAL
5776 if (dark != (*p_bg == 'd')
5777 && get_var_value((char_u *)"g:colors_name") != NULL)
5778 {
5779 /* The color scheme must have set 'background' back to another
5780 * value, that's not what we want here. Disable the color
5781 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005782 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783 free_string_option(p_bg);
5784 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5785 check_string_option(&p_bg);
5786 init_highlight(FALSE, FALSE);
5787 }
5788#endif
5789 }
5790 else
5791 errmsg = e_invarg;
5792 }
5793
5794 /* 'wildmode' */
5795 else if (varp == &p_wim)
5796 {
5797 if (check_opt_wim() == FAIL)
5798 errmsg = e_invarg;
5799 }
5800
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005801#ifdef FEAT_CMDL_COMPL
5802 /* 'wildoptions' */
5803 else if (varp == &p_wop)
5804 {
5805 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5806 errmsg = e_invarg;
5807 }
5808#endif
5809
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810#ifdef FEAT_WAK
5811 /* 'winaltkeys' */
5812 else if (varp == &p_wak)
5813 {
5814 if (*p_wak == NUL
5815 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5816 errmsg = e_invarg;
5817# ifdef FEAT_MENU
5818# ifdef FEAT_GUI_MOTIF
5819 else if (gui.in_use)
5820 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5821# else
5822# ifdef FEAT_GUI_GTK
5823 else if (gui.in_use)
5824 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5825# endif
5826# endif
5827# endif
5828 }
5829#endif
5830
5831#ifdef FEAT_AUTOCMD
5832 /* 'eventignore' */
5833 else if (varp == &p_ei)
5834 {
5835 if (check_ei() == FAIL)
5836 errmsg = e_invarg;
5837 }
5838#endif
5839
5840#ifdef FEAT_MBYTE
5841 /* 'encoding' and 'fileencoding' */
5842 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5843 {
5844 if (gvarp == &p_fenc)
5845 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005846 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 errmsg = e_modifiable;
5848 else if (vim_strchr(*varp, ',') != NULL)
5849 /* No comma allowed in 'fileencoding'; catches confusing it
5850 * with 'fileencodings'. */
5851 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005853 {
5854# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005856 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005858 /* Add 'fileencoding' to the swap file. */
5859 ml_setflags(curbuf);
5860 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 }
5862 if (errmsg == NULL)
5863 {
5864 /* canonize the value, so that STRCMP() can be used on it */
5865 p = enc_canonize(*varp);
5866 if (p != NULL)
5867 {
5868 vim_free(*varp);
5869 *varp = p;
5870 }
5871 if (varp == &p_enc)
5872 {
5873 errmsg = mb_init();
5874# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005875 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876# endif
5877 }
5878 }
5879
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005880# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5882 {
5883 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5884 if (STRCMP(p_tenc, "utf-8") != 0)
5885 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5886 }
5887# endif
5888
5889 if (errmsg == NULL)
5890 {
5891# ifdef FEAT_KEYMAP
5892 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5893 * (with another encoding). */
5894 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5895 (void)keymap_init();
5896# endif
5897
5898 /* When 'termencoding' is not empty and 'encoding' changes or when
5899 * 'termencoding' changes, need to setup for keyboard input and
5900 * display output conversion. */
5901 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5902 {
5903 convert_setup(&input_conv, p_tenc, p_enc);
5904 convert_setup(&output_conv, p_enc, p_tenc);
5905 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005906
5907# if defined(WIN3264) && defined(FEAT_MBYTE)
5908 /* $HOME may have characters in active code page. */
5909 if (varp == &p_enc)
5910 init_homedir();
5911# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 }
5913 }
5914#endif
5915
5916#if defined(FEAT_POSTSCRIPT)
5917 else if (varp == &p_penc)
5918 {
5919 /* Canonize printencoding if VIM standard one */
5920 p = enc_canonize(p_penc);
5921 if (p != NULL)
5922 {
5923 vim_free(p_penc);
5924 p_penc = p;
5925 }
5926 else
5927 {
5928 /* Ensure lower case and '-' for '_' */
5929 for (s = p_penc; *s != NUL; s++)
5930 {
5931 if (*s == '_')
5932 *s = '-';
5933 else
5934 *s = TOLOWER_ASC(*s);
5935 }
5936 }
5937 }
5938#endif
5939
Bram Moolenaar9372a112005-12-06 19:59:18 +00005940#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 else if (varp == &p_imak)
5942 {
5943 if (gui.in_use && !im_xim_isvalid_imactivate())
5944 errmsg = e_invarg;
5945 }
5946#endif
5947
5948#ifdef FEAT_KEYMAP
5949 else if (varp == &curbuf->b_p_keymap)
5950 {
5951 /* load or unload key mapping tables */
5952 errmsg = keymap_init();
5953
Bram Moolenaarfab06232009-03-04 03:13:35 +00005954 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005956 if (*curbuf->b_p_keymap != NUL)
5957 {
5958 /* Installed a new keymap, switch on using it. */
5959 curbuf->b_p_iminsert = B_IMODE_LMAP;
5960 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5961 curbuf->b_p_imsearch = B_IMODE_LMAP;
5962 }
5963 else
5964 {
5965 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5966 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5967 curbuf->b_p_iminsert = B_IMODE_NONE;
5968 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5969 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5970 }
5971 if ((opt_flags & OPT_LOCAL) == 0)
5972 {
5973 set_iminsert_global();
5974 set_imsearch_global();
5975 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976# ifdef FEAT_WINDOWS
5977 status_redraw_curbuf();
5978# endif
5979 }
5980 }
5981#endif
5982
5983 /* 'fileformat' */
5984 else if (gvarp == &p_ff)
5985 {
5986 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5987 errmsg = e_modifiable;
5988 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5989 errmsg = e_invarg;
5990 else
5991 {
5992 /* may also change 'textmode' */
5993 if (get_fileformat(curbuf) == EOL_DOS)
5994 curbuf->b_p_tx = TRUE;
5995 else
5996 curbuf->b_p_tx = FALSE;
5997#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005998 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006000 /* update flag in swap file */
6001 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006002 /* Redraw needed when switching to/from "mac": a CR in the text
6003 * will be displayed differently. */
6004 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6005 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 }
6007 }
6008
6009 /* 'fileformats' */
6010 else if (varp == &p_ffs)
6011 {
6012 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6013 errmsg = e_invarg;
6014 else
6015 {
6016 /* also change 'textauto' */
6017 if (*p_ffs == NUL)
6018 p_ta = FALSE;
6019 else
6020 p_ta = TRUE;
6021 }
6022 }
6023
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006024#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006025 /* 'cryptkey' */
6026 else if (gvarp == &p_key)
6027 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006028# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029 /* Make sure the ":set" command doesn't show the new value in the
6030 * history. */
6031 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006032# endif
6033 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6034 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006035 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6036 }
6037
6038 else if (gvarp == &p_cm)
6039 {
6040 if (opt_flags & OPT_LOCAL)
6041 p = curbuf->b_p_cm;
6042 else
6043 p = p_cm;
6044 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6045 errmsg = e_invarg;
6046 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6047 errmsg = e_invarg;
6048 else
6049 {
6050 /* When setting the global value to empty, make it "zip". */
6051 if (*p_cm == NUL)
6052 {
6053 if (new_value_alloced)
6054 free_string_option(p_cm);
6055 p_cm = vim_strsave((char_u *)"zip");
6056 new_value_alloced = TRUE;
6057 }
6058
6059 /* Need to update the swapfile when the effective method changed.
6060 * Set "s" to the effective old value, "p" to the effective new
6061 * method and compare. */
6062 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6063 s = p_cm; /* was previously using the global value */
6064 else
6065 s = oldval;
6066 if (*curbuf->b_p_cm == NUL)
6067 p = p_cm; /* is now using the global value */
6068 else
6069 p = curbuf->b_p_cm;
6070 if (STRCMP(s, p) != 0)
6071 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6072 crypt_method_from_string(s));
6073
6074 /* If the global value changes need to update the swapfile for all
6075 * buffers using that value. */
6076 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6077 {
6078 buf_T *buf;
6079
6080 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6081 if (buf != curbuf && *buf->b_p_cm == NUL)
6082 ml_set_crypt_key(buf, buf->b_p_key,
6083 crypt_method_from_string(oldval));
6084 }
6085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 }
6087#endif
6088
6089 /* 'matchpairs' */
6090 else if (gvarp == &p_mps)
6091 {
6092 /* Check for "x:y,x:y" */
6093 for (p = *varp; *p != NUL; p += 4)
6094 {
6095 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6096 {
6097 errmsg = e_invarg;
6098 break;
6099 }
6100 if (p[3] == NUL)
6101 break;
6102 }
6103 }
6104
6105#ifdef FEAT_COMMENTS
6106 /* 'comments' */
6107 else if (gvarp == &p_com)
6108 {
6109 for (s = *varp; *s; )
6110 {
6111 while (*s && *s != ':')
6112 {
6113 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6114 && !VIM_ISDIGIT(*s) && *s != '-')
6115 {
6116 errmsg = illegal_char(errbuf, *s);
6117 break;
6118 }
6119 ++s;
6120 }
6121 if (*s++ == NUL)
6122 errmsg = (char_u *)N_("E524: Missing colon");
6123 else if (*s == ',' || *s == NUL)
6124 errmsg = (char_u *)N_("E525: Zero length string");
6125 if (errmsg != NULL)
6126 break;
6127 while (*s && *s != ',')
6128 {
6129 if (*s == '\\' && s[1] != NUL)
6130 ++s;
6131 ++s;
6132 }
6133 s = skip_to_option_part(s);
6134 }
6135 }
6136#endif
6137
6138 /* 'listchars' */
6139 else if (varp == &p_lcs)
6140 {
6141 errmsg = set_chars_option(varp);
6142 }
6143
6144#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6145 /* 'fillchars' */
6146 else if (varp == &p_fcs)
6147 {
6148 errmsg = set_chars_option(varp);
6149 }
6150#endif
6151
6152#ifdef FEAT_CMDWIN
6153 /* 'cedit' */
6154 else if (varp == &p_cedit)
6155 {
6156 errmsg = check_cedit();
6157 }
6158#endif
6159
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006160 /* 'verbosefile' */
6161 else if (varp == &p_vfile)
6162 {
6163 verbose_stop();
6164 if (*p_vfile != NUL && verbose_open() == FAIL)
6165 errmsg = e_invarg;
6166 }
6167
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168#ifdef FEAT_VIMINFO
6169 /* 'viminfo' */
6170 else if (varp == &p_viminfo)
6171 {
6172 for (s = p_viminfo; *s;)
6173 {
6174 /* Check it's a valid character */
6175 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6176 {
6177 errmsg = illegal_char(errbuf, *s);
6178 break;
6179 }
6180 if (*s == 'n') /* name is always last one */
6181 {
6182 break;
6183 }
6184 else if (*s == 'r') /* skip until next ',' */
6185 {
6186 while (*++s && *s != ',')
6187 ;
6188 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006189 else if (*s == '%')
6190 {
6191 /* optional number */
6192 while (vim_isdigit(*++s))
6193 ;
6194 }
6195 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006196 ++s; /* no extra chars */
6197 else /* must have a number */
6198 {
6199 while (vim_isdigit(*++s))
6200 ;
6201
6202 if (!VIM_ISDIGIT(*(s - 1)))
6203 {
6204 if (errbuf != NULL)
6205 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006206 sprintf((char *)errbuf,
6207 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006208 transchar_byte(*(s - 1)));
6209 errmsg = errbuf;
6210 }
6211 else
6212 errmsg = (char_u *)"";
6213 break;
6214 }
6215 }
6216 if (*s == ',')
6217 ++s;
6218 else if (*s)
6219 {
6220 if (errbuf != NULL)
6221 errmsg = (char_u *)N_("E527: Missing comma");
6222 else
6223 errmsg = (char_u *)"";
6224 break;
6225 }
6226 }
6227 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6228 errmsg = (char_u *)N_("E528: Must specify a ' value");
6229 }
6230#endif /* FEAT_VIMINFO */
6231
6232 /* terminal options */
6233 else if (istermoption(&options[opt_idx]) && full_screen)
6234 {
6235 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6236 if (varp == &T_CCO)
6237 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006238 int colors = atoi((char *)T_CCO);
6239
6240 /* Only reinitialize colors if t_Co value has really changed to
6241 * avoid expensive reload of colorscheme if t_Co is set to the
6242 * same value multiple times. */
6243 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006245 t_colors = colors;
6246 if (t_colors <= 1)
6247 {
6248 if (new_value_alloced)
6249 vim_free(T_CCO);
6250 T_CCO = empty_option;
6251 }
6252 /* We now have a different color setup, initialize it again. */
6253 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255 }
6256 ttest(FALSE);
6257 if (varp == &T_ME)
6258 {
6259 out_str(T_ME);
6260 redraw_later(CLEAR);
6261#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6262 /* Since t_me has been set, this probably means that the user
6263 * wants to use this as default colors. Need to reset default
6264 * background/foreground colors. */
6265 mch_set_normal_colors();
6266#endif
6267 }
6268 }
6269
6270#ifdef FEAT_LINEBREAK
6271 /* 'showbreak' */
6272 else if (varp == &p_sbr)
6273 {
6274 for (s = p_sbr; *s; )
6275 {
6276 if (ptr2cells(s) != 1)
6277 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006278 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279 }
6280 }
6281#endif
6282
6283#ifdef FEAT_GUI
6284 /* 'guifont' */
6285 else if (varp == &p_guifont)
6286 {
6287 if (gui.in_use)
6288 {
6289 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006290# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 /*
6292 * Put up a font dialog and let the user select a new value.
6293 * If this is cancelled go back to the old value but don't
6294 * give an error message.
6295 */
6296 if (STRCMP(p, "*") == 0)
6297 {
6298 p = gui_mch_font_dialog(oldval);
6299
6300 if (new_value_alloced)
6301 free_string_option(p_guifont);
6302
6303 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6304 new_value_alloced = TRUE;
6305 }
6306# endif
6307 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6308 {
6309# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6310 if (STRCMP(p_guifont, "*") == 0)
6311 {
6312 /* Dialog was cancelled: Keep the old value without giving
6313 * an error message. */
6314 if (new_value_alloced)
6315 free_string_option(p_guifont);
6316 p_guifont = vim_strsave(oldval);
6317 new_value_alloced = TRUE;
6318 }
6319 else
6320# endif
6321 errmsg = (char_u *)N_("E596: Invalid font(s)");
6322 }
6323 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006324 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 }
6326# ifdef FEAT_XFONTSET
6327 else if (varp == &p_guifontset)
6328 {
6329 if (STRCMP(p_guifontset, "*") == 0)
6330 errmsg = (char_u *)N_("E597: can't select fontset");
6331 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6332 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006333 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 }
6335# endif
6336# ifdef FEAT_MBYTE
6337 else if (varp == &p_guifontwide)
6338 {
6339 if (STRCMP(p_guifontwide, "*") == 0)
6340 errmsg = (char_u *)N_("E533: can't select wide font");
6341 else if (gui_get_wide_font() == FAIL)
6342 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006343 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 }
6345# endif
6346#endif
6347
6348#ifdef CURSOR_SHAPE
6349 /* 'guicursor' */
6350 else if (varp == &p_guicursor)
6351 errmsg = parse_shape_opt(SHAPE_CURSOR);
6352#endif
6353
6354#ifdef FEAT_MOUSESHAPE
6355 /* 'mouseshape' */
6356 else if (varp == &p_mouseshape)
6357 {
6358 errmsg = parse_shape_opt(SHAPE_MOUSE);
6359 update_mouseshape(-1);
6360 }
6361#endif
6362
6363#ifdef FEAT_PRINTER
6364 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006365 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006366# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006367 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006368 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006369# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370#endif
6371
6372#ifdef FEAT_LANGMAP
6373 /* 'langmap' */
6374 else if (varp == &p_langmap)
6375 langmap_set();
6376#endif
6377
6378#ifdef FEAT_LINEBREAK
6379 /* 'breakat' */
6380 else if (varp == &p_breakat)
6381 fill_breakat_flags();
6382#endif
6383
6384#ifdef FEAT_TITLE
6385 /* 'titlestring' and 'iconstring' */
6386 else if (varp == &p_titlestring || varp == &p_iconstring)
6387 {
6388# ifdef FEAT_STL_OPT
6389 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6390
6391 /* NULL => statusline syntax */
6392 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6393 stl_syntax |= flagval;
6394 else
6395 stl_syntax &= ~flagval;
6396# endif
6397 did_set_title(varp == &p_iconstring);
6398
6399 }
6400#endif
6401
6402#ifdef FEAT_GUI
6403 /* 'guioptions' */
6404 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006405 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006406 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006407 redraw_gui_only = TRUE;
6408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409#endif
6410
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006411#if defined(FEAT_GUI_TABLINE)
6412 /* 'guitablabel' */
6413 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006414 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006415 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006416 redraw_gui_only = TRUE;
6417 }
6418 /* 'guitabtooltip' */
6419 else if (varp == &p_gtt)
6420 {
6421 redraw_gui_only = TRUE;
6422 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006423#endif
6424
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6426 /* 'ttymouse' */
6427 else if (varp == &p_ttym)
6428 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006429 /* Switch the mouse off before changing the escape sequences used for
6430 * that. */
6431 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6433 errmsg = e_invarg;
6434 else
6435 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006436 if (termcap_active)
6437 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006438 }
6439#endif
6440
6441#ifdef FEAT_VISUAL
6442 /* 'selection' */
6443 else if (varp == &p_sel)
6444 {
6445 if (*p_sel == NUL
6446 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6447 errmsg = e_invarg;
6448 }
6449
6450 /* 'selectmode' */
6451 else if (varp == &p_slm)
6452 {
6453 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6454 errmsg = e_invarg;
6455 }
6456#endif
6457
6458#ifdef FEAT_BROWSE
6459 /* 'browsedir' */
6460 else if (varp == &p_bsdir)
6461 {
6462 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6463 && !mch_isdir(p_bsdir))
6464 errmsg = e_invarg;
6465 }
6466#endif
6467
6468#ifdef FEAT_VISUAL
6469 /* 'keymodel' */
6470 else if (varp == &p_km)
6471 {
6472 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6473 errmsg = e_invarg;
6474 else
6475 {
6476 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6477 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6478 }
6479 }
6480#endif
6481
6482 /* 'mousemodel' */
6483 else if (varp == &p_mousem)
6484 {
6485 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6486 errmsg = e_invarg;
6487#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6488 else if (*p_mousem != *oldval)
6489 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6490 * to create or delete the popup menus. */
6491 gui_motif_update_mousemodel(root_menu);
6492#endif
6493 }
6494
6495 /* 'switchbuf' */
6496 else if (varp == &p_swb)
6497 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006498 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499 errmsg = e_invarg;
6500 }
6501
6502 /* 'debug' */
6503 else if (varp == &p_debug)
6504 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006505 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006506 errmsg = e_invarg;
6507 }
6508
6509 /* 'display' */
6510 else if (varp == &p_dy)
6511 {
6512 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6513 errmsg = e_invarg;
6514 else
6515 (void)init_chartab();
6516
6517 }
6518
6519#ifdef FEAT_VERTSPLIT
6520 /* 'eadirection' */
6521 else if (varp == &p_ead)
6522 {
6523 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6524 errmsg = e_invarg;
6525 }
6526#endif
6527
6528#ifdef FEAT_CLIPBOARD
6529 /* 'clipboard' */
6530 else if (varp == &p_cb)
6531 errmsg = check_clipboard_option();
6532#endif
6533
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006534#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006535 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6536 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006537 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006538 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006539 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006540 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006541
Bram Moolenaar860cae12010-06-05 23:22:07 +02006542 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006543 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006544 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6545 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006546 ".add") != 0))
6547 errmsg = e_invarg;
6548 }
6549
6550 if (errmsg == NULL)
6551 {
6552 FOR_ALL_WINDOWS(wp)
6553 if (wp->w_buffer == curbuf && wp->w_p_spell)
6554 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006555 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006556# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006557 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006558# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006559 }
6560 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006561 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006562 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006563 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006564 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006565 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006566 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006567 /* 'spellsuggest' */
6568 else if (varp == &p_sps)
6569 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006570 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006571 errmsg = e_invarg;
6572 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006573 /* 'mkspellmem' */
6574 else if (varp == &p_msm)
6575 {
6576 if (spell_check_msm() != OK)
6577 errmsg = e_invarg;
6578 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006579#endif
6580
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581#ifdef FEAT_QUICKFIX
6582 /* When 'bufhidden' is set, check for valid value. */
6583 else if (gvarp == &p_bh)
6584 {
6585 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6586 errmsg = e_invarg;
6587 }
6588
6589 /* When 'buftype' is set, check for valid value. */
6590 else if (gvarp == &p_bt)
6591 {
6592 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6593 errmsg = e_invarg;
6594 else
6595 {
6596# ifdef FEAT_WINDOWS
6597 if (curwin->w_status_height)
6598 {
6599 curwin->w_redr_status = TRUE;
6600 redraw_later(VALID);
6601 }
6602# endif
6603 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006604# ifdef FEAT_TITLE
6605 redraw_titles();
6606# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 }
6608 }
6609#endif
6610
6611#ifdef FEAT_STL_OPT
6612 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006613 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 {
6615 int wid;
6616
6617 if (varp == &p_ruf) /* reset ru_wid first */
6618 ru_wid = 0;
6619 s = *varp;
6620 if (varp == &p_ruf && *s == '%')
6621 {
6622 /* set ru_wid if 'ruf' starts with "%99(" */
6623 if (*++s == '-') /* ignore a '-' */
6624 s++;
6625 wid = getdigits(&s);
6626 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6627 ru_wid = wid;
6628 else
6629 errmsg = check_stl_option(p_ruf);
6630 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006631 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006632 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006634 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 comp_col();
6636 }
6637#endif
6638
6639#ifdef FEAT_INS_EXPAND
6640 /* check if it is a valid value for 'complete' -- Acevedo */
6641 else if (gvarp == &p_cpt)
6642 {
6643 for (s = *varp; *s;)
6644 {
6645 while(*s == ',' || *s == ' ')
6646 s++;
6647 if (!*s)
6648 break;
6649 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6650 {
6651 errmsg = illegal_char(errbuf, *s);
6652 break;
6653 }
6654 if (*++s != NUL && *s != ',' && *s != ' ')
6655 {
6656 if (s[-1] == 'k' || s[-1] == 's')
6657 {
6658 /* skip optional filename after 'k' and 's' */
6659 while (*s && *s != ',' && *s != ' ')
6660 {
6661 if (*s == '\\')
6662 ++s;
6663 ++s;
6664 }
6665 }
6666 else
6667 {
6668 if (errbuf != NULL)
6669 {
6670 sprintf((char *)errbuf,
6671 _("E535: Illegal character after <%c>"),
6672 *--s);
6673 errmsg = errbuf;
6674 }
6675 else
6676 errmsg = (char_u *)"";
6677 break;
6678 }
6679 }
6680 }
6681 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006682
6683 /* 'completeopt' */
6684 else if (varp == &p_cot)
6685 {
6686 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6687 errmsg = e_invarg;
6688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006689#endif /* FEAT_INS_EXPAND */
6690
6691
6692#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6693 else if (varp == &p_toolbar)
6694 {
6695 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6696 &toolbar_flags, TRUE) != OK)
6697 errmsg = e_invarg;
6698 else
6699 {
6700 out_flush();
6701 gui_mch_show_toolbar((toolbar_flags &
6702 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6703 }
6704 }
6705#endif
6706
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006707#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006708 /* 'toolbariconsize': GTK+ 2 only */
6709 else if (varp == &p_tbis)
6710 {
6711 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6712 errmsg = e_invarg;
6713 else
6714 {
6715 out_flush();
6716 gui_mch_show_toolbar((toolbar_flags &
6717 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6718 }
6719 }
6720#endif
6721
6722 /* 'pastetoggle': translate key codes like in a mapping */
6723 else if (varp == &p_pt)
6724 {
6725 if (*p_pt)
6726 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006727 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 if (p != NULL)
6729 {
6730 if (new_value_alloced)
6731 free_string_option(p_pt);
6732 p_pt = p;
6733 new_value_alloced = TRUE;
6734 }
6735 }
6736 }
6737
6738 /* 'backspace' */
6739 else if (varp == &p_bs)
6740 {
6741 if (VIM_ISDIGIT(*p_bs))
6742 {
6743 if (*p_bs >'2' || p_bs[1] != NUL)
6744 errmsg = e_invarg;
6745 }
6746 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6747 errmsg = e_invarg;
6748 }
6749
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006750#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 /* 'casemap' */
6752 else if (varp == &p_cmp)
6753 {
6754 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6755 errmsg = e_invarg;
6756 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758
6759#ifdef FEAT_DIFF
6760 /* 'diffopt' */
6761 else if (varp == &p_dip)
6762 {
6763 if (diffopt_changed() == FAIL)
6764 errmsg = e_invarg;
6765 }
6766#endif
6767
6768#ifdef FEAT_FOLDING
6769 /* 'foldmethod' */
6770 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6771 {
6772 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6773 || *curwin->w_p_fdm == NUL)
6774 errmsg = e_invarg;
6775 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006776 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006778 if (foldmethodIsDiff(curwin))
6779 newFoldLevel();
6780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 }
6782# ifdef FEAT_EVAL
6783 /* 'foldexpr' */
6784 else if (varp == &curwin->w_p_fde)
6785 {
6786 if (foldmethodIsExpr(curwin))
6787 foldUpdateAll(curwin);
6788 }
6789# endif
6790 /* 'foldmarker' */
6791 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6792 {
6793 p = vim_strchr(*varp, ',');
6794 if (p == NULL)
6795 errmsg = (char_u *)N_("E536: comma required");
6796 else if (p == *varp || p[1] == NUL)
6797 errmsg = e_invarg;
6798 else if (foldmethodIsMarker(curwin))
6799 foldUpdateAll(curwin);
6800 }
6801 /* 'commentstring' */
6802 else if (gvarp == &p_cms)
6803 {
6804 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6805 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6806 }
6807 /* 'foldopen' */
6808 else if (varp == &p_fdo)
6809 {
6810 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6811 errmsg = e_invarg;
6812 }
6813 /* 'foldclose' */
6814 else if (varp == &p_fcl)
6815 {
6816 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6817 errmsg = e_invarg;
6818 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006819 /* 'foldignore' */
6820 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6821 {
6822 if (foldmethodIsIndent(curwin))
6823 foldUpdateAll(curwin);
6824 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006825#endif
6826
6827#ifdef FEAT_VIRTUALEDIT
6828 /* 'virtualedit' */
6829 else if (varp == &p_ve)
6830 {
6831 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6832 errmsg = e_invarg;
6833 else if (STRCMP(p_ve, oldval) != 0)
6834 {
6835 /* Recompute cursor position in case the new 've' setting
6836 * changes something. */
6837 validate_virtcol();
6838 coladvance(curwin->w_virtcol);
6839 }
6840 }
6841#endif
6842
6843#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6844 else if (varp == &p_csqf)
6845 {
6846 if (p_csqf != NULL)
6847 {
6848 p = p_csqf;
6849 while (*p != NUL)
6850 {
6851 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6852 || p[1] == NUL
6853 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6854 || (p[2] != NUL && p[2] != ','))
6855 {
6856 errmsg = e_invarg;
6857 break;
6858 }
6859 else if (p[2] == NUL)
6860 break;
6861 else
6862 p += 3;
6863 }
6864 }
6865 }
6866#endif
6867
6868 /* Options that are a list of flags. */
6869 else
6870 {
6871 p = NULL;
6872 if (varp == &p_ww)
6873 p = (char_u *)WW_ALL;
6874 if (varp == &p_shm)
6875 p = (char_u *)SHM_ALL;
6876 else if (varp == &(p_cpo))
6877 p = (char_u *)CPO_ALL;
6878 else if (varp == &(curbuf->b_p_fo))
6879 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006880#ifdef FEAT_CONCEAL
6881 else if (varp == &curwin->w_p_cocu)
6882 p = (char_u *)COCU_ALL;
6883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 else if (varp == &p_mouse)
6885 {
6886#ifdef FEAT_MOUSE
6887 p = (char_u *)MOUSE_ALL;
6888#else
6889 if (*p_mouse != NUL)
6890 errmsg = (char_u *)N_("E538: No mouse support");
6891#endif
6892 }
6893#if defined(FEAT_GUI)
6894 else if (varp == &p_go)
6895 p = (char_u *)GO_ALL;
6896#endif
6897 if (p != NULL)
6898 {
6899 for (s = *varp; *s; ++s)
6900 if (vim_strchr(p, *s) == NULL)
6901 {
6902 errmsg = illegal_char(errbuf, *s);
6903 break;
6904 }
6905 }
6906 }
6907
6908 /*
6909 * If error detected, restore the previous value.
6910 */
6911 if (errmsg != NULL)
6912 {
6913 if (new_value_alloced)
6914 free_string_option(*varp);
6915 *varp = oldval;
6916 /*
6917 * When resetting some values, need to act on it.
6918 */
6919 if (did_chartab)
6920 (void)init_chartab();
6921 if (varp == &p_hl)
6922 (void)highlight_changed();
6923 }
6924 else
6925 {
6926#ifdef FEAT_EVAL
6927 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006928 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929#endif
6930 /*
6931 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006932 * Use "free_oldval", because recursiveness may change the flags under
6933 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006935 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 free_string_option(oldval);
6937 if (new_value_alloced)
6938 options[opt_idx].flags |= P_ALLOCED;
6939 else
6940 options[opt_idx].flags &= ~P_ALLOCED;
6941
6942 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006943 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944 {
6945 /* global option with local value set to use global value; free
6946 * the local value and make it empty */
6947 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6948 free_string_option(*(char_u **)p);
6949 *(char_u **)p = empty_option;
6950 }
6951
6952 /* May set global value for local option. */
6953 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6954 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006955
6956#ifdef FEAT_AUTOCMD
6957 /*
6958 * Trigger the autocommand only after setting the flags.
6959 */
6960# ifdef FEAT_SYN_HL
6961 /* When 'syntax' is set, load the syntax of that name */
6962 if (varp == &(curbuf->b_p_syn))
6963 {
6964 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6965 curbuf->b_fname, TRUE, curbuf);
6966 }
6967# endif
6968 else if (varp == &(curbuf->b_p_ft))
6969 {
6970 /* 'filetype' is set, trigger the FileType autocommand */
6971 did_filetype = TRUE;
6972 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6973 curbuf->b_fname, TRUE, curbuf);
6974 }
6975#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006976#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02006977 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006978 {
6979 char_u fname[200];
6980
6981 /*
6982 * Source the spell/LANG.vim in 'runtimepath'.
6983 * They could set 'spellcapcheck' depending on the language.
6984 * Use the first name in 'spelllang' up to '_region' or
6985 * '.encoding'.
6986 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006987 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006988 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6989 break;
6990 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02006991 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006992 source_runtime(fname, TRUE);
6993 }
6994#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 }
6996
6997#ifdef FEAT_MOUSE
6998 if (varp == &p_mouse)
6999 {
7000# ifdef FEAT_MOUSE_TTY
7001 if (*p_mouse == NUL)
7002 mch_setmouse(FALSE); /* switch mouse off */
7003 else
7004# endif
7005 setmouse(); /* in case 'mouse' changed */
7006 }
7007#endif
7008
7009 if (curwin->w_curswant != MAXCOL)
7010 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007011#ifdef FEAT_GUI
7012 /* check redraw when it's not a GUI option or the GUI is active. */
7013 if (!redraw_gui_only || gui.in_use)
7014#endif
7015 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016
7017 return errmsg;
7018}
7019
Bram Moolenaar1a384422010-07-14 19:53:30 +02007020#ifdef FEAT_SYN_HL
7021/*
7022 * Simple int comparison function for use with qsort()
7023 */
7024 static int
7025int_cmp(a, b)
7026 const void *a;
7027 const void *b;
7028{
7029 return *(const int *)a - *(const int *)b;
7030}
7031
7032/*
7033 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7034 * Returns error message, NULL if it's OK.
7035 */
7036 char_u *
7037check_colorcolumn(wp)
7038 win_T *wp;
7039{
7040 char_u *s;
7041 int col;
7042 int count = 0;
7043 int color_cols[256];
7044 int i;
7045 int j = 0;
7046
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007047 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007048 {
7049 if (*s == '-' || *s == '+')
7050 {
7051 /* -N and +N: add to 'textwidth' */
7052 col = (*s == '-') ? -1 : 1;
7053 ++s;
7054 if (!VIM_ISDIGIT(*s))
7055 return e_invarg;
7056 col = col * getdigits(&s);
7057 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007058 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007059 col += wp->w_buffer->b_p_tw;
7060 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007061 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007062 }
7063 else if (VIM_ISDIGIT(*s))
7064 col = getdigits(&s);
7065 else
7066 return e_invarg;
7067 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007068skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007069 if (*s == NUL)
7070 break;
7071 if (*s != ',')
7072 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007073 if (*++s == NUL)
7074 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007075 }
7076
7077 vim_free(wp->w_p_cc_cols);
7078 if (count == 0)
7079 wp->w_p_cc_cols = NULL;
7080 else
7081 {
7082 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7083 if (wp->w_p_cc_cols != NULL)
7084 {
7085 /* sort the columns for faster usage on screen redraw inside
7086 * win_line() */
7087 qsort(color_cols, count, sizeof(int), int_cmp);
7088
7089 for (i = 0; i < count; ++i)
7090 /* skip duplicates */
7091 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7092 wp->w_p_cc_cols[j++] = color_cols[i];
7093 wp->w_p_cc_cols[j] = -1; /* end marker */
7094 }
7095 }
7096
7097 return NULL; /* no error */
7098}
7099#endif
7100
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101/*
7102 * Handle setting 'listchars' or 'fillchars'.
7103 * Returns error message, NULL if it's OK.
7104 */
7105 static char_u *
7106set_chars_option(varp)
7107 char_u **varp;
7108{
7109 int round, i, len, entries;
7110 char_u *p, *s;
7111 int c1, c2 = 0;
7112 struct charstab
7113 {
7114 int *cp;
7115 char *name;
7116 };
7117#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7118 static struct charstab filltab[] =
7119 {
7120 {&fill_stl, "stl"},
7121 {&fill_stlnc, "stlnc"},
7122 {&fill_vert, "vert"},
7123 {&fill_fold, "fold"},
7124 {&fill_diff, "diff"},
7125 };
7126#endif
7127 static struct charstab lcstab[] =
7128 {
7129 {&lcs_eol, "eol"},
7130 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007131 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132 {&lcs_prec, "precedes"},
7133 {&lcs_tab2, "tab"},
7134 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007135#ifdef FEAT_CONCEAL
7136 {&lcs_conceal, "conceal"},
7137#else
7138 {NULL, "conceal"},
7139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 };
7141 struct charstab *tab;
7142
7143#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7144 if (varp == &p_lcs)
7145#endif
7146 {
7147 tab = lcstab;
7148 entries = sizeof(lcstab) / sizeof(struct charstab);
7149 }
7150#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7151 else
7152 {
7153 tab = filltab;
7154 entries = sizeof(filltab) / sizeof(struct charstab);
7155 }
7156#endif
7157
7158 /* first round: check for valid value, second round: assign values */
7159 for (round = 0; round <= 1; ++round)
7160 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007161 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162 {
7163 /* After checking that the value is valid: set defaults: space for
7164 * 'fillchars', NUL for 'listchars' */
7165 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007166 if (tab[i].cp != NULL)
7167 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168 if (varp == &p_lcs)
7169 lcs_tab1 = NUL;
7170#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7171 else
7172 fill_diff = '-';
7173#endif
7174 }
7175 p = *varp;
7176 while (*p)
7177 {
7178 for (i = 0; i < entries; ++i)
7179 {
7180 len = (int)STRLEN(tab[i].name);
7181 if (STRNCMP(p, tab[i].name, len) == 0
7182 && p[len] == ':'
7183 && p[len + 1] != NUL)
7184 {
7185 s = p + len + 1;
7186#ifdef FEAT_MBYTE
7187 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007188 if (mb_char2cells(c1) > 1)
7189 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190#else
7191 c1 = *s++;
7192#endif
7193 if (tab[i].cp == &lcs_tab2)
7194 {
7195 if (*s == NUL)
7196 continue;
7197#ifdef FEAT_MBYTE
7198 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007199 if (mb_char2cells(c2) > 1)
7200 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201#else
7202 c2 = *s++;
7203#endif
7204 }
7205 if (*s == ',' || *s == NUL)
7206 {
7207 if (round)
7208 {
7209 if (tab[i].cp == &lcs_tab2)
7210 {
7211 lcs_tab1 = c1;
7212 lcs_tab2 = c2;
7213 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007214 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215 *(tab[i].cp) = c1;
7216
7217 }
7218 p = s;
7219 break;
7220 }
7221 }
7222 }
7223
7224 if (i == entries)
7225 return e_invarg;
7226 if (*p == ',')
7227 ++p;
7228 }
7229 }
7230
7231 return NULL; /* no error */
7232}
7233
7234#ifdef FEAT_STL_OPT
7235/*
7236 * Check validity of options with the 'statusline' format.
7237 * Return error message or NULL.
7238 */
7239 char_u *
7240check_stl_option(s)
7241 char_u *s;
7242{
7243 int itemcnt = 0;
7244 int groupdepth = 0;
7245 static char_u errbuf[80];
7246
7247 while (*s && itemcnt < STL_MAX_ITEM)
7248 {
7249 /* Check for valid keys after % sequences */
7250 while (*s && *s != '%')
7251 s++;
7252 if (!*s)
7253 break;
7254 s++;
7255 if (*s != '%' && *s != ')')
7256 ++itemcnt;
7257 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7258 {
7259 s++;
7260 continue;
7261 }
7262 if (*s == ')')
7263 {
7264 s++;
7265 if (--groupdepth < 0)
7266 break;
7267 continue;
7268 }
7269 if (*s == '-')
7270 s++;
7271 while (VIM_ISDIGIT(*s))
7272 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007273 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 continue;
7275 if (*s == '.')
7276 {
7277 s++;
7278 while (*s && VIM_ISDIGIT(*s))
7279 s++;
7280 }
7281 if (*s == '(')
7282 {
7283 groupdepth++;
7284 continue;
7285 }
7286 if (vim_strchr(STL_ALL, *s) == NULL)
7287 {
7288 return illegal_char(errbuf, *s);
7289 }
7290 if (*s == '{')
7291 {
7292 s++;
7293 while (*s != '}' && *s)
7294 s++;
7295 if (*s != '}')
7296 return (char_u *)N_("E540: Unclosed expression sequence");
7297 }
7298 }
7299 if (itemcnt >= STL_MAX_ITEM)
7300 return (char_u *)N_("E541: too many items");
7301 if (groupdepth != 0)
7302 return (char_u *)N_("E542: unbalanced groups");
7303 return NULL;
7304}
7305#endif
7306
7307#ifdef FEAT_CLIPBOARD
7308/*
7309 * Extract the items in the 'clipboard' option and set global values.
7310 */
7311 static char_u *
7312check_clipboard_option()
7313{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007314 int new_unnamed = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007315 int new_autoselect = FALSE;
7316 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007317 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318 regprog_T *new_exclude_prog = NULL;
7319 char_u *errmsg = NULL;
7320 char_u *p;
7321
7322 for (p = p_cb; *p != NUL; )
7323 {
7324 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7325 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007326 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327 p += 7;
7328 }
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007329 else if (STRNCMP(p, "unnamedplus", 11) == 0
7330 && (p[11] == ',' || p[11] == NUL))
7331 {
7332 new_unnamed |= CLIP_UNNAMED_PLUS;
7333 p += 11;
7334 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 else if (STRNCMP(p, "autoselect", 10) == 0
7336 && (p[10] == ',' || p[10] == NUL))
7337 {
7338 new_autoselect = TRUE;
7339 p += 10;
7340 }
7341 else if (STRNCMP(p, "autoselectml", 12) == 0
7342 && (p[12] == ',' || p[12] == NUL))
7343 {
7344 new_autoselectml = TRUE;
7345 p += 12;
7346 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007347 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7348 {
7349 new_html = TRUE;
7350 p += 4;
7351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7353 {
7354 p += 8;
7355 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7356 if (new_exclude_prog == NULL)
7357 errmsg = e_invarg;
7358 break;
7359 }
7360 else
7361 {
7362 errmsg = e_invarg;
7363 break;
7364 }
7365 if (*p == ',')
7366 ++p;
7367 }
7368 if (errmsg == NULL)
7369 {
7370 clip_unnamed = new_unnamed;
7371 clip_autoselect = new_autoselect;
7372 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007373 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 vim_free(clip_exclude_prog);
7375 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007376#ifdef FEAT_GUI_GTK
7377 if (gui.in_use)
7378 {
7379 gui_gtk_set_selection_targets();
7380 gui_gtk_set_dnd_targets();
7381 }
7382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383 }
7384 else
7385 vim_free(new_exclude_prog);
7386
7387 return errmsg;
7388}
7389#endif
7390
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007391#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007392/*
7393 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7394 * Return error message when failed, NULL when OK.
7395 */
7396 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007397compile_cap_prog(synblock)
7398 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007399{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007400 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007401 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007402
Bram Moolenaar860cae12010-06-05 23:22:07 +02007403 if (*synblock->b_p_spc == NUL)
7404 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007405 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007406 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007407 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007408 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007409 if (re != NULL)
7410 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007411 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7412 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007413 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007414 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007415 return e_invarg;
7416 }
7417 vim_free(re);
7418 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007419 }
7420
7421 vim_free(rp);
7422 return NULL;
7423}
7424#endif
7425
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007426#if defined(FEAT_EVAL) || defined(PROTO)
7427/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007428 * Set the scriptID for an option, taking care of setting the buffer- or
7429 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007430 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007431 static void
7432set_option_scriptID_idx(opt_idx, opt_flags, id)
7433 int opt_idx;
7434 int opt_flags;
7435 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007436{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007437 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7438 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007439
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007440 /* Remember where the option was set. For local options need to do that
7441 * in the buffer or window structure. */
7442 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007443 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007444 if (both || (opt_flags & OPT_LOCAL))
7445 {
7446 if (indir & PV_BUF)
7447 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7448 else if (indir & PV_WIN)
7449 curwin->w_p_scriptID[indir & PV_MASK] = id;
7450 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007451}
7452#endif
7453
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454/*
7455 * Set the value of a boolean option, and take care of side effects.
7456 * Returns NULL for success, or an error message for an error.
7457 */
7458 static char_u *
7459set_bool_option(opt_idx, varp, value, opt_flags)
7460 int opt_idx; /* index in options[] table */
7461 char_u *varp; /* pointer to the option variable */
7462 int value; /* new value */
7463 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7464{
7465 int old_value = *(int *)varp;
7466
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 /* Disallow changing some options from secure mode */
7468 if ((secure
7469#ifdef HAVE_SANDBOX
7470 || sandbox != 0
7471#endif
7472 ) && (options[opt_idx].flags & P_SECURE))
7473 return e_secure;
7474
7475 *(int *)varp = value; /* set the new value */
7476#ifdef FEAT_EVAL
7477 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007478 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479#endif
7480
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007481#ifdef FEAT_GUI
7482 need_mouse_correct = TRUE;
7483#endif
7484
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 /* May set global value for local option. */
7486 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7487 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7488
7489 /*
7490 * Handle side effects of changing a bool option.
7491 */
7492
7493 /* 'compatible' */
7494 if ((int *)varp == &p_cp)
7495 {
7496 compatible_set();
7497 }
7498
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007499 /* 'list', 'number' */
7500 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007501 || (int *)varp == &curwin->w_p_nu
7502 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007503 {
7504 if (curwin->w_curswant != MAXCOL)
7505 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007506
7507 /* If 'number' is set, reset 'relativenumber'. */
7508 /* If 'relativenumber' is set, reset 'number'. */
7509 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7510 curwin->w_p_rnu = FALSE;
7511 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7512 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007513 }
7514
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 else if ((int *)varp == &curbuf->b_p_ro)
7516 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007517 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7519 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007520
7521 /* when 'readonly' is set may give W10 again */
7522 if (curbuf->b_p_ro)
7523 curbuf->b_did_warn = FALSE;
7524
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007526 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527#endif
7528 }
7529
Bram Moolenaar9c449722010-07-20 18:44:27 +02007530#ifdef FEAT_GUI
7531 else if ((int *)varp == &p_mh)
7532 {
7533 if (!p_mh)
7534 gui_mch_mousehide(FALSE);
7535 }
7536#endif
7537
Bram Moolenaara539df02010-08-01 14:35:05 +02007538#ifdef FEAT_TITLE
7539 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007541 {
7542 redraw_titles();
7543 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544 /* when 'endofline' is changed, redraw the window title */
7545 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007546 {
7547 redraw_titles();
7548 }
7549# ifdef FEAT_MBYTE
7550 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007551 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007552 {
7553 redraw_titles();
7554 }
7555# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007556#endif
7557
7558 /* when 'bin' is set also set some other options */
7559 else if ((int *)varp == &curbuf->b_p_bin)
7560 {
7561 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7562#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007563 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564#endif
7565 }
7566
7567#ifdef FEAT_AUTOCMD
7568 /* when 'buflisted' changes, trigger autocommands */
7569 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7570 {
7571 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7572 NULL, NULL, TRUE, curbuf);
7573 }
7574#endif
7575
7576 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7577 else if ((int *)varp == &curbuf->b_p_swf)
7578 {
7579 if (curbuf->b_p_swf && p_uc)
7580 ml_open_file(curbuf); /* create the swap file */
7581 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007582 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7583 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584 mf_close_file(curbuf, TRUE); /* remove the swap file */
7585 }
7586
7587 /* when 'terse' is set change 'shortmess' */
7588 else if ((int *)varp == &p_terse)
7589 {
7590 char_u *p;
7591
7592 p = vim_strchr(p_shm, SHM_SEARCH);
7593
7594 /* insert 's' in p_shm */
7595 if (p_terse && p == NULL)
7596 {
7597 STRCPY(IObuff, p_shm);
7598 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007599 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600 }
7601 /* remove 's' from p_shm */
7602 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007603 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604 }
7605
7606 /* when 'paste' is set or reset also change other options */
7607 else if ((int *)varp == &p_paste)
7608 {
7609 paste_option_changed();
7610 }
7611
7612 /* when 'insertmode' is set from an autocommand need to do work here */
7613 else if ((int *)varp == &p_im)
7614 {
7615 if (p_im)
7616 {
7617 if ((State & INSERT) == 0)
7618 need_start_insertmode = TRUE;
7619 stop_insert_mode = FALSE;
7620 }
7621 else
7622 {
7623 need_start_insertmode = FALSE;
7624 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007625 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007626 clear_cmdline = TRUE; /* remove "(insert)" */
7627 restart_edit = 0;
7628 }
7629 }
7630
7631 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7632 else if ((int *)varp == &p_ic && p_hls)
7633 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007634 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635 }
7636
7637#ifdef FEAT_SEARCH_EXTRA
7638 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7639 else if ((int *)varp == &p_hls)
7640 {
7641 no_hlsearch = FALSE;
7642 }
7643#endif
7644
7645#ifdef FEAT_SCROLLBIND
7646 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7647 * at the end of normal_cmd() */
7648 else if ((int *)varp == &curwin->w_p_scb)
7649 {
7650 if (curwin->w_p_scb)
7651 do_check_scrollbind(FALSE);
7652 }
7653#endif
7654
7655#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7656 /* There can be only one window with 'previewwindow' set. */
7657 else if ((int *)varp == &curwin->w_p_pvw)
7658 {
7659 if (curwin->w_p_pvw)
7660 {
7661 win_T *win;
7662
7663 for (win = firstwin; win != NULL; win = win->w_next)
7664 if (win->w_p_pvw && win != curwin)
7665 {
7666 curwin->w_p_pvw = FALSE;
7667 return (char_u *)N_("E590: A preview window already exists");
7668 }
7669 }
7670 }
7671#endif
7672
7673 /* when 'textmode' is set or reset also change 'fileformat' */
7674 else if ((int *)varp == &curbuf->b_p_tx)
7675 {
7676 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7677 }
7678
7679 /* when 'textauto' is set or reset also change 'fileformats' */
7680 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 set_string_option_direct((char_u *)"ffs", -1,
7682 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007683 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684
7685 /*
7686 * When 'lisp' option changes include/exclude '-' in
7687 * keyword characters.
7688 */
7689#ifdef FEAT_LISP
7690 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7691 {
7692 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7693 }
7694#endif
7695
7696#ifdef FEAT_TITLE
7697 /* when 'title' changed, may need to change the title; same for 'icon' */
7698 else if ((int *)varp == &p_title)
7699 {
7700 did_set_title(FALSE);
7701 }
7702
7703 else if ((int *)varp == &p_icon)
7704 {
7705 did_set_title(TRUE);
7706 }
7707#endif
7708
7709 else if ((int *)varp == &curbuf->b_changed)
7710 {
7711 if (!value)
7712 save_file_ff(curbuf); /* Buffer is unchanged */
7713#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007714 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715#endif
7716#ifdef FEAT_AUTOCMD
7717 modified_was_set = value;
7718#endif
7719 }
7720
7721#ifdef BACKSLASH_IN_FILENAME
7722 else if ((int *)varp == &p_ssl)
7723 {
7724 if (p_ssl)
7725 {
7726 psepc = '/';
7727 psepcN = '\\';
7728 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 }
7730 else
7731 {
7732 psepc = '\\';
7733 psepcN = '/';
7734 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 }
7736
7737 /* need to adjust the file name arguments and buffer names. */
7738 buflist_slash_adjust();
7739 alist_slash_adjust();
7740# ifdef FEAT_EVAL
7741 scriptnames_slash_adjust();
7742# endif
7743 }
7744#endif
7745
7746 /* If 'wrap' is set, set w_leftcol to zero. */
7747 else if ((int *)varp == &curwin->w_p_wrap)
7748 {
7749 if (curwin->w_p_wrap)
7750 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007751 if (curwin->w_curswant != MAXCOL)
7752 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753 }
7754
7755#ifdef FEAT_WINDOWS
7756 else if ((int *)varp == &p_ea)
7757 {
7758 if (p_ea && !old_value)
7759 win_equal(curwin, FALSE, 0);
7760 }
7761#endif
7762
7763 else if ((int *)varp == &p_wiv)
7764 {
7765 /*
7766 * When 'weirdinvert' changed, set/reset 't_xs'.
7767 * Then set 'weirdinvert' according to value of 't_xs'.
7768 */
7769 if (p_wiv && !old_value)
7770 T_XS = (char_u *)"y";
7771 else if (!p_wiv && old_value)
7772 T_XS = empty_option;
7773 p_wiv = (*T_XS != NUL);
7774 }
7775
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007776#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 else if ((int *)varp == &p_beval)
7778 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 if (p_beval == TRUE)
7780 gui_mch_enable_beval_area(balloonEval);
7781 else
7782 gui_mch_disable_beval_area(balloonEval);
7783 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007786#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 else if ((int *)varp == &p_acd)
7788 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007789 /* Change directories when the 'acd' option is set now. */
7790 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 }
7792#endif
7793
7794#ifdef FEAT_DIFF
7795 /* 'diff' */
7796 else if ((int *)varp == &curwin->w_p_diff)
7797 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007798 /* May add or remove the buffer from the list of diff buffers. */
7799 diff_buf_adjust(curwin);
7800# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 if (foldmethodIsDiff(curwin))
7802 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007803# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804 }
7805#endif
7806
7807#ifdef USE_IM_CONTROL
7808 /* 'imdisable' */
7809 else if ((int *)varp == &p_imdisable)
7810 {
7811 /* Only de-activate it here, it will be enabled when changing mode. */
7812 if (p_imdisable)
7813 im_set_active(FALSE);
7814 }
7815#endif
7816
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007817#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007818 /* 'spell' */
7819 else if ((int *)varp == &curwin->w_p_spell)
7820 {
7821 if (curwin->w_p_spell)
7822 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007823 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007824 if (errmsg != NULL)
7825 EMSG(_(errmsg));
7826 }
7827 }
7828#endif
7829
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830#ifdef FEAT_FKMAP
7831 else if ((int *)varp == &p_altkeymap)
7832 {
7833 if (old_value != p_altkeymap)
7834 {
7835 if (!p_altkeymap)
7836 {
7837 p_hkmap = p_fkmap;
7838 p_fkmap = 0;
7839 }
7840 else
7841 {
7842 p_fkmap = p_hkmap;
7843 p_hkmap = 0;
7844 }
7845 (void)init_chartab();
7846 }
7847 }
7848
7849 /*
7850 * In case some second language keymapping options have changed, check
7851 * and correct the setting in a consistent way.
7852 */
7853
7854 /*
7855 * If hkmap or fkmap are set, reset Arabic keymapping.
7856 */
7857 if ((p_hkmap || p_fkmap) && p_altkeymap)
7858 {
7859 p_altkeymap = p_fkmap;
7860# ifdef FEAT_ARABIC
7861 curwin->w_p_arab = FALSE;
7862# endif
7863 (void)init_chartab();
7864 }
7865
7866 /*
7867 * If hkmap set, reset Farsi keymapping.
7868 */
7869 if (p_hkmap && p_altkeymap)
7870 {
7871 p_altkeymap = 0;
7872 p_fkmap = 0;
7873# ifdef FEAT_ARABIC
7874 curwin->w_p_arab = FALSE;
7875# endif
7876 (void)init_chartab();
7877 }
7878
7879 /*
7880 * If fkmap set, reset Hebrew keymapping.
7881 */
7882 if (p_fkmap && !p_altkeymap)
7883 {
7884 p_altkeymap = 1;
7885 p_hkmap = 0;
7886# ifdef FEAT_ARABIC
7887 curwin->w_p_arab = FALSE;
7888# endif
7889 (void)init_chartab();
7890 }
7891#endif
7892
7893#ifdef FEAT_ARABIC
7894 if ((int *)varp == &curwin->w_p_arab)
7895 {
7896 if (curwin->w_p_arab)
7897 {
7898 /*
7899 * 'arabic' is set, handle various sub-settings.
7900 */
7901 if (!p_tbidi)
7902 {
7903 /* set rightleft mode */
7904 if (!curwin->w_p_rl)
7905 {
7906 curwin->w_p_rl = TRUE;
7907 changed_window_setting();
7908 }
7909
7910 /* Enable Arabic shaping (major part of what Arabic requires) */
7911 if (!p_arshape)
7912 {
7913 p_arshape = TRUE;
7914 redraw_later_clear();
7915 }
7916 }
7917
7918 /* Arabic requires a utf-8 encoding, inform the user if its not
7919 * set. */
7920 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007921 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007922 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7923
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007924 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007925 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7926#ifdef FEAT_EVAL
7927 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7928#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007929 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930
7931# ifdef FEAT_MBYTE
7932 /* set 'delcombine' */
7933 p_deco = TRUE;
7934# endif
7935
7936# ifdef FEAT_KEYMAP
7937 /* Force-set the necessary keymap for arabic */
7938 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7939 OPT_LOCAL);
7940# endif
7941# ifdef FEAT_FKMAP
7942 p_altkeymap = 0;
7943 p_hkmap = 0;
7944 p_fkmap = 0;
7945 (void)init_chartab();
7946# endif
7947 }
7948 else
7949 {
7950 /*
7951 * 'arabic' is reset, handle various sub-settings.
7952 */
7953 if (!p_tbidi)
7954 {
7955 /* reset rightleft mode */
7956 if (curwin->w_p_rl)
7957 {
7958 curwin->w_p_rl = FALSE;
7959 changed_window_setting();
7960 }
7961
7962 /* 'arabicshape' isn't reset, it is a global option and
7963 * another window may still need it "on". */
7964 }
7965
7966 /* 'delcombine' isn't reset, it is a global option and another
7967 * window may still want it "on". */
7968
7969# ifdef FEAT_KEYMAP
7970 /* Revert to the default keymap */
7971 curbuf->b_p_iminsert = B_IMODE_NONE;
7972 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7973# endif
7974 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007975 if (curwin->w_curswant != MAXCOL)
7976 curwin->w_set_curswant = TRUE;
7977 }
7978
7979 else if ((int *)varp == &p_arshape)
7980 {
7981 if (curwin->w_curswant != MAXCOL)
7982 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984#endif
7985
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007986#ifdef FEAT_LINEBREAK
7987 if ((int *)varp == &curwin->w_p_lbr)
7988 {
7989 if (curwin->w_curswant != MAXCOL)
7990 curwin->w_set_curswant = TRUE;
7991 }
7992#endif
7993
7994#ifdef FEAT_RIGHTLEFT
7995 if ((int *)varp == &curwin->w_p_rl)
7996 {
7997 if (curwin->w_curswant != MAXCOL)
7998 curwin->w_set_curswant = TRUE;
7999 }
8000#endif
8001
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 /*
8003 * End of handling side effects for bool options.
8004 */
8005
8006 options[opt_idx].flags |= P_WAS_SET;
8007
8008 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008009
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 check_redraw(options[opt_idx].flags);
8011
8012 return NULL;
8013}
8014
8015/*
8016 * Set the value of a number option, and take care of side effects.
8017 * Returns NULL for success, or an error message for an error.
8018 */
8019 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008020set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 int opt_idx; /* index in options[] table */
8022 char_u *varp; /* pointer to the option variable */
8023 long value; /* new value */
8024 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008025 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8027 OPT_MODELINE */
8028{
8029 char_u *errmsg = NULL;
8030 long old_value = *(long *)varp;
8031 long old_Rows = Rows; /* remember old Rows */
8032 long old_Columns = Columns; /* remember old Columns */
8033 long *pp = (long *)varp;
8034
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008035 /* Disallow changing some options from secure mode. */
8036 if ((secure
8037#ifdef HAVE_SANDBOX
8038 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008040 ) && (options[opt_idx].flags & P_SECURE))
8041 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042
8043 *pp = value;
8044#ifdef FEAT_EVAL
8045 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008046 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008048#ifdef FEAT_GUI
8049 need_mouse_correct = TRUE;
8050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008051
8052 if (curbuf->b_p_sw <= 0)
8053 {
8054 errmsg = e_positive;
8055 curbuf->b_p_sw = curbuf->b_p_ts;
8056 }
8057
8058 /*
8059 * Number options that need some action when changed
8060 */
8061#ifdef FEAT_WINDOWS
8062 if (pp == &p_wh || pp == &p_hh)
8063 {
8064 if (p_wh < 1)
8065 {
8066 errmsg = e_positive;
8067 p_wh = 1;
8068 }
8069 if (p_wmh > p_wh)
8070 {
8071 errmsg = e_winheight;
8072 p_wh = p_wmh;
8073 }
8074 if (p_hh < 0)
8075 {
8076 errmsg = e_positive;
8077 p_hh = 0;
8078 }
8079
8080 /* Change window height NOW */
8081 if (lastwin != firstwin)
8082 {
8083 if (pp == &p_wh && curwin->w_height < p_wh)
8084 win_setheight((int)p_wh);
8085 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8086 win_setheight((int)p_hh);
8087 }
8088 }
8089
8090 /* 'winminheight' */
8091 else if (pp == &p_wmh)
8092 {
8093 if (p_wmh < 0)
8094 {
8095 errmsg = e_positive;
8096 p_wmh = 0;
8097 }
8098 if (p_wmh > p_wh)
8099 {
8100 errmsg = e_winheight;
8101 p_wmh = p_wh;
8102 }
8103 win_setminheight();
8104 }
8105
8106# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008107 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 {
8109 if (p_wiw < 1)
8110 {
8111 errmsg = e_positive;
8112 p_wiw = 1;
8113 }
8114 if (p_wmw > p_wiw)
8115 {
8116 errmsg = e_winwidth;
8117 p_wiw = p_wmw;
8118 }
8119
8120 /* Change window width NOW */
8121 if (lastwin != firstwin && curwin->w_width < p_wiw)
8122 win_setwidth((int)p_wiw);
8123 }
8124
8125 /* 'winminwidth' */
8126 else if (pp == &p_wmw)
8127 {
8128 if (p_wmw < 0)
8129 {
8130 errmsg = e_positive;
8131 p_wmw = 0;
8132 }
8133 if (p_wmw > p_wiw)
8134 {
8135 errmsg = e_winwidth;
8136 p_wmw = p_wiw;
8137 }
8138 win_setminheight();
8139 }
8140# endif
8141
8142#endif
8143
8144#ifdef FEAT_WINDOWS
8145 /* (re)set last window status line */
8146 else if (pp == &p_ls)
8147 {
8148 last_status(FALSE);
8149 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008150
8151 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008152 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008153 {
8154 shell_new_rows(); /* recompute window positions and heights */
8155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156#endif
8157
8158#ifdef FEAT_GUI
8159 else if (pp == &p_linespace)
8160 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008161 /* Recompute gui.char_height and resize the Vim window to keep the
8162 * same number of lines. */
8163 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008164 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 }
8166#endif
8167
8168#ifdef FEAT_FOLDING
8169 /* 'foldlevel' */
8170 else if (pp == &curwin->w_p_fdl)
8171 {
8172 if (curwin->w_p_fdl < 0)
8173 curwin->w_p_fdl = 0;
8174 newFoldLevel();
8175 }
8176
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008177 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 else if (pp == &curwin->w_p_fml)
8179 {
8180 foldUpdateAll(curwin);
8181 }
8182
8183 /* 'foldnestmax' */
8184 else if (pp == &curwin->w_p_fdn)
8185 {
8186 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8187 foldUpdateAll(curwin);
8188 }
8189
8190 /* 'foldcolumn' */
8191 else if (pp == &curwin->w_p_fdc)
8192 {
8193 if (curwin->w_p_fdc < 0)
8194 {
8195 errmsg = e_positive;
8196 curwin->w_p_fdc = 0;
8197 }
8198 else if (curwin->w_p_fdc > 12)
8199 {
8200 errmsg = e_invarg;
8201 curwin->w_p_fdc = 12;
8202 }
8203 }
8204
8205 /* 'shiftwidth' or 'tabstop' */
8206 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8207 {
8208 if (foldmethodIsIndent(curwin))
8209 foldUpdateAll(curwin);
8210 }
8211#endif /* FEAT_FOLDING */
8212
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008213#ifdef FEAT_MBYTE
8214 /* 'maxcombine' */
8215 else if (pp == &p_mco)
8216 {
8217 if (p_mco > MAX_MCO)
8218 p_mco = MAX_MCO;
8219 else if (p_mco < 0)
8220 p_mco = 0;
8221 screenclear(); /* will re-allocate the screen */
8222 }
8223#endif
8224
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225 else if (pp == &curbuf->b_p_iminsert)
8226 {
8227 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8228 {
8229 errmsg = e_invarg;
8230 curbuf->b_p_iminsert = B_IMODE_NONE;
8231 }
8232 p_iminsert = curbuf->b_p_iminsert;
8233 if (termcap_active) /* don't do this in the alternate screen */
8234 showmode();
8235#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8236 /* Show/unshow value of 'keymap' in status lines. */
8237 status_redraw_curbuf();
8238#endif
8239 }
8240
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008241 else if (pp == &p_window)
8242 {
8243 if (p_window < 1)
8244 p_window = 1;
8245 else if (p_window >= Rows)
8246 p_window = Rows - 1;
8247 }
8248
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249 else if (pp == &curbuf->b_p_imsearch)
8250 {
8251 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8252 {
8253 errmsg = e_invarg;
8254 curbuf->b_p_imsearch = B_IMODE_NONE;
8255 }
8256 p_imsearch = curbuf->b_p_imsearch;
8257 }
8258
8259#ifdef FEAT_TITLE
8260 /* if 'titlelen' has changed, redraw the title */
8261 else if (pp == &p_titlelen)
8262 {
8263 if (p_titlelen < 0)
8264 {
8265 errmsg = e_positive;
8266 p_titlelen = 85;
8267 }
8268 if (starting != NO_SCREEN && old_value != p_titlelen)
8269 need_maketitle = TRUE;
8270 }
8271#endif
8272
8273 /* if p_ch changed value, change the command line height */
8274 else if (pp == &p_ch)
8275 {
8276 if (p_ch < 1)
8277 {
8278 errmsg = e_positive;
8279 p_ch = 1;
8280 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008281 if (p_ch > Rows - min_rows() + 1)
8282 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283
8284 /* Only compute the new window layout when startup has been
8285 * completed. Otherwise the frame sizes may be wrong. */
8286 if (p_ch != old_value && full_screen
8287#ifdef FEAT_GUI
8288 && !gui.starting
8289#endif
8290 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008291 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008292 }
8293
8294 /* when 'updatecount' changes from zero to non-zero, open swap files */
8295 else if (pp == &p_uc)
8296 {
8297 if (p_uc < 0)
8298 {
8299 errmsg = e_positive;
8300 p_uc = 100;
8301 }
8302 if (p_uc && !old_value)
8303 ml_open_files();
8304 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008305#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008306 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008307 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008308 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008309 {
8310 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008311 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008312 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008313 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008314 {
8315 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008316 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008317 }
8318 }
8319#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008320#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008321 else if (pp == &p_mzq)
8322 mzvim_reset_timer();
8323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324
8325 /* sync undo before 'undolevels' changes */
8326 else if (pp == &p_ul)
8327 {
8328 /* use the old value, otherwise u_sync() may not work properly */
8329 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008330 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331 p_ul = value;
8332 }
8333
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008334#ifdef FEAT_LINEBREAK
8335 /* 'numberwidth' must be positive */
8336 else if (pp == &curwin->w_p_nuw)
8337 {
8338 if (curwin->w_p_nuw < 1)
8339 {
8340 errmsg = e_positive;
8341 curwin->w_p_nuw = 1;
8342 }
8343 if (curwin->w_p_nuw > 10)
8344 {
8345 errmsg = e_invarg;
8346 curwin->w_p_nuw = 10;
8347 }
8348 curwin->w_nrwidth_line_count = 0;
8349 }
8350#endif
8351
Bram Moolenaar1a384422010-07-14 19:53:30 +02008352 else if (pp == &curbuf->b_p_tw)
8353 {
8354 if (curbuf->b_p_tw < 0)
8355 {
8356 errmsg = e_positive;
8357 curbuf->b_p_tw = 0;
8358 }
8359#ifdef FEAT_SYN_HL
8360# ifdef FEAT_WINDOWS
8361 {
8362 win_T *wp;
8363 tabpage_T *tp;
8364
8365 FOR_ALL_TAB_WINDOWS(tp, wp)
8366 check_colorcolumn(wp);
8367 }
8368# else
8369 check_colorcolumn(curwin);
8370# endif
8371#endif
8372 }
8373
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 /*
8375 * Check the bounds for numeric options here
8376 */
8377 if (Rows < min_rows() && full_screen)
8378 {
8379 if (errbuf != NULL)
8380 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008381 vim_snprintf((char *)errbuf, errbuflen,
8382 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 errmsg = errbuf;
8384 }
8385 Rows = min_rows();
8386 }
8387 if (Columns < MIN_COLUMNS && full_screen)
8388 {
8389 if (errbuf != NULL)
8390 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008391 vim_snprintf((char *)errbuf, errbuflen,
8392 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 errmsg = errbuf;
8394 }
8395 Columns = MIN_COLUMNS;
8396 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008397 /* Limit the values to avoid an overflow in Rows * Columns. */
8398 if (Columns > 10000)
8399 Columns = 10000;
8400 if (Rows > 1000)
8401 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402
8403#ifdef DJGPP
8404 /* avoid a crash by checking for a too large value of 'columns' */
8405 if (old_Columns != Columns && full_screen && term_console)
8406 mch_check_columns();
8407#endif
8408
8409 /*
8410 * If the screen (shell) height has been changed, assume it is the
8411 * physical screenheight.
8412 */
8413 if (old_Rows != Rows || old_Columns != Columns)
8414 {
8415 /* Changing the screen size is not allowed while updating the screen. */
8416 if (updating_screen)
8417 *pp = old_value;
8418 else if (full_screen
8419#ifdef FEAT_GUI
8420 && !gui.starting
8421#endif
8422 )
8423 set_shellsize((int)Columns, (int)Rows, TRUE);
8424 else
8425 {
8426 /* Postpone the resizing; check the size and cmdline position for
8427 * messages. */
8428 check_shellsize();
8429 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8430 cmdline_row = Rows - p_ch;
8431 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008432 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008433 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 }
8435
8436 if (curbuf->b_p_sts < 0)
8437 {
8438 errmsg = e_positive;
8439 curbuf->b_p_sts = 0;
8440 }
8441 if (curbuf->b_p_ts <= 0)
8442 {
8443 errmsg = e_positive;
8444 curbuf->b_p_ts = 8;
8445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446 if (p_tm < 0)
8447 {
8448 errmsg = e_positive;
8449 p_tm = 0;
8450 }
8451 if ((curwin->w_p_scr <= 0
8452 || (curwin->w_p_scr > curwin->w_height
8453 && curwin->w_height > 0))
8454 && full_screen)
8455 {
8456 if (pp == &(curwin->w_p_scr))
8457 {
8458 if (curwin->w_p_scr != 0)
8459 errmsg = e_scroll;
8460 win_comp_scroll(curwin);
8461 }
8462 /* If 'scroll' became invalid because of a side effect silently adjust
8463 * it. */
8464 else if (curwin->w_p_scr <= 0)
8465 curwin->w_p_scr = 1;
8466 else /* curwin->w_p_scr > curwin->w_height */
8467 curwin->w_p_scr = curwin->w_height;
8468 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008469 if (p_hi < 0)
8470 {
8471 errmsg = e_positive;
8472 p_hi = 0;
8473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 if (p_report < 0)
8475 {
8476 errmsg = e_positive;
8477 p_report = 1;
8478 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008479 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480 {
8481 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8482 p_sj = Rows / 2;
8483 else
8484 {
8485 errmsg = e_scroll;
8486 p_sj = 1;
8487 }
8488 }
8489 if (p_so < 0 && full_screen)
8490 {
8491 errmsg = e_scroll;
8492 p_so = 0;
8493 }
8494 if (p_siso < 0 && full_screen)
8495 {
8496 errmsg = e_positive;
8497 p_siso = 0;
8498 }
8499#ifdef FEAT_CMDWIN
8500 if (p_cwh < 1)
8501 {
8502 errmsg = e_positive;
8503 p_cwh = 1;
8504 }
8505#endif
8506 if (p_ut < 0)
8507 {
8508 errmsg = e_positive;
8509 p_ut = 2000;
8510 }
8511 if (p_ss < 0)
8512 {
8513 errmsg = e_positive;
8514 p_ss = 0;
8515 }
8516
8517 /* May set global value for local option. */
8518 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8519 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8520
8521 options[opt_idx].flags |= P_WAS_SET;
8522
8523 comp_col(); /* in case 'columns' or 'ls' changed */
8524 if (curwin->w_curswant != MAXCOL)
8525 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8526 check_redraw(options[opt_idx].flags);
8527
8528 return errmsg;
8529}
8530
8531/*
8532 * Called after an option changed: check if something needs to be redrawn.
8533 */
8534 static void
8535check_redraw(flags)
8536 long_u flags;
8537{
8538 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8539 int clear = (flags & P_RCLR) == P_RCLR;
8540 int all = ((flags & P_RALL) == P_RALL || clear);
8541
8542#ifdef FEAT_WINDOWS
8543 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8544 status_redraw_all();
8545#endif
8546
8547 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8548 changed_window_setting();
8549 if (flags & P_RBUF)
8550 redraw_curbuf_later(NOT_VALID);
8551 if (clear)
8552 redraw_all_later(CLEAR);
8553 else if (all)
8554 redraw_all_later(NOT_VALID);
8555}
8556
8557/*
8558 * Find index for option 'arg'.
8559 * Return -1 if not found.
8560 */
8561 static int
8562findoption(arg)
8563 char_u *arg;
8564{
8565 int opt_idx;
8566 char *s, *p;
8567 static short quick_tab[27] = {0, 0}; /* quick access table */
8568 int is_term_opt;
8569
8570 /*
8571 * For first call: Initialize the quick-access table.
8572 * It contains the index for the first option that starts with a certain
8573 * letter. There are 26 letters, plus the first "t_" option.
8574 */
8575 if (quick_tab[1] == 0)
8576 {
8577 p = options[0].fullname;
8578 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8579 {
8580 if (s[0] != p[0])
8581 {
8582 if (s[0] == 't' && s[1] == '_')
8583 quick_tab[26] = opt_idx;
8584 else
8585 quick_tab[CharOrdLow(s[0])] = opt_idx;
8586 }
8587 p = s;
8588 }
8589 }
8590
8591 /*
8592 * Check for name starting with an illegal character.
8593 */
8594#ifdef EBCDIC
8595 if (!islower(arg[0]))
8596#else
8597 if (arg[0] < 'a' || arg[0] > 'z')
8598#endif
8599 return -1;
8600
8601 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8602 if (is_term_opt)
8603 opt_idx = quick_tab[26];
8604 else
8605 opt_idx = quick_tab[CharOrdLow(arg[0])];
8606 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8607 {
8608 if (STRCMP(arg, s) == 0) /* match full name */
8609 break;
8610 }
8611 if (s == NULL && !is_term_opt)
8612 {
8613 opt_idx = quick_tab[CharOrdLow(arg[0])];
8614 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8615 {
8616 s = options[opt_idx].shortname;
8617 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8618 break;
8619 s = NULL;
8620 }
8621 }
8622 if (s == NULL)
8623 opt_idx = -1;
8624 return opt_idx;
8625}
8626
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008627#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628/*
8629 * Get the value for an option.
8630 *
8631 * Returns:
8632 * Number or Toggle option: 1, *numval gets value.
8633 * String option: 0, *stringval gets allocated string.
8634 * Hidden Number or Toggle option: -1.
8635 * hidden String option: -2.
8636 * unknown option: -3.
8637 */
8638 int
8639get_option_value(name, numval, stringval, opt_flags)
8640 char_u *name;
8641 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008642 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 int opt_flags;
8644{
8645 int opt_idx;
8646 char_u *varp;
8647
8648 opt_idx = findoption(name);
8649 if (opt_idx < 0) /* unknown option */
8650 return -3;
8651
8652 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8653
8654 if (options[opt_idx].flags & P_STRING)
8655 {
8656 if (varp == NULL) /* hidden option */
8657 return -2;
8658 if (stringval != NULL)
8659 {
8660#ifdef FEAT_CRYPT
8661 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008662 if ((char_u **)varp == &curbuf->b_p_key
8663 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 *stringval = vim_strsave((char_u *)"*****");
8665 else
8666#endif
8667 *stringval = vim_strsave(*(char_u **)(varp));
8668 }
8669 return 0;
8670 }
8671
8672 if (varp == NULL) /* hidden option */
8673 return -1;
8674 if (options[opt_idx].flags & P_NUM)
8675 *numval = *(long *)varp;
8676 else
8677 {
8678 /* Special case: 'modified' is b_changed, but we also want to consider
8679 * it set when 'ff' or 'fenc' changed. */
8680 if ((int *)varp == &curbuf->b_changed)
8681 *numval = curbufIsChanged();
8682 else
8683 *numval = *(int *)varp;
8684 }
8685 return 1;
8686}
8687#endif
8688
8689/*
8690 * Set the value of option "name".
8691 * Use "string" for string options, use "number" for other options.
8692 */
8693 void
8694set_option_value(name, number, string, opt_flags)
8695 char_u *name;
8696 long number;
8697 char_u *string;
8698 int opt_flags; /* OPT_LOCAL or 0 (both) */
8699{
8700 int opt_idx;
8701 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008702 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703
8704 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008705 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 EMSG2(_("E355: Unknown option: %s"), name);
8707 else
8708 {
8709 flags = options[opt_idx].flags;
8710#ifdef HAVE_SANDBOX
8711 /* Disallow changing some options in the sandbox */
8712 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008713 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008715 return;
8716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008718 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008719 set_string_option(opt_idx, string, opt_flags);
8720 else
8721 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008722 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 if (varp != NULL) /* hidden option is not changed */
8724 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008725 if (number == 0 && string != NULL)
8726 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008727 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008728
8729 /* Either we are given a string or we are setting option
8730 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008731 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008732 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008733 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008734 {
8735 /* There's another character after zeros or the string
8736 * is empty. In both cases, we are trying to set a
8737 * num option using a string. */
8738 EMSG3(_("E521: Number required: &%s = '%s'"),
8739 name, string);
8740 return; /* do nothing as we hit an error */
8741
8742 }
8743 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008745 (void)set_num_option(opt_idx, varp, number,
8746 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008748 (void)set_bool_option(opt_idx, varp, (int)number,
8749 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 }
8751 }
8752 }
8753}
8754
8755/*
8756 * Get the terminal code for a terminal option.
8757 * Returns NULL when not found.
8758 */
8759 char_u *
8760get_term_code(tname)
8761 char_u *tname;
8762{
8763 int opt_idx;
8764 char_u *varp;
8765
8766 if (tname[0] != 't' || tname[1] != '_' ||
8767 tname[2] == NUL || tname[3] == NUL)
8768 return NULL;
8769 if ((opt_idx = findoption(tname)) >= 0)
8770 {
8771 varp = get_varp(&(options[opt_idx]));
8772 if (varp != NULL)
8773 varp = *(char_u **)(varp);
8774 return varp;
8775 }
8776 return find_termcode(tname + 2);
8777}
8778
8779 char_u *
8780get_highlight_default()
8781{
8782 int i;
8783
8784 i = findoption((char_u *)"hl");
8785 if (i >= 0)
8786 return options[i].def_val[VI_DEFAULT];
8787 return (char_u *)NULL;
8788}
8789
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008790#if defined(FEAT_MBYTE) || defined(PROTO)
8791 char_u *
8792get_encoding_default()
8793{
8794 int i;
8795
8796 i = findoption((char_u *)"enc");
8797 if (i >= 0)
8798 return options[i].def_val[VI_DEFAULT];
8799 return (char_u *)NULL;
8800}
8801#endif
8802
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803/*
8804 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8805 */
8806 static int
8807find_key_option(arg)
8808 char_u *arg;
8809{
8810 int key;
8811 int modifiers;
8812
8813 /*
8814 * Don't use get_special_key_code() for t_xx, we don't want it to call
8815 * add_termcap_entry().
8816 */
8817 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8818 key = TERMCAP2KEY(arg[2], arg[3]);
8819 else
8820 {
8821 --arg; /* put arg at the '<' */
8822 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008823 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 if (modifiers) /* can't handle modifiers here */
8825 key = 0;
8826 }
8827 return key;
8828}
8829
8830/*
8831 * if 'all' == 0: show changed options
8832 * if 'all' == 1: show all normal options
8833 * if 'all' == 2: show all terminal options
8834 */
8835 static void
8836showoptions(all, opt_flags)
8837 int all;
8838 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8839{
8840 struct vimoption *p;
8841 int col;
8842 int isterm;
8843 char_u *varp;
8844 struct vimoption **items;
8845 int item_count;
8846 int run;
8847 int row, rows;
8848 int cols;
8849 int i;
8850 int len;
8851
8852#define INC 20
8853#define GAP 3
8854
8855 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8856 PARAM_COUNT));
8857 if (items == NULL)
8858 return;
8859
8860 /* Highlight title */
8861 if (all == 2)
8862 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8863 else if (opt_flags & OPT_GLOBAL)
8864 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8865 else if (opt_flags & OPT_LOCAL)
8866 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8867 else
8868 MSG_PUTS_TITLE(_("\n--- Options ---"));
8869
8870 /*
8871 * do the loop two times:
8872 * 1. display the short items
8873 * 2. display the long items (only strings and numbers)
8874 */
8875 for (run = 1; run <= 2 && !got_int; ++run)
8876 {
8877 /*
8878 * collect the items in items[]
8879 */
8880 item_count = 0;
8881 for (p = &options[0]; p->fullname != NULL; p++)
8882 {
8883 varp = NULL;
8884 isterm = istermoption(p);
8885 if (opt_flags != 0)
8886 {
8887 if (p->indir != PV_NONE && !isterm)
8888 varp = get_varp_scope(p, opt_flags);
8889 }
8890 else
8891 varp = get_varp(p);
8892 if (varp != NULL
8893 && ((all == 2 && isterm)
8894 || (all == 1 && !isterm)
8895 || (all == 0 && !optval_default(p, varp))))
8896 {
8897 if (p->flags & P_BOOL)
8898 len = 1; /* a toggle option fits always */
8899 else
8900 {
8901 option_value2string(p, opt_flags);
8902 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8903 }
8904 if ((len <= INC - GAP && run == 1) ||
8905 (len > INC - GAP && run == 2))
8906 items[item_count++] = p;
8907 }
8908 }
8909
8910 /*
8911 * display the items
8912 */
8913 if (run == 1)
8914 {
8915 cols = (Columns + GAP - 3) / INC;
8916 if (cols == 0)
8917 cols = 1;
8918 rows = (item_count + cols - 1) / cols;
8919 }
8920 else /* run == 2 */
8921 rows = item_count;
8922 for (row = 0; row < rows && !got_int; ++row)
8923 {
8924 msg_putchar('\n'); /* go to next line */
8925 if (got_int) /* 'q' typed in more */
8926 break;
8927 col = 0;
8928 for (i = row; i < item_count; i += rows)
8929 {
8930 msg_col = col; /* make columns */
8931 showoneopt(items[i], opt_flags);
8932 col += INC;
8933 }
8934 out_flush();
8935 ui_breakcheck();
8936 }
8937 }
8938 vim_free(items);
8939}
8940
8941/*
8942 * Return TRUE if option "p" has its default value.
8943 */
8944 static int
8945optval_default(p, varp)
8946 struct vimoption *p;
8947 char_u *varp;
8948{
8949 int dvi;
8950
8951 if (varp == NULL)
8952 return TRUE; /* hidden option is always at default */
8953 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8954 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008955 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008957 /* the cast to long is required for Manx C, long_i is
8958 * needed for MSVC */
8959 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 /* P_STRING */
8961 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8962}
8963
8964/*
8965 * showoneopt: show the value of one option
8966 * must not be called with a hidden option!
8967 */
8968 static void
8969showoneopt(p, opt_flags)
8970 struct vimoption *p;
8971 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8972{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008973 char_u *varp;
8974 int save_silent = silent_mode;
8975
8976 silent_mode = FALSE;
8977 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978
8979 varp = get_varp_scope(p, opt_flags);
8980
8981 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8982 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8983 ? !curbufIsChanged() : !*(int *)varp))
8984 MSG_PUTS("no");
8985 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8986 MSG_PUTS("--");
8987 else
8988 MSG_PUTS(" ");
8989 MSG_PUTS(p->fullname);
8990 if (!(p->flags & P_BOOL))
8991 {
8992 msg_putchar('=');
8993 /* put value string in NameBuff */
8994 option_value2string(p, opt_flags);
8995 msg_outtrans(NameBuff);
8996 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008997
8998 silent_mode = save_silent;
8999 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000}
9001
9002/*
9003 * Write modified options as ":set" commands to a file.
9004 *
9005 * There are three values for "opt_flags":
9006 * OPT_GLOBAL: Write global option values and fresh values of
9007 * buffer-local options (used for start of a session
9008 * file).
9009 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9010 * curwin (used for a vimrc file).
9011 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9012 * and local values for window-local options of
9013 * curwin. Local values are also written when at the
9014 * default value, because a modeline or autocommand
9015 * may have set them when doing ":edit file" and the
9016 * user has set them back at the default or fresh
9017 * value.
9018 * When "local_only" is TRUE, don't write fresh
9019 * values, only local values (for ":mkview").
9020 * (fresh value = value used for a new buffer or window for a local option).
9021 *
9022 * Return FAIL on error, OK otherwise.
9023 */
9024 int
9025makeset(fd, opt_flags, local_only)
9026 FILE *fd;
9027 int opt_flags;
9028 int local_only;
9029{
9030 struct vimoption *p;
9031 char_u *varp; /* currently used value */
9032 char_u *varp_fresh; /* local value */
9033 char_u *varp_local = NULL; /* fresh value */
9034 char *cmd;
9035 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009036 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037
9038 /*
9039 * The options that don't have a default (terminal name, columns, lines)
9040 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009041 * Do the loop over "options[]" twice: once for options with the
9042 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009044 for (pri = 1; pri >= 0; --pri)
9045 {
9046 for (p = &options[0]; !istermoption(p); p++)
9047 if (!(p->flags & P_NO_MKRC)
9048 && !istermoption(p)
9049 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 {
9051 /* skip global option when only doing locals */
9052 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9053 continue;
9054
9055 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9056 * file, they are always buffer-specific. */
9057 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9058 continue;
9059
9060 /* Global values are only written when not at the default value. */
9061 varp = get_varp_scope(p, opt_flags);
9062 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9063 continue;
9064
9065 round = 2;
9066 if (p->indir != PV_NONE)
9067 {
9068 if (p->var == VAR_WIN)
9069 {
9070 /* skip window-local option when only doing globals */
9071 if (!(opt_flags & OPT_LOCAL))
9072 continue;
9073 /* When fresh value of window-local option is not at the
9074 * default, need to write it too. */
9075 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9076 {
9077 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9078 if (!optval_default(p, varp_fresh))
9079 {
9080 round = 1;
9081 varp_local = varp;
9082 varp = varp_fresh;
9083 }
9084 }
9085 }
9086 }
9087
9088 /* Round 1: fresh value for window-local options.
9089 * Round 2: other values */
9090 for ( ; round <= 2; varp = varp_local, ++round)
9091 {
9092 if (round == 1 || (opt_flags & OPT_GLOBAL))
9093 cmd = "set";
9094 else
9095 cmd = "setlocal";
9096
9097 if (p->flags & P_BOOL)
9098 {
9099 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9100 return FAIL;
9101 }
9102 else if (p->flags & P_NUM)
9103 {
9104 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9105 return FAIL;
9106 }
9107 else /* P_STRING */
9108 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009109#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9110 int do_endif = FALSE;
9111
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 /* Don't set 'syntax' and 'filetype' again if the value is
9113 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009114 if (
9115# if defined(FEAT_SYN_HL)
9116 p->indir == PV_SYN
9117# if defined(FEAT_AUTOCMD)
9118 ||
9119# endif
9120# endif
9121# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009122 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009123# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009124 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 {
9126 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9127 *(char_u **)(varp)) < 0
9128 || put_eol(fd) < 0)
9129 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009130 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9134 (p->flags & P_EXPAND) != 0) == FAIL)
9135 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009136#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9137 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 {
9139 if (put_line(fd, "endif") == FAIL)
9140 return FAIL;
9141 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143 }
9144 }
9145 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 return OK;
9148}
9149
9150#if defined(FEAT_FOLDING) || defined(PROTO)
9151/*
9152 * Generate set commands for the local fold options only. Used when
9153 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9154 */
9155 int
9156makefoldset(fd)
9157 FILE *fd;
9158{
9159 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9160# ifdef FEAT_EVAL
9161 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9162 == FAIL
9163# endif
9164 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9165 == FAIL
9166 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9167 == FAIL
9168 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9169 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9170 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9171 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9172 )
9173 return FAIL;
9174
9175 return OK;
9176}
9177#endif
9178
9179 static int
9180put_setstring(fd, cmd, name, valuep, expand)
9181 FILE *fd;
9182 char *cmd;
9183 char *name;
9184 char_u **valuep;
9185 int expand;
9186{
9187 char_u *s;
9188 char_u buf[MAXPATHL];
9189
9190 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9191 return FAIL;
9192 if (*valuep != NULL)
9193 {
9194 /* Output 'pastetoggle' as key names. For other
9195 * options some characters have to be escaped with
9196 * CTRL-V or backslash */
9197 if (valuep == &p_pt)
9198 {
9199 s = *valuep;
9200 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009201 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 return FAIL;
9203 }
9204 else if (expand)
9205 {
9206 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9207 if (put_escstr(fd, buf, 2) == FAIL)
9208 return FAIL;
9209 }
9210 else if (put_escstr(fd, *valuep, 2) == FAIL)
9211 return FAIL;
9212 }
9213 if (put_eol(fd) < 0)
9214 return FAIL;
9215 return OK;
9216}
9217
9218 static int
9219put_setnum(fd, cmd, name, valuep)
9220 FILE *fd;
9221 char *cmd;
9222 char *name;
9223 long *valuep;
9224{
9225 long wc;
9226
9227 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9228 return FAIL;
9229 if (wc_use_keyname((char_u *)valuep, &wc))
9230 {
9231 /* print 'wildchar' and 'wildcharm' as a key name */
9232 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9233 return FAIL;
9234 }
9235 else if (fprintf(fd, "%ld", *valuep) < 0)
9236 return FAIL;
9237 if (put_eol(fd) < 0)
9238 return FAIL;
9239 return OK;
9240}
9241
9242 static int
9243put_setbool(fd, cmd, name, value)
9244 FILE *fd;
9245 char *cmd;
9246 char *name;
9247 int value;
9248{
Bram Moolenaar893de922007-10-02 18:40:57 +00009249 if (value < 0) /* global/local option using global value */
9250 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9252 || put_eol(fd) < 0)
9253 return FAIL;
9254 return OK;
9255}
9256
9257/*
9258 * Clear all the terminal options.
9259 * If the option has been allocated, free the memory.
9260 * Terminal options are never hidden or indirect.
9261 */
9262 void
9263clear_termoptions()
9264{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009265 /*
9266 * Reset a few things before clearing the old options. This may cause
9267 * outputting a few things that the terminal doesn't understand, but the
9268 * screen will be cleared later, so this is OK.
9269 */
9270#ifdef FEAT_MOUSE_TTY
9271 mch_setmouse(FALSE); /* switch mouse off */
9272#endif
9273#ifdef FEAT_TITLE
9274 mch_restore_title(3); /* restore window titles */
9275#endif
9276#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9277 /* When starting the GUI close the display opened for the clipboard.
9278 * After restoring the title, because that will need the display. */
9279 if (gui.starting)
9280 clear_xterm_clip();
9281#endif
9282#ifdef WIN3264
9283 /*
9284 * Check if this is allowed now.
9285 */
9286 if (can_end_termcap_mode(FALSE) == TRUE)
9287#endif
9288 stoptermcap(); /* stop termcap mode */
9289
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009290 free_termoptions();
9291}
9292
9293 void
9294free_termoptions()
9295{
9296 struct vimoption *p;
9297
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298 for (p = &options[0]; p->fullname != NULL; p++)
9299 if (istermoption(p))
9300 {
9301 if (p->flags & P_ALLOCED)
9302 free_string_option(*(char_u **)(p->var));
9303 if (p->flags & P_DEF_ALLOCED)
9304 free_string_option(p->def_val[VI_DEFAULT]);
9305 *(char_u **)(p->var) = empty_option;
9306 p->def_val[VI_DEFAULT] = empty_option;
9307 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9308 }
9309 clear_termcodes();
9310}
9311
9312/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009313 * Free the string for one term option, if it was allocated.
9314 * Set the string to empty_option and clear allocated flag.
9315 * "var" points to the option value.
9316 */
9317 void
9318free_one_termoption(var)
9319 char_u *var;
9320{
9321 struct vimoption *p;
9322
9323 for (p = &options[0]; p->fullname != NULL; p++)
9324 if (p->var == var)
9325 {
9326 if (p->flags & P_ALLOCED)
9327 free_string_option(*(char_u **)(p->var));
9328 *(char_u **)(p->var) = empty_option;
9329 p->flags &= ~P_ALLOCED;
9330 break;
9331 }
9332}
9333
9334/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 * Set the terminal option defaults to the current value.
9336 * Used after setting the terminal name.
9337 */
9338 void
9339set_term_defaults()
9340{
9341 struct vimoption *p;
9342
9343 for (p = &options[0]; p->fullname != NULL; p++)
9344 {
9345 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9346 {
9347 if (p->flags & P_DEF_ALLOCED)
9348 {
9349 free_string_option(p->def_val[VI_DEFAULT]);
9350 p->flags &= ~P_DEF_ALLOCED;
9351 }
9352 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9353 if (p->flags & P_ALLOCED)
9354 {
9355 p->flags |= P_DEF_ALLOCED;
9356 p->flags &= ~P_ALLOCED; /* don't free the value now */
9357 }
9358 }
9359 }
9360}
9361
9362/*
9363 * return TRUE if 'p' starts with 't_'
9364 */
9365 static int
9366istermoption(p)
9367 struct vimoption *p;
9368{
9369 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9370}
9371
9372/*
9373 * Compute columns for ruler and shown command. 'sc_col' is also used to
9374 * decide what the maximum length of a message on the status line can be.
9375 * If there is a status line for the last window, 'sc_col' is independent
9376 * of 'ru_col'.
9377 */
9378
9379#define COL_RULER 17 /* columns needed by standard ruler */
9380
9381 void
9382comp_col()
9383{
9384#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9385 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9386
9387 sc_col = 0;
9388 ru_col = 0;
9389 if (p_ru)
9390 {
9391#ifdef FEAT_STL_OPT
9392 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9393#else
9394 ru_col = COL_RULER + 1;
9395#endif
9396 /* no last status line, adjust sc_col */
9397 if (!last_has_status)
9398 sc_col = ru_col;
9399 }
9400 if (p_sc)
9401 {
9402 sc_col += SHOWCMD_COLS;
9403 if (!p_ru || last_has_status) /* no need for separating space */
9404 ++sc_col;
9405 }
9406 sc_col = Columns - sc_col;
9407 ru_col = Columns - ru_col;
9408 if (sc_col <= 0) /* screen too narrow, will become a mess */
9409 sc_col = 1;
9410 if (ru_col <= 0)
9411 ru_col = 1;
9412#else
9413 sc_col = Columns;
9414 ru_col = Columns;
9415#endif
9416}
9417
9418/*
9419 * Get pointer to option variable, depending on local or global scope.
9420 */
9421 static char_u *
9422get_varp_scope(p, opt_flags)
9423 struct vimoption *p;
9424 int opt_flags;
9425{
9426 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9427 {
9428 if (p->var == VAR_WIN)
9429 return (char_u *)GLOBAL_WO(get_varp(p));
9430 return p->var;
9431 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009432 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 {
9434 switch ((int)p->indir)
9435 {
9436#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009437 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9438 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9439 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009441 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9442 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9443 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009444 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009445 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009447 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9448 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009449#endif
9450#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009451 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9452 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009454#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9455 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9456#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009457#if defined(FEAT_CRYPT)
9458 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9459#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009460#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009461 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009463 }
9464 return NULL; /* "cannot happen" */
9465 }
9466 return get_varp(p);
9467}
9468
9469/*
9470 * Get pointer to option variable.
9471 */
9472 static char_u *
9473get_varp(p)
9474 struct vimoption *p;
9475{
9476 /* hidden option, always return NULL */
9477 if (p->var == NULL)
9478 return NULL;
9479
9480 switch ((int)p->indir)
9481 {
9482 case PV_NONE: return p->var;
9483
9484 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009485 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009487 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009488 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009489 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009491 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009492 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009493 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9495#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009496 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009498 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009499 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9500#endif
9501#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009502 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009503 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009504 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009505 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9506#endif
9507#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009508 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009509 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009510 case PV_GP: return *curbuf->b_p_gp != NUL
9511 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9512 case PV_MP: return *curbuf->b_p_mp != NUL
9513 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009515#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9516 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9517 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9518#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009519#if defined(FEAT_CRYPT)
9520 case PV_CM: return *curbuf->b_p_cm != NUL
9521 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9522#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009523#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009524 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009525 ? (char_u *)&(curwin->w_p_stl) : p->var;
9526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527
9528#ifdef FEAT_ARABIC
9529 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9530#endif
9531 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009532#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009533 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9534#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009535#ifdef FEAT_SYN_HL
9536 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9537 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009538 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009539#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009540#ifdef FEAT_DIFF
9541 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9542#endif
9543#ifdef FEAT_FOLDING
9544 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9545 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9546 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9547 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9548 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9549 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9550 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9551# ifdef FEAT_EVAL
9552 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9553 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9554# endif
9555 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9556#endif
9557 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009558 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009559#ifdef FEAT_LINEBREAK
9560 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9561#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009562#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9564#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009565#ifdef FEAT_VERTSPLIT
9566 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9569 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9570#endif
9571#ifdef FEAT_RIGHTLEFT
9572 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9573 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9574#endif
9575 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9576 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9577#ifdef FEAT_LINEBREAK
9578 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9579#endif
9580#ifdef FEAT_SCROLLBIND
9581 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9582#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009583#ifdef FEAT_CURSORBIND
9584 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9585#endif
9586#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009587 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
9588 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009589#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590
9591 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9592 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9593#ifdef FEAT_MBYTE
9594 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9595#endif
9596#if defined(FEAT_QUICKFIX)
9597 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9598 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9599#endif
9600 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9601 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9602#ifdef FEAT_CINDENT
9603 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9604 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9605 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9606#endif
9607#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9608 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9609#endif
9610#ifdef FEAT_COMMENTS
9611 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9612#endif
9613#ifdef FEAT_FOLDING
9614 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9615#endif
9616#ifdef FEAT_INS_EXPAND
9617 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9618#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009619#ifdef FEAT_COMPL_FUNC
9620 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009621 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9624 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9625#ifdef FEAT_MBYTE
9626 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9627#endif
9628 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9629#ifdef FEAT_AUTOCMD
9630 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9631#endif
9632 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009633 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9635 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9636 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9637 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9638#ifdef FEAT_FIND_ID
9639# ifdef FEAT_EVAL
9640 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9641# endif
9642#endif
9643#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9644 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9645 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9646#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009647#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009648 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9649#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009650#ifdef FEAT_CRYPT
9651 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9652#endif
9653#ifdef FEAT_LISP
9654 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9655#endif
9656 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9657 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9658 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9659 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9660 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9661#ifdef FEAT_OSFILETYPE
9662 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9663#endif
9664 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009665#ifdef FEAT_TEXTOBJ
9666 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9669#ifdef FEAT_SMARTINDENT
9670 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9671#endif
9672#ifndef SHORT_FNAME
9673 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9674#endif
9675 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9676#ifdef FEAT_SEARCHPATH
9677 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9678#endif
9679 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9680#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009681 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009682 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9683#endif
9684#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009685 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9686 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9687 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688#endif
9689 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9690 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9691 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9692 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009693#ifdef FEAT_PERSISTENT_UNDO
9694 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009696 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9697#ifdef FEAT_KEYMAP
9698 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9699#endif
9700 default: EMSG(_("E356: get_varp ERROR"));
9701 }
9702 /* always return a valid pointer to avoid a crash! */
9703 return (char_u *)&(curbuf->b_p_wm);
9704}
9705
9706/*
9707 * Get the value of 'equalprg', either the buffer-local one or the global one.
9708 */
9709 char_u *
9710get_equalprg()
9711{
9712 if (*curbuf->b_p_ep == NUL)
9713 return p_ep;
9714 return curbuf->b_p_ep;
9715}
9716
9717#if defined(FEAT_WINDOWS) || defined(PROTO)
9718/*
9719 * Copy options from one window to another.
9720 * Used when splitting a window.
9721 */
9722 void
9723win_copy_options(wp_from, wp_to)
9724 win_T *wp_from;
9725 win_T *wp_to;
9726{
9727 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9728 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9729# ifdef FEAT_RIGHTLEFT
9730# ifdef FEAT_FKMAP
9731 /* Is this right? */
9732 wp_to->w_farsi = wp_from->w_farsi;
9733# endif
9734# endif
9735}
9736#endif
9737
9738/*
9739 * Copy the options from one winopt_T to another.
9740 * Doesn't free the old option values in "to", use clear_winopt() for that.
9741 * The 'scroll' option is not copied, because it depends on the window height.
9742 * The 'previewwindow' option is reset, there can be only one preview window.
9743 */
9744 void
9745copy_winopt(from, to)
9746 winopt_T *from;
9747 winopt_T *to;
9748{
9749#ifdef FEAT_ARABIC
9750 to->wo_arab = from->wo_arab;
9751#endif
9752 to->wo_list = from->wo_list;
9753 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009754 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009755#ifdef FEAT_LINEBREAK
9756 to->wo_nuw = from->wo_nuw;
9757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758#ifdef FEAT_RIGHTLEFT
9759 to->wo_rl = from->wo_rl;
9760 to->wo_rlc = vim_strsave(from->wo_rlc);
9761#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009762#ifdef FEAT_STL_OPT
9763 to->wo_stl = vim_strsave(from->wo_stl);
9764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765 to->wo_wrap = from->wo_wrap;
9766#ifdef FEAT_LINEBREAK
9767 to->wo_lbr = from->wo_lbr;
9768#endif
9769#ifdef FEAT_SCROLLBIND
9770 to->wo_scb = from->wo_scb;
9771#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +01009772#ifdef FEAT_CURSORBIND
9773 to->wo_crb = from->wo_crb;
9774#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009775#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009776 to->wo_spell = from->wo_spell;
9777#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009778#ifdef FEAT_SYN_HL
9779 to->wo_cuc = from->wo_cuc;
9780 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009781 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783#ifdef FEAT_DIFF
9784 to->wo_diff = from->wo_diff;
9785#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009786#ifdef FEAT_CONCEAL
9787 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +02009788 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790#ifdef FEAT_FOLDING
9791 to->wo_fdc = from->wo_fdc;
9792 to->wo_fen = from->wo_fen;
9793 to->wo_fdi = vim_strsave(from->wo_fdi);
9794 to->wo_fml = from->wo_fml;
9795 to->wo_fdl = from->wo_fdl;
9796 to->wo_fdm = vim_strsave(from->wo_fdm);
9797 to->wo_fdn = from->wo_fdn;
9798# ifdef FEAT_EVAL
9799 to->wo_fde = vim_strsave(from->wo_fde);
9800 to->wo_fdt = vim_strsave(from->wo_fdt);
9801# endif
9802 to->wo_fmr = vim_strsave(from->wo_fmr);
9803#endif
9804 check_winopt(to); /* don't want NULL pointers */
9805}
9806
9807/*
9808 * Check string options in a window for a NULL value.
9809 */
9810 void
9811check_win_options(win)
9812 win_T *win;
9813{
9814 check_winopt(&win->w_onebuf_opt);
9815 check_winopt(&win->w_allbuf_opt);
9816}
9817
9818/*
9819 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9820 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821 void
9822check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009823 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824{
9825#ifdef FEAT_FOLDING
9826 check_string_option(&wop->wo_fdi);
9827 check_string_option(&wop->wo_fdm);
9828# ifdef FEAT_EVAL
9829 check_string_option(&wop->wo_fde);
9830 check_string_option(&wop->wo_fdt);
9831# endif
9832 check_string_option(&wop->wo_fmr);
9833#endif
9834#ifdef FEAT_RIGHTLEFT
9835 check_string_option(&wop->wo_rlc);
9836#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009837#ifdef FEAT_STL_OPT
9838 check_string_option(&wop->wo_stl);
9839#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009840#ifdef FEAT_SYN_HL
9841 check_string_option(&wop->wo_cc);
9842#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009843#ifdef FEAT_CONCEAL
9844 check_string_option(&wop->wo_cocu);
9845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846}
9847
9848/*
9849 * Free the allocated memory inside a winopt_T.
9850 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851 void
9852clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009853 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854{
9855#ifdef FEAT_FOLDING
9856 clear_string_option(&wop->wo_fdi);
9857 clear_string_option(&wop->wo_fdm);
9858# ifdef FEAT_EVAL
9859 clear_string_option(&wop->wo_fde);
9860 clear_string_option(&wop->wo_fdt);
9861# endif
9862 clear_string_option(&wop->wo_fmr);
9863#endif
9864#ifdef FEAT_RIGHTLEFT
9865 clear_string_option(&wop->wo_rlc);
9866#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009867#ifdef FEAT_STL_OPT
9868 clear_string_option(&wop->wo_stl);
9869#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009870#ifdef FEAT_SYN_HL
9871 clear_string_option(&wop->wo_cc);
9872#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009873#ifdef FEAT_CONCEAL
9874 clear_string_option(&wop->wo_cocu);
9875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876}
9877
9878/*
9879 * Copy global option values to local options for one buffer.
9880 * Used when creating a new buffer and sometimes when entering a buffer.
9881 * flags:
9882 * BCO_ENTER We will enter the buf buffer.
9883 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9884 * appropriate.
9885 * BCO_NOHELP Don't copy the values to a help buffer.
9886 */
9887 void
9888buf_copy_options(buf, flags)
9889 buf_T *buf;
9890 int flags;
9891{
9892 int should_copy = TRUE;
9893 char_u *save_p_isk = NULL; /* init for GCC */
9894 int dont_do_help;
9895 int did_isk = FALSE;
9896
9897 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009898 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 */
9900 if (buf == NULL || !buf_valid(buf))
9901 return;
9902
9903 /*
9904 * Skip this when the option defaults have not been set yet. Happens when
9905 * main() allocates the first buffer.
9906 */
9907 if (p_cpo != NULL)
9908 {
9909 /*
9910 * Always copy when entering and 'cpo' contains 'S'.
9911 * Don't copy when already initialized.
9912 * Don't copy when 'cpo' contains 's' and not entering.
9913 * 'S' BCO_ENTER initialized 's' should_copy
9914 * yes yes X X TRUE
9915 * yes no yes X FALSE
9916 * no X yes X FALSE
9917 * X no no yes FALSE
9918 * X no no no TRUE
9919 * no yes no X TRUE
9920 */
9921 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9922 && (buf->b_p_initialized
9923 || (!(flags & BCO_ENTER)
9924 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9925 should_copy = FALSE;
9926
9927 if (should_copy || (flags & BCO_ALWAYS))
9928 {
9929 /* Don't copy the options specific to a help buffer when
9930 * BCO_NOHELP is given or the options were initialized already
9931 * (jumping back to a help file with CTRL-T or CTRL-O) */
9932 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9933 || buf->b_p_initialized;
9934 if (dont_do_help) /* don't free b_p_isk */
9935 {
9936 save_p_isk = buf->b_p_isk;
9937 buf->b_p_isk = NULL;
9938 }
9939 /*
9940 * Always free the allocated strings.
9941 * If not already initialized, set 'readonly' and copy 'fileformat'.
9942 */
9943 if (!buf->b_p_initialized)
9944 {
9945 free_buf_options(buf, TRUE);
9946 buf->b_p_ro = FALSE; /* don't copy readonly */
9947 buf->b_p_tx = p_tx;
9948#ifdef FEAT_MBYTE
9949 buf->b_p_fenc = vim_strsave(p_fenc);
9950#endif
9951 buf->b_p_ff = vim_strsave(p_ff);
9952#if defined(FEAT_QUICKFIX)
9953 buf->b_p_bh = empty_option;
9954 buf->b_p_bt = empty_option;
9955#endif
9956 }
9957 else
9958 free_buf_options(buf, FALSE);
9959
9960 buf->b_p_ai = p_ai;
9961 buf->b_p_ai_nopaste = p_ai_nopaste;
9962 buf->b_p_sw = p_sw;
9963 buf->b_p_tw = p_tw;
9964 buf->b_p_tw_nopaste = p_tw_nopaste;
9965 buf->b_p_tw_nobin = p_tw_nobin;
9966 buf->b_p_wm = p_wm;
9967 buf->b_p_wm_nopaste = p_wm_nopaste;
9968 buf->b_p_wm_nobin = p_wm_nobin;
9969 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009970#ifdef FEAT_MBYTE
9971 buf->b_p_bomb = p_bomb;
9972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 buf->b_p_et = p_et;
9974 buf->b_p_et_nobin = p_et_nobin;
9975 buf->b_p_ml = p_ml;
9976 buf->b_p_ml_nobin = p_ml_nobin;
9977 buf->b_p_inf = p_inf;
9978 buf->b_p_swf = p_swf;
9979#ifdef FEAT_INS_EXPAND
9980 buf->b_p_cpt = vim_strsave(p_cpt);
9981#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009982#ifdef FEAT_COMPL_FUNC
9983 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009984 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 buf->b_p_sts = p_sts;
9987 buf->b_p_sts_nopaste = p_sts_nopaste;
9988#ifndef SHORT_FNAME
9989 buf->b_p_sn = p_sn;
9990#endif
9991#ifdef FEAT_COMMENTS
9992 buf->b_p_com = vim_strsave(p_com);
9993#endif
9994#ifdef FEAT_FOLDING
9995 buf->b_p_cms = vim_strsave(p_cms);
9996#endif
9997 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009998 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009999 buf->b_p_nf = vim_strsave(p_nf);
10000 buf->b_p_mps = vim_strsave(p_mps);
10001#ifdef FEAT_SMARTINDENT
10002 buf->b_p_si = p_si;
10003#endif
10004 buf->b_p_ci = p_ci;
10005#ifdef FEAT_CINDENT
10006 buf->b_p_cin = p_cin;
10007 buf->b_p_cink = vim_strsave(p_cink);
10008 buf->b_p_cino = vim_strsave(p_cino);
10009#endif
10010#ifdef FEAT_AUTOCMD
10011 /* Don't copy 'filetype', it must be detected */
10012 buf->b_p_ft = empty_option;
10013#endif
10014#ifdef FEAT_OSFILETYPE
10015 buf->b_p_oft = vim_strsave(p_oft);
10016#endif
10017 buf->b_p_pi = p_pi;
10018#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10019 buf->b_p_cinw = vim_strsave(p_cinw);
10020#endif
10021#ifdef FEAT_LISP
10022 buf->b_p_lisp = p_lisp;
10023#endif
10024#ifdef FEAT_SYN_HL
10025 /* Don't copy 'syntax', it must be set */
10026 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010027 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010028#endif
10029#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010030 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010031 (void)compile_cap_prog(&buf->b_s);
10032 buf->b_s.b_p_spf = vim_strsave(p_spf);
10033 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034#endif
10035#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10036 buf->b_p_inde = vim_strsave(p_inde);
10037 buf->b_p_indk = vim_strsave(p_indk);
10038#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010039#if defined(FEAT_EVAL)
10040 buf->b_p_fex = vim_strsave(p_fex);
10041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042#ifdef FEAT_CRYPT
10043 buf->b_p_key = vim_strsave(p_key);
10044#endif
10045#ifdef FEAT_SEARCHPATH
10046 buf->b_p_sua = vim_strsave(p_sua);
10047#endif
10048#ifdef FEAT_KEYMAP
10049 buf->b_p_keymap = vim_strsave(p_keymap);
10050 buf->b_kmap_state |= KEYMAP_INIT;
10051#endif
10052 /* This isn't really an option, but copying the langmap and IME
10053 * state from the current buffer is better than resetting it. */
10054 buf->b_p_iminsert = p_iminsert;
10055 buf->b_p_imsearch = p_imsearch;
10056
10057 /* options that are normally global but also have a local value
10058 * are not copied, start using the global value */
10059 buf->b_p_ar = -1;
10060#ifdef FEAT_QUICKFIX
10061 buf->b_p_gp = empty_option;
10062 buf->b_p_mp = empty_option;
10063 buf->b_p_efm = empty_option;
10064#endif
10065 buf->b_p_ep = empty_option;
10066 buf->b_p_kp = empty_option;
10067 buf->b_p_path = empty_option;
10068 buf->b_p_tags = empty_option;
10069#ifdef FEAT_FIND_ID
10070 buf->b_p_def = empty_option;
10071 buf->b_p_inc = empty_option;
10072# ifdef FEAT_EVAL
10073 buf->b_p_inex = vim_strsave(p_inex);
10074# endif
10075#endif
10076#ifdef FEAT_INS_EXPAND
10077 buf->b_p_dict = empty_option;
10078 buf->b_p_tsr = empty_option;
10079#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010080#ifdef FEAT_TEXTOBJ
10081 buf->b_p_qe = vim_strsave(p_qe);
10082#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010083#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10084 buf->b_p_bexpr = empty_option;
10085#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010086#if defined(FEAT_CRYPT)
10087 buf->b_p_cm = empty_option;
10088#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010089#ifdef FEAT_PERSISTENT_UNDO
10090 buf->b_p_udf = p_udf;
10091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010092
10093 /*
10094 * Don't copy the options set by ex_help(), use the saved values,
10095 * when going from a help buffer to a non-help buffer.
10096 * Don't touch these at all when BCO_NOHELP is used and going from
10097 * or to a help buffer.
10098 */
10099 if (dont_do_help)
10100 buf->b_p_isk = save_p_isk;
10101 else
10102 {
10103 buf->b_p_isk = vim_strsave(p_isk);
10104 did_isk = TRUE;
10105 buf->b_p_ts = p_ts;
10106 buf->b_help = FALSE;
10107#ifdef FEAT_QUICKFIX
10108 if (buf->b_p_bt[0] == 'h')
10109 clear_string_option(&buf->b_p_bt);
10110#endif
10111 buf->b_p_ma = p_ma;
10112 }
10113 }
10114
10115 /*
10116 * When the options should be copied (ignoring BCO_ALWAYS), set the
10117 * flag that indicates that the options have been initialized.
10118 */
10119 if (should_copy)
10120 buf->b_p_initialized = TRUE;
10121 }
10122
10123 check_buf_options(buf); /* make sure we don't have NULLs */
10124 if (did_isk)
10125 (void)buf_init_chartab(buf, FALSE);
10126}
10127
10128/*
10129 * Reset the 'modifiable' option and its default value.
10130 */
10131 void
10132reset_modifiable()
10133{
10134 int opt_idx;
10135
10136 curbuf->b_p_ma = FALSE;
10137 p_ma = FALSE;
10138 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010139 if (opt_idx >= 0)
10140 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141}
10142
10143/*
10144 * Set the global value for 'iminsert' to the local value.
10145 */
10146 void
10147set_iminsert_global()
10148{
10149 p_iminsert = curbuf->b_p_iminsert;
10150}
10151
10152/*
10153 * Set the global value for 'imsearch' to the local value.
10154 */
10155 void
10156set_imsearch_global()
10157{
10158 p_imsearch = curbuf->b_p_imsearch;
10159}
10160
10161#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10162static int expand_option_idx = -1;
10163static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10164static int expand_option_flags = 0;
10165
10166 void
10167set_context_in_set_cmd(xp, arg, opt_flags)
10168 expand_T *xp;
10169 char_u *arg;
10170 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10171{
10172 int nextchar;
10173 long_u flags = 0; /* init for GCC */
10174 int opt_idx = 0; /* init for GCC */
10175 char_u *p;
10176 char_u *s;
10177 int is_term_option = FALSE;
10178 int key;
10179
10180 expand_option_flags = opt_flags;
10181
10182 xp->xp_context = EXPAND_SETTINGS;
10183 if (*arg == NUL)
10184 {
10185 xp->xp_pattern = arg;
10186 return;
10187 }
10188 p = arg + STRLEN(arg) - 1;
10189 if (*p == ' ' && *(p - 1) != '\\')
10190 {
10191 xp->xp_pattern = p + 1;
10192 return;
10193 }
10194 while (p > arg)
10195 {
10196 s = p;
10197 /* count number of backslashes before ' ' or ',' */
10198 if (*p == ' ' || *p == ',')
10199 {
10200 while (s > arg && *(s - 1) == '\\')
10201 --s;
10202 }
10203 /* break at a space with an even number of backslashes */
10204 if (*p == ' ' && ((p - s) & 1) == 0)
10205 {
10206 ++p;
10207 break;
10208 }
10209 --p;
10210 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010211 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 {
10213 xp->xp_context = EXPAND_BOOL_SETTINGS;
10214 p += 2;
10215 }
10216 if (STRNCMP(p, "inv", 3) == 0)
10217 {
10218 xp->xp_context = EXPAND_BOOL_SETTINGS;
10219 p += 3;
10220 }
10221 xp->xp_pattern = arg = p;
10222 if (*arg == '<')
10223 {
10224 while (*p != '>')
10225 if (*p++ == NUL) /* expand terminal option name */
10226 return;
10227 key = get_special_key_code(arg + 1);
10228 if (key == 0) /* unknown name */
10229 {
10230 xp->xp_context = EXPAND_NOTHING;
10231 return;
10232 }
10233 nextchar = *++p;
10234 is_term_option = TRUE;
10235 expand_option_name[2] = KEY2TERMCAP0(key);
10236 expand_option_name[3] = KEY2TERMCAP1(key);
10237 }
10238 else
10239 {
10240 if (p[0] == 't' && p[1] == '_')
10241 {
10242 p += 2;
10243 if (*p != NUL)
10244 ++p;
10245 if (*p == NUL)
10246 return; /* expand option name */
10247 nextchar = *++p;
10248 is_term_option = TRUE;
10249 expand_option_name[2] = p[-2];
10250 expand_option_name[3] = p[-1];
10251 }
10252 else
10253 {
10254 /* Allow * wildcard */
10255 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10256 p++;
10257 if (*p == NUL)
10258 return;
10259 nextchar = *p;
10260 *p = NUL;
10261 opt_idx = findoption(arg);
10262 *p = nextchar;
10263 if (opt_idx == -1 || options[opt_idx].var == NULL)
10264 {
10265 xp->xp_context = EXPAND_NOTHING;
10266 return;
10267 }
10268 flags = options[opt_idx].flags;
10269 if (flags & P_BOOL)
10270 {
10271 xp->xp_context = EXPAND_NOTHING;
10272 return;
10273 }
10274 }
10275 }
10276 /* handle "-=" and "+=" */
10277 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10278 {
10279 ++p;
10280 nextchar = '=';
10281 }
10282 if ((nextchar != '=' && nextchar != ':')
10283 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10284 {
10285 xp->xp_context = EXPAND_UNSUCCESSFUL;
10286 return;
10287 }
10288 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10289 {
10290 xp->xp_context = EXPAND_OLD_SETTING;
10291 if (is_term_option)
10292 expand_option_idx = -1;
10293 else
10294 expand_option_idx = opt_idx;
10295 xp->xp_pattern = p + 1;
10296 return;
10297 }
10298 xp->xp_context = EXPAND_NOTHING;
10299 if (is_term_option || (flags & P_NUM))
10300 return;
10301
10302 xp->xp_pattern = p + 1;
10303
10304 if (flags & P_EXPAND)
10305 {
10306 p = options[opt_idx].var;
10307 if (p == (char_u *)&p_bdir
10308 || p == (char_u *)&p_dir
10309 || p == (char_u *)&p_path
10310 || p == (char_u *)&p_rtp
10311#ifdef FEAT_SEARCHPATH
10312 || p == (char_u *)&p_cdpath
10313#endif
10314#ifdef FEAT_SESSION
10315 || p == (char_u *)&p_vdir
10316#endif
10317 )
10318 {
10319 xp->xp_context = EXPAND_DIRECTORIES;
10320 if (p == (char_u *)&p_path
10321#ifdef FEAT_SEARCHPATH
10322 || p == (char_u *)&p_cdpath
10323#endif
10324 )
10325 xp->xp_backslash = XP_BS_THREE;
10326 else
10327 xp->xp_backslash = XP_BS_ONE;
10328 }
10329 else
10330 {
10331 xp->xp_context = EXPAND_FILES;
10332 /* for 'tags' need three backslashes for a space */
10333 if (p == (char_u *)&p_tags)
10334 xp->xp_backslash = XP_BS_THREE;
10335 else
10336 xp->xp_backslash = XP_BS_ONE;
10337 }
10338 }
10339
10340 /* For an option that is a list of file names, find the start of the
10341 * last file name. */
10342 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10343 {
10344 /* count number of backslashes before ' ' or ',' */
10345 if (*p == ' ' || *p == ',')
10346 {
10347 s = p;
10348 while (s > xp->xp_pattern && *(s - 1) == '\\')
10349 --s;
10350 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10351 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10352 {
10353 xp->xp_pattern = p + 1;
10354 break;
10355 }
10356 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010357
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010358#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010359 /* for 'spellsuggest' start at "file:" */
10360 if (options[opt_idx].var == (char_u *)&p_sps
10361 && STRNCMP(p, "file:", 5) == 0)
10362 {
10363 xp->xp_pattern = p + 5;
10364 break;
10365 }
10366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010367 }
10368
10369 return;
10370}
10371
10372 int
10373ExpandSettings(xp, regmatch, num_file, file)
10374 expand_T *xp;
10375 regmatch_T *regmatch;
10376 int *num_file;
10377 char_u ***file;
10378{
10379 int num_normal = 0; /* Nr of matching non-term-code settings */
10380 int num_term = 0; /* Nr of matching terminal code settings */
10381 int opt_idx;
10382 int match;
10383 int count = 0;
10384 char_u *str;
10385 int loop;
10386 int is_term_opt;
10387 char_u name_buf[MAX_KEY_NAME_LEN];
10388 static char *(names[]) = {"all", "termcap"};
10389 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10390
10391 /* do this loop twice:
10392 * loop == 0: count the number of matching options
10393 * loop == 1: copy the matching options into allocated memory
10394 */
10395 for (loop = 0; loop <= 1; ++loop)
10396 {
10397 regmatch->rm_ic = ic;
10398 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10399 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010400 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10401 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10403 {
10404 if (loop == 0)
10405 num_normal++;
10406 else
10407 (*file)[count++] = vim_strsave((char_u *)names[match]);
10408 }
10409 }
10410 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10411 opt_idx++)
10412 {
10413 if (options[opt_idx].var == NULL)
10414 continue;
10415 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10416 && !(options[opt_idx].flags & P_BOOL))
10417 continue;
10418 is_term_opt = istermoption(&options[opt_idx]);
10419 if (is_term_opt && num_normal > 0)
10420 continue;
10421 match = FALSE;
10422 if (vim_regexec(regmatch, str, (colnr_T)0)
10423 || (options[opt_idx].shortname != NULL
10424 && vim_regexec(regmatch,
10425 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10426 match = TRUE;
10427 else if (is_term_opt)
10428 {
10429 name_buf[0] = '<';
10430 name_buf[1] = 't';
10431 name_buf[2] = '_';
10432 name_buf[3] = str[2];
10433 name_buf[4] = str[3];
10434 name_buf[5] = '>';
10435 name_buf[6] = NUL;
10436 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10437 {
10438 match = TRUE;
10439 str = name_buf;
10440 }
10441 }
10442 if (match)
10443 {
10444 if (loop == 0)
10445 {
10446 if (is_term_opt)
10447 num_term++;
10448 else
10449 num_normal++;
10450 }
10451 else
10452 (*file)[count++] = vim_strsave(str);
10453 }
10454 }
10455 /*
10456 * Check terminal key codes, these are not in the option table
10457 */
10458 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10459 {
10460 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10461 {
10462 if (!isprint(str[0]) || !isprint(str[1]))
10463 continue;
10464
10465 name_buf[0] = 't';
10466 name_buf[1] = '_';
10467 name_buf[2] = str[0];
10468 name_buf[3] = str[1];
10469 name_buf[4] = NUL;
10470
10471 match = FALSE;
10472 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10473 match = TRUE;
10474 else
10475 {
10476 name_buf[0] = '<';
10477 name_buf[1] = 't';
10478 name_buf[2] = '_';
10479 name_buf[3] = str[0];
10480 name_buf[4] = str[1];
10481 name_buf[5] = '>';
10482 name_buf[6] = NUL;
10483
10484 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10485 match = TRUE;
10486 }
10487 if (match)
10488 {
10489 if (loop == 0)
10490 num_term++;
10491 else
10492 (*file)[count++] = vim_strsave(name_buf);
10493 }
10494 }
10495
10496 /*
10497 * Check special key names.
10498 */
10499 regmatch->rm_ic = TRUE; /* ignore case here */
10500 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10501 {
10502 name_buf[0] = '<';
10503 STRCPY(name_buf + 1, str);
10504 STRCAT(name_buf, ">");
10505
10506 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10507 {
10508 if (loop == 0)
10509 num_term++;
10510 else
10511 (*file)[count++] = vim_strsave(name_buf);
10512 }
10513 }
10514 }
10515 if (loop == 0)
10516 {
10517 if (num_normal > 0)
10518 *num_file = num_normal;
10519 else if (num_term > 0)
10520 *num_file = num_term;
10521 else
10522 return OK;
10523 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10524 if (*file == NULL)
10525 {
10526 *file = (char_u **)"";
10527 return FAIL;
10528 }
10529 }
10530 }
10531 return OK;
10532}
10533
10534 int
10535ExpandOldSetting(num_file, file)
10536 int *num_file;
10537 char_u ***file;
10538{
10539 char_u *var = NULL; /* init for GCC */
10540 char_u *buf;
10541
10542 *num_file = 0;
10543 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10544 if (*file == NULL)
10545 return FAIL;
10546
10547 /*
10548 * For a terminal key code expand_option_idx is < 0.
10549 */
10550 if (expand_option_idx < 0)
10551 {
10552 var = find_termcode(expand_option_name + 2);
10553 if (var == NULL)
10554 expand_option_idx = findoption(expand_option_name);
10555 }
10556
10557 if (expand_option_idx >= 0)
10558 {
10559 /* put string of option value in NameBuff */
10560 option_value2string(&options[expand_option_idx], expand_option_flags);
10561 var = NameBuff;
10562 }
10563 else if (var == NULL)
10564 var = (char_u *)"";
10565
10566 /* A backslash is required before some characters. This is the reverse of
10567 * what happens in do_set(). */
10568 buf = vim_strsave_escaped(var, escape_chars);
10569
10570 if (buf == NULL)
10571 {
10572 vim_free(*file);
10573 *file = NULL;
10574 return FAIL;
10575 }
10576
10577#ifdef BACKSLASH_IN_FILENAME
10578 /* For MS-Windows et al. we don't double backslashes at the start and
10579 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010580 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 if (var[0] == '\\' && var[1] == '\\'
10582 && expand_option_idx >= 0
10583 && (options[expand_option_idx].flags & P_EXPAND)
10584 && vim_isfilec(var[2])
10585 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010586 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#endif
10588
10589 *file[0] = buf;
10590 *num_file = 1;
10591 return OK;
10592}
10593#endif
10594
10595/*
10596 * Get the value for the numeric or string option *opp in a nice format into
10597 * NameBuff[]. Must not be called with a hidden option!
10598 */
10599 static void
10600option_value2string(opp, opt_flags)
10601 struct vimoption *opp;
10602 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10603{
10604 char_u *varp;
10605
10606 varp = get_varp_scope(opp, opt_flags);
10607
10608 if (opp->flags & P_NUM)
10609 {
10610 long wc = 0;
10611
10612 if (wc_use_keyname(varp, &wc))
10613 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10614 else if (wc != 0)
10615 STRCPY(NameBuff, transchar((int)wc));
10616 else
10617 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10618 }
10619 else /* P_STRING */
10620 {
10621 varp = *(char_u **)(varp);
10622 if (varp == NULL) /* just in case */
10623 NameBuff[0] = NUL;
10624#ifdef FEAT_CRYPT
10625 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010626 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 STRCPY(NameBuff, "*****");
10628#endif
10629 else if (opp->flags & P_EXPAND)
10630 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10631 /* Translate 'pastetoggle' into special key names */
10632 else if ((char_u **)opp->var == &p_pt)
10633 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10634 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010635 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 }
10637}
10638
10639/*
10640 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10641 * printed as a keyname.
10642 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10643 */
10644 static int
10645wc_use_keyname(varp, wcp)
10646 char_u *varp;
10647 long *wcp;
10648{
10649 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10650 {
10651 *wcp = *(long *)varp;
10652 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10653 return TRUE;
10654 }
10655 return FALSE;
10656}
10657
10658#ifdef FEAT_LANGMAP
10659/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010660 * Any character has an equivalent 'langmap' character. This is used for
10661 * keyboards that have a special language mode that sends characters above
10662 * 128 (although other characters can be translated too). The "to" field is a
10663 * Vim command character. This avoids having to switch the keyboard back to
10664 * ASCII mode when leaving Insert mode.
10665 *
10666 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10667 * commands.
10668 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10669 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10670 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010672# ifdef FEAT_MBYTE
10673/*
10674 * With multi-byte support use growarray for 'langmap' chars >= 256
10675 */
10676typedef struct
10677{
10678 int from;
10679 int to;
10680} langmap_entry_T;
10681
10682static garray_T langmap_mapga;
10683static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010684
10685/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010686 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10687 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010689 static void
10690langmap_set_entry(from, to)
10691 int from;
10692 int to;
10693{
10694 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010695 int a = 0;
10696 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010697
10698 /* Do a binary search for an existing entry. */
10699 while (a != b)
10700 {
10701 int i = (a + b) / 2;
10702 int d = entries[i].from - from;
10703
10704 if (d == 0)
10705 {
10706 entries[i].to = to;
10707 return;
10708 }
10709 if (d < 0)
10710 a = i + 1;
10711 else
10712 b = i;
10713 }
10714
10715 if (ga_grow(&langmap_mapga, 1) != OK)
10716 return; /* out of memory */
10717
10718 /* insert new entry at position "a" */
10719 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10720 mch_memmove(entries + 1, entries,
10721 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10722 ++langmap_mapga.ga_len;
10723 entries[0].from = from;
10724 entries[0].to = to;
10725}
10726
10727/*
10728 * Apply 'langmap' to multi-byte character "c" and return the result.
10729 */
10730 int
10731langmap_adjust_mb(c)
10732 int c;
10733{
10734 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10735 int a = 0;
10736 int b = langmap_mapga.ga_len;
10737
10738 while (a != b)
10739 {
10740 int i = (a + b) / 2;
10741 int d = entries[i].from - c;
10742
10743 if (d == 0)
10744 return entries[i].to; /* found matching entry */
10745 if (d < 0)
10746 a = i + 1;
10747 else
10748 b = i;
10749 }
10750 return c; /* no entry found, return "c" unmodified */
10751}
10752# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753
10754 static void
10755langmap_init()
10756{
10757 int i;
10758
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010759 for (i = 0; i < 256; i++)
10760 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10761# ifdef FEAT_MBYTE
10762 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10763# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764}
10765
10766/*
10767 * Called when langmap option is set; the language map can be
10768 * changed at any time!
10769 */
10770 static void
10771langmap_set()
10772{
10773 char_u *p;
10774 char_u *p2;
10775 int from, to;
10776
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010777#ifdef FEAT_MBYTE
10778 ga_clear(&langmap_mapga); /* clear the previous map first */
10779#endif
10780 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781
10782 for (p = p_langmap; p[0] != NUL; )
10783 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010784 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10785 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786 {
10787 if (p2[0] == '\\' && p2[1] != NUL)
10788 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 }
10790 if (p2[0] == ';')
10791 ++p2; /* abcd;ABCD form, p2 points to A */
10792 else
10793 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10794 while (p[0])
10795 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010796 if (p[0] == ',')
10797 {
10798 ++p;
10799 break;
10800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 if (p[0] == '\\' && p[1] != NUL)
10802 ++p;
10803#ifdef FEAT_MBYTE
10804 from = (*mb_ptr2char)(p);
10805#else
10806 from = p[0];
10807#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010808 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809 if (p2 == NULL)
10810 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010811 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010812 if (p[0] != ',')
10813 {
10814 if (p[0] == '\\')
10815 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010817 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010819 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010821 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 }
10823 else
10824 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010825 if (p2[0] != ',')
10826 {
10827 if (p2[0] == '\\')
10828 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010830 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010832 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 }
10836 if (to == NUL)
10837 {
10838 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10839 transchar(from));
10840 return;
10841 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010842
10843#ifdef FEAT_MBYTE
10844 if (from >= 256)
10845 langmap_set_entry(from, to);
10846 else
10847#endif
10848 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849
10850 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010851 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010852 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010854 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855 if (*p == ';')
10856 {
10857 p = p2;
10858 if (p[0] != NUL)
10859 {
10860 if (p[0] != ',')
10861 {
10862 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10863 return;
10864 }
10865 ++p;
10866 }
10867 break;
10868 }
10869 }
10870 }
10871 }
10872}
10873#endif
10874
10875/*
10876 * Return TRUE if format option 'x' is in effect.
10877 * Take care of no formatting when 'paste' is set.
10878 */
10879 int
10880has_format_option(x)
10881 int x;
10882{
10883 if (p_paste)
10884 return FALSE;
10885 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10886}
10887
10888/*
10889 * Return TRUE if "x" is present in 'shortmess' option, or
10890 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10891 */
10892 int
10893shortmess(x)
10894 int x;
10895{
10896 return ( vim_strchr(p_shm, x) != NULL
10897 || (vim_strchr(p_shm, 'a') != NULL
10898 && vim_strchr((char_u *)SHM_A, x) != NULL));
10899}
10900
10901/*
10902 * paste_option_changed() - Called after p_paste was set or reset.
10903 */
10904 static void
10905paste_option_changed()
10906{
10907 static int old_p_paste = FALSE;
10908 static int save_sm = 0;
10909#ifdef FEAT_CMDL_INFO
10910 static int save_ru = 0;
10911#endif
10912#ifdef FEAT_RIGHTLEFT
10913 static int save_ri = 0;
10914 static int save_hkmap = 0;
10915#endif
10916 buf_T *buf;
10917
10918 if (p_paste)
10919 {
10920 /*
10921 * Paste switched from off to on.
10922 * Save the current values, so they can be restored later.
10923 */
10924 if (!old_p_paste)
10925 {
10926 /* save options for each buffer */
10927 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10928 {
10929 buf->b_p_tw_nopaste = buf->b_p_tw;
10930 buf->b_p_wm_nopaste = buf->b_p_wm;
10931 buf->b_p_sts_nopaste = buf->b_p_sts;
10932 buf->b_p_ai_nopaste = buf->b_p_ai;
10933 }
10934
10935 /* save global options */
10936 save_sm = p_sm;
10937#ifdef FEAT_CMDL_INFO
10938 save_ru = p_ru;
10939#endif
10940#ifdef FEAT_RIGHTLEFT
10941 save_ri = p_ri;
10942 save_hkmap = p_hkmap;
10943#endif
10944 /* save global values for local buffer options */
10945 p_tw_nopaste = p_tw;
10946 p_wm_nopaste = p_wm;
10947 p_sts_nopaste = p_sts;
10948 p_ai_nopaste = p_ai;
10949 }
10950
10951 /*
10952 * Always set the option values, also when 'paste' is set when it is
10953 * already on.
10954 */
10955 /* set options for each buffer */
10956 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10957 {
10958 buf->b_p_tw = 0; /* textwidth is 0 */
10959 buf->b_p_wm = 0; /* wrapmargin is 0 */
10960 buf->b_p_sts = 0; /* softtabstop is 0 */
10961 buf->b_p_ai = 0; /* no auto-indent */
10962 }
10963
10964 /* set global options */
10965 p_sm = 0; /* no showmatch */
10966#ifdef FEAT_CMDL_INFO
10967# ifdef FEAT_WINDOWS
10968 if (p_ru)
10969 status_redraw_all(); /* redraw to remove the ruler */
10970# endif
10971 p_ru = 0; /* no ruler */
10972#endif
10973#ifdef FEAT_RIGHTLEFT
10974 p_ri = 0; /* no reverse insert */
10975 p_hkmap = 0; /* no Hebrew keyboard */
10976#endif
10977 /* set global values for local buffer options */
10978 p_tw = 0;
10979 p_wm = 0;
10980 p_sts = 0;
10981 p_ai = 0;
10982 }
10983
10984 /*
10985 * Paste switched from on to off: Restore saved values.
10986 */
10987 else if (old_p_paste)
10988 {
10989 /* restore options for each buffer */
10990 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10991 {
10992 buf->b_p_tw = buf->b_p_tw_nopaste;
10993 buf->b_p_wm = buf->b_p_wm_nopaste;
10994 buf->b_p_sts = buf->b_p_sts_nopaste;
10995 buf->b_p_ai = buf->b_p_ai_nopaste;
10996 }
10997
10998 /* restore global options */
10999 p_sm = save_sm;
11000#ifdef FEAT_CMDL_INFO
11001# ifdef FEAT_WINDOWS
11002 if (p_ru != save_ru)
11003 status_redraw_all(); /* redraw to draw the ruler */
11004# endif
11005 p_ru = save_ru;
11006#endif
11007#ifdef FEAT_RIGHTLEFT
11008 p_ri = save_ri;
11009 p_hkmap = save_hkmap;
11010#endif
11011 /* set global values for local buffer options */
11012 p_tw = p_tw_nopaste;
11013 p_wm = p_wm_nopaste;
11014 p_sts = p_sts_nopaste;
11015 p_ai = p_ai_nopaste;
11016 }
11017
11018 old_p_paste = p_paste;
11019}
11020
11021/*
11022 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11023 *
11024 * Reset 'compatible' and set the values for options that didn't get set yet
11025 * to the Vim defaults.
11026 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011027 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011028 */
11029 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011030vimrc_found(fname, envname)
11031 char_u *fname;
11032 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011033{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011034 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011035 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011036 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011037
11038 if (!option_was_set((char_u *)"cp"))
11039 {
11040 p_cp = FALSE;
11041 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11042 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11043 set_option_default(opt_idx, OPT_FREE, FALSE);
11044 didset_options();
11045 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011046
11047 if (fname != NULL)
11048 {
11049 p = vim_getenv(envname, &dofree);
11050 if (p == NULL)
11051 {
11052 /* Set $MYVIMRC to the first vimrc file found. */
11053 p = FullName_save(fname, FALSE);
11054 if (p != NULL)
11055 {
11056 vim_setenv(envname, p);
11057 vim_free(p);
11058 }
11059 }
11060 else if (dofree)
11061 vim_free(p);
11062 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063}
11064
11065/*
11066 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11067 */
11068 void
11069change_compatible(on)
11070 int on;
11071{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011072 int opt_idx;
11073
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 if (p_cp != on)
11075 {
11076 p_cp = on;
11077 compatible_set();
11078 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011079 opt_idx = findoption((char_u *)"cp");
11080 if (opt_idx >= 0)
11081 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082}
11083
11084/*
11085 * Return TRUE when option "name" has been set.
11086 */
11087 int
11088option_was_set(name)
11089 char_u *name;
11090{
11091 int idx;
11092
11093 idx = findoption(name);
11094 if (idx < 0) /* unknown option */
11095 return FALSE;
11096 if (options[idx].flags & P_WAS_SET)
11097 return TRUE;
11098 return FALSE;
11099}
11100
11101/*
11102 * compatible_set() - Called when 'compatible' has been set or unset.
11103 *
11104 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11105 * flag) to a Vi compatible value.
11106 * When 'compatible' is unset: Set all options that have a different default
11107 * for Vim (without the P_VI_DEF flag) to that default.
11108 */
11109 static void
11110compatible_set()
11111{
11112 int opt_idx;
11113
11114 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11115 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11116 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11117 set_option_default(opt_idx, OPT_FREE, p_cp);
11118 didset_options();
11119}
11120
11121#ifdef FEAT_LINEBREAK
11122
11123# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11124 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011125 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126# endif
11127
11128/*
11129 * fill_breakat_flags() -- called when 'breakat' changes value.
11130 */
11131 static void
11132fill_breakat_flags()
11133{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011134 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135 int i;
11136
11137 for (i = 0; i < 256; i++)
11138 breakat_flags[i] = FALSE;
11139
11140 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011141 for (p = p_breakat; *p; p++)
11142 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011143}
11144
11145# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011146 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147# endif
11148
11149#endif
11150
11151/*
11152 * Check an option that can be a range of string values.
11153 *
11154 * Return OK for correct value, FAIL otherwise.
11155 * Empty is always OK.
11156 */
11157 static int
11158check_opt_strings(val, values, list)
11159 char_u *val;
11160 char **values;
11161 int list; /* when TRUE: accept a list of values */
11162{
11163 return opt_strings_flags(val, values, NULL, list);
11164}
11165
11166/*
11167 * Handle an option that can be a range of string values.
11168 * Set a flag in "*flagp" for each string present.
11169 *
11170 * Return OK for correct value, FAIL otherwise.
11171 * Empty is always OK.
11172 */
11173 static int
11174opt_strings_flags(val, values, flagp, list)
11175 char_u *val; /* new value */
11176 char **values; /* array of valid string values */
11177 unsigned *flagp;
11178 int list; /* when TRUE: accept a list of values */
11179{
11180 int i;
11181 int len;
11182 unsigned new_flags = 0;
11183
11184 while (*val)
11185 {
11186 for (i = 0; ; ++i)
11187 {
11188 if (values[i] == NULL) /* val not found in values[] */
11189 return FAIL;
11190
11191 len = (int)STRLEN(values[i]);
11192 if (STRNCMP(values[i], val, len) == 0
11193 && ((list && val[len] == ',') || val[len] == NUL))
11194 {
11195 val += len + (val[len] == ',');
11196 new_flags |= (1 << i);
11197 break; /* check next item in val list */
11198 }
11199 }
11200 }
11201 if (flagp != NULL)
11202 *flagp = new_flags;
11203
11204 return OK;
11205}
11206
11207/*
11208 * Read the 'wildmode' option, fill wim_flags[].
11209 */
11210 static int
11211check_opt_wim()
11212{
11213 char_u new_wim_flags[4];
11214 char_u *p;
11215 int i;
11216 int idx = 0;
11217
11218 for (i = 0; i < 4; ++i)
11219 new_wim_flags[i] = 0;
11220
11221 for (p = p_wim; *p; ++p)
11222 {
11223 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11224 ;
11225 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11226 return FAIL;
11227 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11228 new_wim_flags[idx] |= WIM_LONGEST;
11229 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11230 new_wim_flags[idx] |= WIM_FULL;
11231 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11232 new_wim_flags[idx] |= WIM_LIST;
11233 else
11234 return FAIL;
11235 p += i;
11236 if (*p == NUL)
11237 break;
11238 if (*p == ',')
11239 {
11240 if (idx == 3)
11241 return FAIL;
11242 ++idx;
11243 }
11244 }
11245
11246 /* fill remaining entries with last flag */
11247 while (idx < 3)
11248 {
11249 new_wim_flags[idx + 1] = new_wim_flags[idx];
11250 ++idx;
11251 }
11252
11253 /* only when there are no errors, wim_flags[] is changed */
11254 for (i = 0; i < 4; ++i)
11255 wim_flags[i] = new_wim_flags[i];
11256 return OK;
11257}
11258
11259/*
11260 * Check if backspacing over something is allowed.
11261 */
11262 int
11263can_bs(what)
11264 int what; /* BS_INDENT, BS_EOL or BS_START */
11265{
11266 switch (*p_bs)
11267 {
11268 case '2': return TRUE;
11269 case '1': return (what != BS_START);
11270 case '0': return FALSE;
11271 }
11272 return vim_strchr(p_bs, what) != NULL;
11273}
11274
11275/*
11276 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11277 * the file must be considered changed when the value is different.
11278 */
11279 void
11280save_file_ff(buf)
11281 buf_T *buf;
11282{
11283 buf->b_start_ffc = *buf->b_p_ff;
11284 buf->b_start_eol = buf->b_p_eol;
11285#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011286 buf->b_start_bomb = buf->b_p_bomb;
11287
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 /* Only use free/alloc when necessary, they take time. */
11289 if (buf->b_start_fenc == NULL
11290 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11291 {
11292 vim_free(buf->b_start_fenc);
11293 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11294 }
11295#endif
11296}
11297
11298/*
11299 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11300 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011301 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11302 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011303 * When "ignore_empty" is true don't consider a new, empty buffer to be
11304 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011305 */
11306 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011307file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011309 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011311 /* In a buffer that was never loaded the options are not valid. */
11312 if (buf->b_flags & BF_NEVERLOADED)
11313 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011314 if (ignore_empty
11315 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 && buf->b_ml.ml_line_count == 1
11317 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11318 return FALSE;
11319 if (buf->b_start_ffc != *buf->b_p_ff)
11320 return TRUE;
11321 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11322 return TRUE;
11323#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011324 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11325 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326 if (buf->b_start_fenc == NULL)
11327 return (*buf->b_p_fenc != NUL);
11328 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11329#else
11330 return FALSE;
11331#endif
11332}
11333
11334/*
11335 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11336 */
11337 int
11338check_ff_value(p)
11339 char_u *p;
11340{
11341 return check_opt_strings(p, p_ff_values, FALSE);
11342}