blob: 6c0618ab37490528eeaac341d46af4cd4870c739 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +020080#define PV_CM OPT_BUF(BV_CM)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
143#ifdef FEAT_OSFILETYPE
144# define PV_OFT OPT_BUF(BV_OFT)
145#endif
146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
180#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000181
182/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183 * Definition of the PV_ values for window-local options.
184 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186#define PV_LIST OPT_WIN(WV_LIST)
187#ifdef FEAT_ARABIC
188# define PV_ARAB OPT_WIN(WV_ARAB)
189#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000190#ifdef FEAT_DIFF
191# define PV_DIFF OPT_WIN(WV_DIFF)
192#endif
193#ifdef FEAT_FOLDING
194# define PV_FDC OPT_WIN(WV_FDC)
195# define PV_FEN OPT_WIN(WV_FEN)
196# define PV_FDI OPT_WIN(WV_FDI)
197# define PV_FDL OPT_WIN(WV_FDL)
198# define PV_FDM OPT_WIN(WV_FDM)
199# define PV_FML OPT_WIN(WV_FML)
200# define PV_FDN OPT_WIN(WV_FDN)
201# ifdef FEAT_EVAL
202# define PV_FDE OPT_WIN(WV_FDE)
203# define PV_FDT OPT_WIN(WV_FDT)
204# endif
205# define PV_FMR OPT_WIN(WV_FMR)
206#endif
207#ifdef FEAT_LINEBREAK
208# define PV_LBR OPT_WIN(WV_LBR)
209#endif
210#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200211#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000212#ifdef FEAT_LINEBREAK
213# define PV_NUW OPT_WIN(WV_NUW)
214#endif
215#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216# define PV_PVW OPT_WIN(WV_PVW)
217#endif
218#ifdef FEAT_RIGHTLEFT
219# define PV_RL OPT_WIN(WV_RL)
220# define PV_RLC OPT_WIN(WV_RLC)
221#endif
222#ifdef FEAT_SCROLLBIND
223# define PV_SCBIND OPT_WIN(WV_SCBIND)
224#endif
225#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000226#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_SPELL OPT_WIN(WV_SPELL)
228#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SYN_HL
230# define PV_CUC OPT_WIN(WV_CUC)
231# define PV_CUL OPT_WIN(WV_CUL)
232#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233#ifdef FEAT_STL_OPT
234# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
235#endif
236#ifdef FEAT_WINDOWS
237# define PV_WFH OPT_WIN(WV_WFH)
238#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000239#ifdef FEAT_VERTSPLIT
240# define PV_WFW OPT_WIN(WV_WFW)
241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000243
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244
245/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246typedef enum
247{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000248 PV_NONE = 0,
249 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250} idopt_T;
251
252/*
253 * Options local to a window have a value local to a buffer and global to all
254 * buffers. Indicate this by setting "var" to VAR_WIN.
255 */
256#define VAR_WIN ((char_u *)-1)
257
258/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000259 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260 * Only to be used in option.c!
261 */
262static int p_ai;
263static int p_bin;
264#ifdef FEAT_MBYTE
265static int p_bomb;
266#endif
267#if defined(FEAT_QUICKFIX)
268static char_u *p_bh;
269static char_u *p_bt;
270#endif
271static int p_bl;
272static int p_ci;
273#ifdef FEAT_CINDENT
274static int p_cin;
275static char_u *p_cink;
276static char_u *p_cino;
277#endif
278#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
279static char_u *p_cinw;
280#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200281#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200282static long p_cm;
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284#ifdef FEAT_COMMENTS
285static char_u *p_com;
286#endif
287#ifdef FEAT_FOLDING
288static char_u *p_cms;
289#endif
290#ifdef FEAT_INS_EXPAND
291static char_u *p_cpt;
292#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000293#ifdef FEAT_COMPL_FUNC
294static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000295static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000297static int p_eol;
298static int p_et;
299#ifdef FEAT_MBYTE
300static char_u *p_fenc;
301#endif
302static char_u *p_ff;
303static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000304static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305#ifdef FEAT_AUTOCMD
306static char_u *p_ft;
307#endif
308static long p_iminsert;
309static long p_imsearch;
310#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
311static char_u *p_inex;
312#endif
313#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
314static char_u *p_inde;
315static char_u *p_indk;
316#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000317#if defined(FEAT_EVAL)
318static char_u *p_fex;
319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320static int p_inf;
321static char_u *p_isk;
322#ifdef FEAT_CRYPT
323static char_u *p_key;
324#endif
325#ifdef FEAT_LISP
326static int p_lisp;
327#endif
328static int p_ml;
329static int p_ma;
330static int p_mod;
331static char_u *p_mps;
332static char_u *p_nf;
333#ifdef FEAT_OSFILETYPE
334static char_u *p_oft;
335#endif
336static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000337#ifdef FEAT_TEXTOBJ
338static char_u *p_qe;
339#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000340static int p_ro;
341#ifdef FEAT_SMARTINDENT
342static int p_si;
343#endif
344#ifndef SHORT_FNAME
345static int p_sn;
346#endif
347static long p_sts;
348#if defined(FEAT_SEARCHPATH)
349static char_u *p_sua;
350#endif
351static long p_sw;
352static int p_swf;
353#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000354static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000356#endif
357#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000358static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000359static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000360static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361#endif
362static long p_ts;
363static long p_tw;
364static int p_tx;
365static long p_wm;
366#ifdef FEAT_KEYMAP
367static char_u *p_keymap;
368#endif
369
370/* Saved values for when 'bin' is set. */
371static int p_et_nobin;
372static int p_ml_nobin;
373static long p_tw_nobin;
374static long p_wm_nobin;
375
376/* Saved values for when 'paste' is set */
377static long p_tw_nopaste;
378static long p_wm_nopaste;
379static long p_sts_nopaste;
380static int p_ai_nopaste;
381
382struct vimoption
383{
384 char *fullname; /* full option name */
385 char *shortname; /* permissible abbreviation */
386 long_u flags; /* see below */
387 char_u *var; /* global option: pointer to variable;
388 * window-local option: VAR_WIN;
389 * buffer-local option: global value */
390 idopt_T indir; /* global option: PV_NONE;
391 * local option: indirect option index */
392 char_u *def_val[2]; /* default values for variable (vi and vim) */
393#ifdef FEAT_EVAL
394 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000395# define SCRIPTID_INIT , 0
396#else
397# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398#endif
399};
400
401#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
402#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
403
404/*
405 * Flags
406 */
407#define P_BOOL 0x01 /* the option is boolean */
408#define P_NUM 0x02 /* the option is numeric */
409#define P_STRING 0x04 /* the option is a string */
410#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000411 must use free_string_option() when
412 assigning new value. Not set if default is
413 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
415 never be used for local or hidden options! */
416#define P_NODEFAULT 0x40 /* don't set to default value */
417#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
418 use vim_free() when assigning new value */
419#define P_WAS_SET 0x100 /* option has been set/reset */
420#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
421#define P_VI_DEF 0x400 /* Use Vi default for Vim */
422#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
423
424 /* when option changed, what to display: */
425#define P_RSTAT 0x1000 /* redraw status lines */
426#define P_RWIN 0x2000 /* redraw current window */
427#define P_RBUF 0x4000 /* redraw current buffer */
428#define P_RALL 0x6000 /* redraw all windows */
429#define P_RCLR 0x7000 /* clear and redraw all */
430
431#define P_COMMA 0x8000 /* comma separated list */
432#define P_NODUP 0x10000L/* don't allow duplicate strings */
433#define P_FLAGLIST 0x20000L/* list of single-char flags */
434
435#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
436#define P_GETTEXT 0x80000L/* expand default value with _() */
437#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000438#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000439#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000440#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
441 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000442
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000443#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
444
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000445/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
446 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000447#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000448# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000449#else
450# define ISP_LATIN1 (char_u *)"@,161-255"
451#endif
452
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000453/* The 16 bit MS-DOS version is low on space, make the string as short as
454 * possible when compiling with few features. */
455#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
456 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
457 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
458# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine"
459#else
460# 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"
461#endif
462
Bram Moolenaar071d4272004-06-13 20:20:40 +0000463/*
464 * options[] is initialized here.
465 * The order of the options MUST be alphabetic for ":set all" and findoption().
466 * All option names MUST start with a lowercase letter (for findoption()).
467 * Exception: "t_" options are at the end.
468 * The options with a NULL variable are 'hidden': a set command for them is
469 * ignored and they are not printed.
470 */
471static struct vimoption
472#ifdef FEAT_GUI_W16
473 _far
474#endif
475 options[] =
476{
477 {"aleph", "al", P_NUM|P_VI_DEF,
478#ifdef FEAT_RIGHTLEFT
479 (char_u *)&p_aleph, PV_NONE,
480#else
481 (char_u *)NULL, PV_NONE,
482#endif
483 {
484#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
485 (char_u *)128L,
486#else
487 (char_u *)224L,
488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
491#if defined(FEAT_GUI) && defined(MACOS_X)
492 (char_u *)&p_antialias, PV_NONE,
493 {(char_u *)FALSE, (char_u *)FALSE}
494#else
495 (char_u *)NULL, PV_NONE,
496 {(char_u *)FALSE, (char_u *)FALSE}
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
500#ifdef FEAT_ARABIC
501 (char_u *)VAR_WIN, PV_ARAB,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
507#ifdef FEAT_ARABIC
508 (char_u *)&p_arshape, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
514#ifdef FEAT_RIGHTLEFT
515 (char_u *)&p_ari, PV_NONE,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
521#ifdef FEAT_FKMAP
522 (char_u *)&p_altkeymap, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
528#if defined(FEAT_MBYTE)
529 (char_u *)&p_ambw, PV_NONE,
530 {(char_u *)"single", (char_u *)0L}
531#else
532 (char_u *)NULL, PV_NONE,
533 {(char_u *)0L, (char_u *)0L}
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000536#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 {"autochdir", "acd", P_BOOL|P_VI_DEF,
538 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540#endif
541 {"autoindent", "ai", P_BOOL|P_VI_DEF,
542 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000543 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 {"autoprint", "ap", P_BOOL|P_VI_DEF,
545 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000548 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autowrite", "aw", P_BOOL|P_VI_DEF,
551 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autowriteall","awa", P_BOOL|P_VI_DEF,
554 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
557 (char_u *)&p_bg, PV_NONE,
558 {
559#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
560 (char_u *)"dark",
561#else
562 (char_u *)"light",
563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
566 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
569 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
572 (char_u *)&p_bkc, PV_NONE,
573#ifdef UNIX
574 {(char_u *)"yes", (char_u *)"auto"}
575#else
576 {(char_u *)"auto", (char_u *)"auto"}
577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
580 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000582 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 (char_u *)&p_bex, PV_NONE,
584 {
585#ifdef VMS
586 (char_u *)"_",
587#else
588 (char_u *)"~",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
592#ifdef FEAT_WILDIGN
593 (char_u *)&p_bsk, PV_NONE,
594 {(char_u *)"", (char_u *)0L}
595#else
596 (char_u *)NULL, PV_NONE,
597 {(char_u *)0L, (char_u *)0L}
598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000599 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600#ifdef FEAT_BEVAL
601 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
602 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
605 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000606 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000607# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000608 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000609 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000610 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000611# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612#endif
613 {"beautify", "bf", P_BOOL|P_VI_DEF,
614 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
617 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
620#ifdef MSDOS
621 (char_u *)&p_biosk, PV_NONE,
622#else
623 (char_u *)NULL, PV_NONE,
624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
627#ifdef FEAT_MBYTE
628 (char_u *)&p_bomb, PV_BOMB,
629#else
630 (char_u *)NULL, PV_NONE,
631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
634#ifdef FEAT_LINEBREAK
635 (char_u *)&p_breakat, PV_NONE,
636 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
637#else
638 (char_u *)NULL, PV_NONE,
639 {(char_u *)0L, (char_u *)0L}
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
643#ifdef FEAT_BROWSE
644 (char_u *)&p_bsdir, PV_NONE,
645 {(char_u *)"last", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
652#if defined(FEAT_QUICKFIX)
653 (char_u *)&p_bh, PV_BH,
654 {(char_u *)"", (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000659 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
661 (char_u *)&p_bl, PV_BL,
662 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
665#if defined(FEAT_QUICKFIX)
666 (char_u *)&p_bt, PV_BT,
667 {(char_u *)"", (char_u *)0L}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)0L, (char_u *)0L}
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000674#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)&p_cmp, PV_NONE,
676 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
683#ifdef FEAT_SEARCHPATH
684 (char_u *)&p_cdpath, PV_NONE,
685 {(char_u *)",,", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"cedit", NULL, P_STRING,
692#ifdef FEAT_CMDWIN
693 (char_u *)&p_cedit, PV_NONE,
694 {(char_u *)"", (char_u *)CTRL_F_STR}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000700 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
701#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
702 (char_u *)&p_ccv, PV_NONE,
703 {(char_u *)"", (char_u *)0L}
704#else
705 (char_u *)NULL, PV_NONE,
706 {(char_u *)0L, (char_u *)0L}
707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
710#ifdef FEAT_CINDENT
711 (char_u *)&p_cin, PV_CIN,
712#else
713 (char_u *)NULL, PV_NONE,
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
717#ifdef FEAT_CINDENT
718 (char_u *)&p_cink, PV_CINK,
719 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
720#else
721 (char_u *)NULL, PV_NONE,
722 {(char_u *)0L, (char_u *)0L}
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_CINDENT
727 (char_u *)&p_cino, PV_CINO,
728#else
729 (char_u *)NULL, PV_NONE,
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
733#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
734 (char_u *)&p_cinw, PV_CINW,
735 {(char_u *)"if,else,while,do,for,switch",
736 (char_u *)0L}
737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_CLIPBOARD
744 (char_u *)&p_cb, PV_NONE,
745# ifdef FEAT_XCLIPBOARD
746 {(char_u *)"autoselect,exclude:cons\\|linux",
747 (char_u *)0L}
748# else
749 {(char_u *)"", (char_u *)0L}
750# endif
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)"", (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
757 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
760#ifdef FEAT_CMDWIN
761 (char_u *)&p_cwh, PV_NONE,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
767 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
770#ifdef FEAT_COMMENTS
771 (char_u *)&p_com, PV_COM,
772 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
773 (char_u *)0L}
774#else
775 (char_u *)NULL, PV_NONE,
776 {(char_u *)0L, (char_u *)0L}
777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000778 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
780#ifdef FEAT_FOLDING
781 (char_u *)&p_cms, PV_CMS,
782 {(char_u *)"/*%s*/", (char_u *)0L}
783#else
784 (char_u *)NULL, PV_NONE,
785 {(char_u *)0L, (char_u *)0L}
786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000787 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000788 /* P_PRI_MKRC isn't needed here, optval_default()
789 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"compatible", "cp", P_BOOL|P_RALL,
791 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000792 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
794#ifdef FEAT_INS_EXPAND
795 (char_u *)&p_cpt, PV_CPT,
796 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000802 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
803#ifdef FEAT_COMPL_FUNC
804 (char_u *)&p_cfu, PV_CFU,
805 {(char_u *)"", (char_u *)0L}
806#else
807 (char_u *)NULL, PV_NONE,
808 {(char_u *)0L, (char_u *)0L}
809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000810 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000811 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
812#ifdef FEAT_INS_EXPAND
813 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000814 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000815#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 Moolenaar071d4272004-06-13 20:20:40 +0000820 {"confirm", "cf", P_BOOL|P_VI_DEF,
821#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
822 (char_u *)&p_confirm, PV_NONE,
823#else
824 (char_u *)NULL, PV_NONE,
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827 {"conskey", "consk",P_BOOL|P_VI_DEF,
828#ifdef MSDOS
829 (char_u *)&p_consk, PV_NONE,
830#else
831 (char_u *)NULL, PV_NONE,
832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
835 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
838 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
840 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200841 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200842#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200843 (char_u *)&p_cm, PV_CM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200844#else
845 (char_u *)NULL, PV_NONE,
846#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200847 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
849#ifdef FEAT_CSCOPE
850 (char_u *)&p_cspc, PV_NONE,
851#else
852 (char_u *)NULL, PV_NONE,
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000855 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
856#ifdef FEAT_CSCOPE
857 (char_u *)&p_csprg, PV_NONE,
858 {(char_u *)"cscope", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
865#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
866 (char_u *)&p_csqf, PV_NONE,
867 {(char_u *)"", (char_u *)0L}
868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)0L, (char_u *)0L}
871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
874#ifdef FEAT_CSCOPE
875 (char_u *)&p_cst, PV_NONE,
876#else
877 (char_u *)NULL, PV_NONE,
878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000879 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
881#ifdef FEAT_CSCOPE
882 (char_u *)&p_csto, PV_NONE,
883#else
884 (char_u *)NULL, PV_NONE,
885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000886 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
888#ifdef FEAT_CSCOPE
889 (char_u *)&p_csverbose, PV_NONE,
890#else
891 (char_u *)NULL, PV_NONE,
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000894 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
895#ifdef FEAT_SYN_HL
896 (char_u *)VAR_WIN, PV_CUC,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000901 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
902#ifdef FEAT_SYN_HL
903 (char_u *)VAR_WIN, PV_CUL,
904#else
905 (char_u *)NULL, PV_NONE,
906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"debug", NULL, P_STRING|P_VI_DEF,
909 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
912#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000913 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000914 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915#else
916 (char_u *)NULL, PV_NONE,
917 {(char_u *)NULL, (char_u *)0L}
918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
921#ifdef FEAT_MBYTE
922 (char_u *)&p_deco, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
928#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000929 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930#else
931 (char_u *)NULL, PV_NONE,
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
935#ifdef FEAT_DIFF
936 (char_u *)VAR_WIN, PV_DIFF,
937#else
938 (char_u *)NULL, PV_NONE,
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
942#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
943 (char_u *)&p_dex, PV_NONE,
944 {(char_u *)"", (char_u *)0L}
945#else
946 (char_u *)NULL, PV_NONE,
947 {(char_u *)0L, (char_u *)0L}
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
951#ifdef FEAT_DIFF
952 (char_u *)&p_dip, PV_NONE,
953 {(char_u *)"filler", (char_u *)NULL}
954#else
955 (char_u *)NULL, PV_NONE,
956 {(char_u *)"", (char_u *)NULL}
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
960#ifdef FEAT_DIGRAPHS
961 (char_u *)&p_dg, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
967 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
970 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"eadirection", "ead", P_STRING|P_VI_DEF,
973#ifdef FEAT_VERTSPLIT
974 (char_u *)&p_ead, PV_NONE,
975 {(char_u *)"both", (char_u *)0L}
976#else
977 (char_u *)NULL, PV_NONE,
978 {(char_u *)NULL, (char_u *)0L}
979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000980 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000981 {"edcompatible","ed", P_BOOL|P_VI_DEF,
982 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
985#ifdef FEAT_MBYTE
986 (char_u *)&p_enc, PV_NONE,
987 {(char_u *)ENC_DFLT, (char_u *)0L}
988#else
989 (char_u *)NULL, PV_NONE,
990 {(char_u *)0L, (char_u *)0L}
991#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
994 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
997 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1003 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1006#ifdef FEAT_QUICKFIX
1007 (char_u *)&p_ef, PV_NONE,
1008 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1009#else
1010 (char_u *)NULL, PV_NONE,
1011 {(char_u *)NULL, (char_u *)0L}
1012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1015#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018#else
1019 (char_u *)NULL, PV_NONE,
1020 {(char_u *)NULL, (char_u *)0L}
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 {"esckeys", "ek", P_BOOL|P_VIM,
1024 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001025 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1027#ifdef FEAT_AUTOCMD
1028 (char_u *)&p_ei, PV_NONE,
1029#else
1030 (char_u *)NULL, PV_NONE,
1031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1034 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1037 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1040#ifdef FEAT_MBYTE
1041 (char_u *)&p_fenc, PV_FENC,
1042 {(char_u *)"", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)0L, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1049#ifdef FEAT_MBYTE
1050 (char_u *)&p_fencs, PV_NONE,
1051 {(char_u *)"ucs-bom", (char_u *)0L}
1052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)0L, (char_u *)0L}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1058 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1061 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1063 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001064 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065#ifdef FEAT_AUTOCMD
1066 (char_u *)&p_ft, PV_FT,
1067 {(char_u *)"", (char_u *)0L}
1068#else
1069 (char_u *)NULL, PV_NONE,
1070 {(char_u *)0L, (char_u *)0L}
1071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1074#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1075 (char_u *)&p_fcs, PV_NONE,
1076 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1077#else
1078 (char_u *)NULL, PV_NONE,
1079 {(char_u *)"", (char_u *)0L}
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1083#ifdef FEAT_FKMAP
1084 (char_u *)&p_fkmap, PV_NONE,
1085#else
1086 (char_u *)NULL, PV_NONE,
1087#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"flash", "fl", P_BOOL|P_VI_DEF,
1090 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092#ifdef FEAT_FOLDING
1093 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1094 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1097 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1100 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1103# ifdef FEAT_EVAL
1104 (char_u *)VAR_WIN, PV_FDE,
1105 {(char_u *)"0", (char_u *)NULL}
1106# else
1107 (char_u *)NULL, PV_NONE,
1108 {(char_u *)NULL, (char_u *)0L}
1109# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1112 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001113 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1115 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1118 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1121 P_RWIN|P_COMMA|P_NODUP,
1122 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)"{{{,}}}", (char_u *)NULL}
1124 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1126 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1129 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1132 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1135 (char_u *)&p_fdo, PV_NONE,
1136 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1139# ifdef FEAT_EVAL
1140 (char_u *)VAR_WIN, PV_FDT,
1141 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001142# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 (char_u *)NULL, PV_NONE,
1144 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001145# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001148 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001149#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001150 (char_u *)&p_fex, PV_FEX,
1151 {(char_u *)"", (char_u *)0L}
1152#else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1158 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1160 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001161 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1162 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1164 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1166 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001168 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1169#ifdef HAVE_FSYNC
1170 (char_u *)&p_fs, PV_NONE,
1171 {(char_u *)TRUE, (char_u *)0L}
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)FALSE, (char_u *)0L}
1175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1178 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 {"graphic", "gr", P_BOOL|P_VI_DEF,
1181 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1184#ifdef FEAT_QUICKFIX
1185 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001186 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)NULL, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1193#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001194 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {
1196# ifdef WIN3264
1197 /* may be changed to "grep -n" in os_win32.c */
1198 (char_u *)"findstr /n",
1199# else
1200# ifdef UNIX
1201 /* Add an extra file name so that grep will always
1202 * insert a file name in the match line. */
1203 (char_u *)"grep -n $* /dev/null",
1204# else
1205# ifdef VMS
1206 (char_u *)"SEARCH/NUMBERS ",
1207# else
1208 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209# endif
1210# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213#else
1214 (char_u *)NULL, PV_NONE,
1215 {(char_u *)NULL, (char_u *)0L}
1216#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1219#ifdef CURSOR_SHAPE
1220 (char_u *)&p_guicursor, PV_NONE,
1221 {
1222# ifdef FEAT_GUI
1223 (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",
1224# else /* MSDOS or Win32 console */
1225 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1226# endif
1227 (char_u *)0L}
1228#else
1229 (char_u *)NULL, PV_NONE,
1230 {(char_u *)NULL, (char_u *)0L}
1231#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001232 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1234#ifdef FEAT_GUI
1235 (char_u *)&p_guifont, PV_NONE,
1236 {(char_u *)"", (char_u *)0L}
1237#else
1238 (char_u *)NULL, PV_NONE,
1239 {(char_u *)NULL, (char_u *)0L}
1240#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001241 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1243#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1244 (char_u *)&p_guifontset, PV_NONE,
1245 {(char_u *)"", (char_u *)0L}
1246#else
1247 (char_u *)NULL, PV_NONE,
1248 {(char_u *)NULL, (char_u *)0L}
1249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001250 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1252#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1253 (char_u *)&p_guifontwide, PV_NONE,
1254 {(char_u *)"", (char_u *)0L}
1255#else
1256 (char_u *)NULL, PV_NONE,
1257 {(char_u *)NULL, (char_u *)0L}
1258#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001261#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)&p_ghr, PV_NONE,
1263#else
1264 (char_u *)NULL, PV_NONE,
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001268#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269 (char_u *)&p_go, PV_NONE,
1270# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001271 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001273 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274# endif
1275#else
1276 (char_u *)NULL, PV_NONE,
1277 {(char_u *)NULL, (char_u *)0L}
1278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"guipty", NULL, P_BOOL|P_VI_DEF,
1281#if defined(FEAT_GUI)
1282 (char_u *)&p_guipty, PV_NONE,
1283#else
1284 (char_u *)NULL, PV_NONE,
1285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001287 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001288#if defined(FEAT_GUI_TABLINE)
1289 (char_u *)&p_gtl, PV_NONE,
1290 {(char_u *)"", (char_u *)0L}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001295 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001296 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001297#if defined(FEAT_GUI_TABLINE)
1298 (char_u *)&p_gtt, PV_NONE,
1299 {(char_u *)"", (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001304 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1306 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1309 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1311 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312 {"helpheight", "hh", P_NUM|P_VI_DEF,
1313#ifdef FEAT_WINDOWS
1314 (char_u *)&p_hh, PV_NONE,
1315#else
1316 (char_u *)NULL, PV_NONE,
1317#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001318 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1320#ifdef FEAT_MULTI_LANG
1321 (char_u *)&p_hlg, PV_NONE,
1322 {(char_u *)"", (char_u *)0L}
1323#else
1324 (char_u *)NULL, PV_NONE,
1325 {(char_u *)0L, (char_u *)0L}
1326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328 {"hidden", "hid", P_BOOL|P_VI_DEF,
1329 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1332 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1334 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335 {"history", "hi", P_NUM|P_VIM,
1336 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1339#ifdef FEAT_RIGHTLEFT
1340 (char_u *)&p_hkmap, PV_NONE,
1341#else
1342 (char_u *)NULL, PV_NONE,
1343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1346#ifdef FEAT_RIGHTLEFT
1347 (char_u *)&p_hkmapp, PV_NONE,
1348#else
1349 (char_u *)NULL, PV_NONE,
1350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1353 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355 {"icon", NULL, P_BOOL|P_VI_DEF,
1356#ifdef FEAT_TITLE
1357 (char_u *)&p_icon, PV_NONE,
1358#else
1359 (char_u *)NULL, PV_NONE,
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"iconstring", NULL, P_STRING|P_VI_DEF,
1363#ifdef FEAT_TITLE
1364 (char_u *)&p_iconstring, PV_NONE,
1365#else
1366 (char_u *)NULL, PV_NONE,
1367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1370 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001373#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374 (char_u *)&p_imak, PV_NONE,
1375#else
1376 (char_u *)NULL, PV_NONE,
1377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1380#ifdef USE_IM_CONTROL
1381 (char_u *)&p_imcmdline, PV_NONE,
1382#else
1383 (char_u *)NULL, PV_NONE,
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1387#ifdef USE_IM_CONTROL
1388 (char_u *)&p_imdisable, PV_NONE,
1389#else
1390 (char_u *)NULL, PV_NONE,
1391#endif
1392#ifdef __sgi
1393 {(char_u *)TRUE, (char_u *)0L}
1394#else
1395 {(char_u *)FALSE, (char_u *)0L}
1396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"iminsert", "imi", P_NUM|P_VI_DEF,
1399 (char_u *)&p_iminsert, PV_IMI,
1400#ifdef B_IMODE_IM
1401 {(char_u *)B_IMODE_IM, (char_u *)0L}
1402#else
1403 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {"imsearch", "ims", P_NUM|P_VI_DEF,
1407 (char_u *)&p_imsearch, PV_IMS,
1408#ifdef B_IMODE_IM
1409 {(char_u *)B_IMODE_IM, (char_u *)0L}
1410#else
1411 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1415#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001416 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1418#else
1419 (char_u *)NULL, PV_NONE,
1420 {(char_u *)0L, (char_u *)0L}
1421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001422 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1424#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1425 (char_u *)&p_inex, PV_INEX,
1426 {(char_u *)"", (char_u *)0L}
1427#else
1428 (char_u *)NULL, PV_NONE,
1429 {(char_u *)0L, (char_u *)0L}
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1433 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1436#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1437 (char_u *)&p_inde, PV_INDE,
1438 {(char_u *)"", (char_u *)0L}
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)0L, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1445#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1446 (char_u *)&p_indk, PV_INDK,
1447 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1448#else
1449 (char_u *)NULL, PV_NONE,
1450 {(char_u *)0L, (char_u *)0L}
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"infercase", "inf", P_BOOL|P_VI_DEF,
1454 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001455 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1457 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1460 (char_u *)&p_isf, PV_NONE,
1461 {
1462#ifdef BACKSLASH_IN_FILENAME
1463 /* Excluded are: & and ^ are special in cmd.exe
1464 * ( and ) are used in text separating fnames */
1465 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1466#else
1467# ifdef AMIGA
1468 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1469# else
1470# ifdef VMS
1471 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1472# else /* UNIX et al. */
1473# ifdef EBCDIC
1474 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1475# else
1476 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1477# endif
1478# endif
1479# endif
1480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001481 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1483 (char_u *)&p_isi, PV_NONE,
1484 {
1485#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1486 (char_u *)"@,48-57,_,128-167,224-235",
1487#else
1488# ifdef EBCDIC
1489 /* TODO: EBCDIC Check this! @ == isalpha()*/
1490 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1491 "112-120,128,140-142,156,158,172,"
1492 "174,186,191,203-207,219-225,235-239,"
1493 "251-254",
1494# else
1495 (char_u *)"@,48-57,_,192-255",
1496# endif
1497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1500 (char_u *)&p_isk, PV_ISK,
1501 {
1502#ifdef EBCDIC
1503 (char_u *)"@,240-249,_",
1504 /* TODO: EBCDIC Check this! @ == isalpha()*/
1505 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1506 "112-120,128,140-142,156,158,172,"
1507 "174,186,191,203-207,219-225,235-239,"
1508 "251-254",
1509#else
1510 (char_u *)"@,48-57,_",
1511# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1512 (char_u *)"@,48-57,_,128-167,224-235"
1513# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001514 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515# endif
1516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001517 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1519 (char_u *)&p_isp, PV_NONE,
1520 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001521#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1522 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 || defined(VMS)
1524 (char_u *)"@,~-255",
1525#else
1526# ifdef EBCDIC
1527 /* all chars above 63 are printable */
1528 (char_u *)"63-255",
1529# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001530 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531# endif
1532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1535 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1538#ifdef FEAT_CRYPT
1539 (char_u *)&p_key, PV_KEY,
1540 {(char_u *)"", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001546 {"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 +00001547#ifdef FEAT_KEYMAP
1548 (char_u *)&p_keymap, PV_KMAP,
1549 {(char_u *)"", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)"", (char_u *)0L}
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1556#ifdef FEAT_VISUAL
1557 (char_u *)&p_km, PV_NONE,
1558#else
1559 (char_u *)NULL, PV_NONE,
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001563 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {
1565#if defined(MSDOS) || defined(MSWIN)
1566 (char_u *)":help",
1567#else
1568#ifdef VMS
1569 (char_u *)"help",
1570#else
1571# if defined(OS2)
1572 (char_u *)"view /",
1573# else
1574# ifdef USEMAN_S
1575 (char_u *)"man -s",
1576# else
1577 (char_u *)"man",
1578# endif
1579# endif
1580#endif
1581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001582 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1584#ifdef FEAT_LANGMAP
1585 (char_u *)&p_langmap, PV_NONE,
1586 {(char_u *)"", /* unmatched } */
1587#else
1588 (char_u *)NULL, PV_NONE,
1589 {(char_u *)NULL,
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001592 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1594 (char_u *)&p_lm, PV_NONE,
1595#else
1596 (char_u *)NULL, PV_NONE,
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1600#ifdef FEAT_WINDOWS
1601 (char_u *)&p_ls, PV_NONE,
1602#else
1603 (char_u *)NULL, PV_NONE,
1604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1607 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001608 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1610#ifdef FEAT_LINEBREAK
1611 (char_u *)VAR_WIN, PV_LBR,
1612#else
1613 (char_u *)NULL, PV_NONE,
1614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1617 (char_u *)&Rows, PV_NONE,
1618 {
1619#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1620 (char_u *)25L,
1621#else
1622 (char_u *)24L,
1623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001624 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1626#ifdef FEAT_GUI
1627 (char_u *)&p_linespace, PV_NONE,
1628#else
1629 (char_u *)NULL, PV_NONE,
1630#endif
1631#ifdef FEAT_GUI_W32
1632 {(char_u *)1L, (char_u *)0L}
1633#else
1634 {(char_u *)0L, (char_u *)0L}
1635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001636 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 {"lisp", NULL, P_BOOL|P_VI_DEF,
1638#ifdef FEAT_LISP
1639 (char_u *)&p_lisp, PV_LISP,
1640#else
1641 (char_u *)NULL, PV_NONE,
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1645#ifdef FEAT_LISP
1646 (char_u *)&p_lispwords, PV_NONE,
1647 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)"", (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1654 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1657 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1660 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001662#ifdef FEAT_GUI_MAC
1663 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1664 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {"magic", NULL, P_BOOL|P_VI_DEF,
1668 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001670 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671#ifdef FEAT_QUICKFIX
1672 (char_u *)&p_mef, PV_NONE,
1673 {(char_u *)"", (char_u *)0L}
1674#else
1675 (char_u *)NULL, PV_NONE,
1676 {(char_u *)NULL, (char_u *)0L}
1677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1680#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001681 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682# ifdef VMS
1683 {(char_u *)"MMS", (char_u *)0L}
1684# else
1685 {(char_u *)"make", (char_u *)0L}
1686# endif
1687#else
1688 (char_u *)NULL, PV_NONE,
1689 {(char_u *)NULL, (char_u *)0L}
1690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1693 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001694 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696 {"matchtime", "mat", P_NUM|P_VI_DEF,
1697 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001698 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001699 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1700#ifdef FEAT_MBYTE
1701 (char_u *)&p_mco, PV_NONE,
1702#else
1703 (char_u *)NULL, PV_NONE,
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1707#ifdef FEAT_EVAL
1708 (char_u *)&p_mfd, PV_NONE,
1709#else
1710 (char_u *)NULL, PV_NONE,
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1714 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001715 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"maxmem", "mm", P_NUM|P_VI_DEF,
1717 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1719 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001720 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1721 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1724 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"menuitems", "mis", P_NUM|P_VI_DEF,
1728#ifdef FEAT_MENU
1729 (char_u *)&p_mis, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"mesg", NULL, P_BOOL|P_VI_DEF,
1735 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001737 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001738#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001739 (char_u *)&p_msm, PV_NONE,
1740 {(char_u *)"460000,2000,500", (char_u *)0L}
1741#else
1742 (char_u *)NULL, PV_NONE,
1743 {(char_u *)0L, (char_u *)0L}
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"modeline", "ml", P_BOOL|P_VIM,
1747 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {"modelines", "mls", P_NUM|P_VI_DEF,
1750 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1753 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1756 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"more", NULL, P_BOOL|P_VIM,
1759 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1762 (char_u *)&p_mouse, PV_NONE,
1763 {
1764#if defined(MSDOS) || defined(WIN3264)
1765 (char_u *)"a",
1766#else
1767 (char_u *)"",
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1771#ifdef FEAT_GUI
1772 (char_u *)&p_mousef, PV_NONE,
1773#else
1774 (char_u *)NULL, PV_NONE,
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1778#ifdef FEAT_GUI
1779 (char_u *)&p_mh, PV_NONE,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1785 (char_u *)&p_mousem, PV_NONE,
1786 {
1787#if defined(MSDOS) || defined(MSWIN)
1788 (char_u *)"popup",
1789#else
1790# if defined(MACOS)
1791 (char_u *)"popup_setpos",
1792# else
1793 (char_u *)"extend",
1794# endif
1795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1798#ifdef FEAT_MOUSESHAPE
1799 (char_u *)&p_mouseshape, PV_NONE,
1800 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1801#else
1802 (char_u *)NULL, PV_NONE,
1803 {(char_u *)NULL, (char_u *)0L}
1804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1807 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001808 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001809 {"mzquantum", "mzq", P_NUM,
1810#ifdef FEAT_MZSCHEME
1811 (char_u *)&p_mzq, PV_NONE,
1812#else
1813 (char_u *)NULL, PV_NONE,
1814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"novice", NULL, P_BOOL|P_VI_DEF,
1817 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001818 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1820 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)"octal,hex", (char_u *)0L}
1822 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1824 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001826 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1827#ifdef FEAT_LINEBREAK
1828 (char_u *)VAR_WIN, PV_NUW,
1829#else
1830 (char_u *)NULL, PV_NONE,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001833 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001834#ifdef FEAT_COMPL_FUNC
1835 (char_u *)&p_ofu, PV_OFU,
1836 {(char_u *)"", (char_u *)0L}
1837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)0L, (char_u *)0L}
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"open", NULL, P_BOOL|P_VI_DEF,
1843 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001845 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1846#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1847 (char_u *)&p_odev, PV_NONE,
1848#else
1849 (char_u *)NULL, PV_NONE,
1850#endif
1851 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001853 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1854 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"optimize", "opt", P_BOOL|P_VI_DEF,
1857 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1860#ifdef FEAT_OSFILETYPE
1861 (char_u *)&p_oft, PV_OFT,
1862 {(char_u *)DFLT_OFT, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"paragraphs", "para", P_STRING|P_VI_DEF,
1869 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001870 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001872 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1876 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1879#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1880 (char_u *)&p_pex, PV_NONE,
1881 {(char_u *)"", (char_u *)0L}
1882#else
1883 (char_u *)NULL, PV_NONE,
1884 {(char_u *)0L, (char_u *)0L}
1885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001887 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001891 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {
1893#if defined AMIGA || defined MSDOS || defined MSWIN
1894 (char_u *)".,,",
1895#else
1896# if defined(__EMX__)
1897 (char_u *)".,/emx/include,,",
1898# else /* Unix, probably */
1899 (char_u *)".,/usr/include,,",
1900# endif
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1904 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001906 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1908 (char_u *)&p_pvh, PV_NONE,
1909#else
1910 (char_u *)NULL, PV_NONE,
1911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1914#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1915 (char_u *)VAR_WIN, PV_PVW,
1916#else
1917 (char_u *)NULL, PV_NONE,
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001920 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921#ifdef FEAT_PRINTER
1922 (char_u *)&p_pdev, PV_NONE,
1923 {(char_u *)"", (char_u *)0L}
1924#else
1925 (char_u *)NULL, PV_NONE,
1926 {(char_u *)NULL, (char_u *)0L}
1927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"printencoding", "penc", P_STRING|P_VI_DEF,
1930#ifdef FEAT_POSTSCRIPT
1931 (char_u *)&p_penc, PV_NONE,
1932 {(char_u *)"", (char_u *)0L}
1933#else
1934 (char_u *)NULL, PV_NONE,
1935 {(char_u *)NULL, (char_u *)0L}
1936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1939#ifdef FEAT_POSTSCRIPT
1940 (char_u *)&p_pexpr, PV_NONE,
1941 {(char_u *)"", (char_u *)0L}
1942#else
1943 (char_u *)NULL, PV_NONE,
1944 {(char_u *)NULL, (char_u *)0L}
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"printfont", "pfn", P_STRING|P_VI_DEF,
1948#ifdef FEAT_PRINTER
1949 (char_u *)&p_pfn, PV_NONE,
1950 {
1951# ifdef MSWIN
1952 (char_u *)"Courier_New:h10",
1953# else
1954 (char_u *)"courier",
1955# endif
1956 (char_u *)0L}
1957#else
1958 (char_u *)NULL, PV_NONE,
1959 {(char_u *)NULL, (char_u *)0L}
1960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1963#ifdef FEAT_PRINTER
1964 (char_u *)&p_header, PV_NONE,
1965 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1966#else
1967 (char_u *)NULL, PV_NONE,
1968 {(char_u *)NULL, (char_u *)0L}
1969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001971 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1972#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1973 (char_u *)&p_pmcs, PV_NONE,
1974 {(char_u *)"", (char_u *)0L}
1975#else
1976 (char_u *)NULL, PV_NONE,
1977 {(char_u *)NULL, (char_u *)0L}
1978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001980 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1981#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1982 (char_u *)&p_pmfn, PV_NONE,
1983 {(char_u *)"", (char_u *)0L}
1984#else
1985 (char_u *)NULL, PV_NONE,
1986 {(char_u *)NULL, (char_u *)0L}
1987#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1990#ifdef FEAT_PRINTER
1991 (char_u *)&p_popt, PV_NONE,
1992 {(char_u *)"", (char_u *)0L}
1993#else
1994 (char_u *)NULL, PV_NONE,
1995 {(char_u *)NULL, (char_u *)0L}
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001999 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002001 {"pumheight", "ph", P_NUM|P_VI_DEF,
2002#ifdef FEAT_INS_EXPAND
2003 (char_u *)&p_ph, PV_NONE,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002008 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2009#ifdef FEAT_TEXTOBJ
2010 (char_u *)&p_qe, PV_QE,
2011 {(char_u *)"\\", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)NULL, (char_u *)0L}
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2018 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"redraw", NULL, P_BOOL|P_VI_DEF,
2021 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002023 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2024#ifdef FEAT_RELTIME
2025 (char_u *)&p_rdt, PV_NONE,
2026#else
2027 (char_u *)NULL, PV_NONE,
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002030 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2031 (char_u *)VAR_WIN, PV_RNU,
2032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"remap", NULL, P_BOOL|P_VI_DEF,
2034 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"report", NULL, P_NUM|P_VI_DEF,
2037 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2040#ifdef WIN3264
2041 (char_u *)&p_rs, PV_NONE,
2042#else
2043 (char_u *)NULL, PV_NONE,
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2047#ifdef FEAT_RIGHTLEFT
2048 (char_u *)&p_ri, PV_NONE,
2049#else
2050 (char_u *)NULL, PV_NONE,
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2054#ifdef FEAT_RIGHTLEFT
2055 (char_u *)VAR_WIN, PV_RL,
2056#else
2057 (char_u *)NULL, PV_NONE,
2058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2061#ifdef FEAT_RIGHTLEFT
2062 (char_u *)VAR_WIN, PV_RLC,
2063 {(char_u *)"search", (char_u *)NULL}
2064#else
2065 (char_u *)NULL, PV_NONE,
2066 {(char_u *)NULL, (char_u *)0L}
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2070#ifdef FEAT_CMDL_INFO
2071 (char_u *)&p_ru, PV_NONE,
2072#else
2073 (char_u *)NULL, PV_NONE,
2074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2077#ifdef FEAT_STL_OPT
2078 (char_u *)&p_ruf, PV_NONE,
2079#else
2080 (char_u *)NULL, PV_NONE,
2081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2084 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2088 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2091#ifdef FEAT_SCROLLBIND
2092 (char_u *)VAR_WIN, PV_SCBIND,
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 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2098 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2101 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2104#ifdef FEAT_SCROLLBIND
2105 (char_u *)&p_sbo, PV_NONE,
2106 {(char_u *)"ver,jump", (char_u *)0L}
2107#else
2108 (char_u *)NULL, PV_NONE,
2109 {(char_u *)0L, (char_u *)0L}
2110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 {"sections", "sect", P_STRING|P_VI_DEF,
2113 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2117 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"selection", "sel", P_STRING|P_VI_DEF,
2120#ifdef FEAT_VISUAL
2121 (char_u *)&p_sel, PV_NONE,
2122#else
2123 (char_u *)NULL, PV_NONE,
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)"inclusive", (char_u *)0L}
2126 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2128#ifdef FEAT_VISUAL
2129 (char_u *)&p_slm, PV_NONE,
2130#else
2131 (char_u *)NULL, PV_NONE,
2132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2135#ifdef FEAT_SESSION
2136 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002137 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)0L, (char_u *)0L}
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2145 (char_u *)&p_sh, PV_NONE,
2146 {
2147#ifdef VMS
2148 (char_u *)"-",
2149#else
2150# if defined(MSDOS)
2151 (char_u *)"command",
2152# else
2153# if defined(WIN16)
2154 (char_u *)"command.com",
2155# else
2156# if defined(WIN3264)
2157 (char_u *)"", /* set in set_init_1() */
2158# else
2159# if defined(OS2)
2160 (char_u *)"cmd.exe",
2161# else
2162# if defined(ARCHIE)
2163 (char_u *)"gos",
2164# else
2165 (char_u *)"sh",
2166# endif
2167# endif
2168# endif
2169# endif
2170# endif
2171#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2174 (char_u *)&p_shcf, PV_NONE,
2175 {
2176#if defined(MSDOS) || defined(MSWIN)
2177 (char_u *)"/c",
2178#else
2179# if defined(OS2)
2180 (char_u *)"/c",
2181# else
2182 (char_u *)"-c",
2183# endif
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2187#ifdef FEAT_QUICKFIX
2188 (char_u *)&p_sp, PV_NONE,
2189 {
2190#if defined(UNIX) || defined(OS2)
2191# ifdef ARCHIE
2192 (char_u *)"2>",
2193# else
2194 (char_u *)"| tee",
2195# endif
2196#else
2197 (char_u *)">",
2198#endif
2199 (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)0L, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2209 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2212#ifdef BACKSLASH_IN_FILENAME
2213 (char_u *)&p_ssl, PV_NONE,
2214#else
2215 (char_u *)NULL, PV_NONE,
2216#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002217 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002218 {"shelltemp", "stmp", P_BOOL,
2219 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221 {"shelltype", "st", P_NUM|P_VI_DEF,
2222#ifdef AMIGA
2223 (char_u *)&p_st, PV_NONE,
2224#else
2225 (char_u *)NULL, PV_NONE,
2226#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002227 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2229 (char_u *)&p_sxq, PV_NONE,
2230 {
2231#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2232 (char_u *)"\"",
2233#else
2234 (char_u *)"",
2235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2238 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2241 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2244 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)"", (char_u *)"filnxtToO"}
2246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"shortname", "sn", P_BOOL|P_VI_DEF,
2248#ifdef SHORT_FNAME
2249 (char_u *)NULL, PV_NONE,
2250#else
2251 (char_u *)&p_sn, PV_SN,
2252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2255#ifdef FEAT_LINEBREAK
2256 (char_u *)&p_sbr, PV_NONE,
2257#else
2258 (char_u *)NULL, PV_NONE,
2259#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002260 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 {"showcmd", "sc", P_BOOL|P_VIM,
2262#ifdef FEAT_CMDL_INFO
2263 (char_u *)&p_sc, PV_NONE,
2264#else
2265 (char_u *)NULL, PV_NONE,
2266#endif
2267 {(char_u *)FALSE,
2268#ifdef UNIX
2269 (char_u *)FALSE
2270#else
2271 (char_u *)TRUE
2272#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2275 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2278 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"showmode", "smd", P_BOOL|P_VIM,
2281 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002283 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2284#ifdef FEAT_WINDOWS
2285 (char_u *)&p_stal, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2291 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2294 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2297 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2300 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2303#ifdef FEAT_SMARTINDENT
2304 (char_u *)&p_si, PV_SI,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2310 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2313 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2316 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002318 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002319#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002320 (char_u *)VAR_WIN, PV_SPELL,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002325 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002326#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002327 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002328 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002329#else
2330 (char_u *)NULL, PV_NONE,
2331 {(char_u *)0L, (char_u *)0L}
2332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002334 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002335#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002336 (char_u *)&p_spf, PV_SPF,
2337 {(char_u *)"", (char_u *)0L}
2338#else
2339 (char_u *)NULL, PV_NONE,
2340 {(char_u *)0L, (char_u *)0L}
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002343 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002344#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002345 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002346 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002347#else
2348 (char_u *)NULL, PV_NONE,
2349 {(char_u *)0L, (char_u *)0L}
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002352 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002353#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002354 (char_u *)&p_sps, PV_NONE,
2355 {(char_u *)"best", (char_u *)0L}
2356#else
2357 (char_u *)NULL, PV_NONE,
2358 {(char_u *)0L, (char_u *)0L}
2359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2362#ifdef FEAT_WINDOWS
2363 (char_u *)&p_sb, PV_NONE,
2364#else
2365 (char_u *)NULL, PV_NONE,
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"splitright", "spr", P_BOOL|P_VI_DEF,
2369#ifdef FEAT_VERTSPLIT
2370 (char_u *)&p_spr, PV_NONE,
2371#else
2372 (char_u *)NULL, PV_NONE,
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2376 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2379#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002380 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2386 (char_u *)&p_su, PV_NONE,
2387 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002390#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 (char_u *)&p_sua, PV_SUA,
2392 {(char_u *)"", (char_u *)0L}
2393#else
2394 (char_u *)NULL, PV_NONE,
2395 {(char_u *)0L, (char_u *)0L}
2396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2399 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"swapsync", "sws", P_STRING|P_VI_DEF,
2402 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2405 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002407 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2408#ifdef FEAT_SYN_HL
2409 (char_u *)&p_smc, PV_SMC,
2410 {(char_u *)3000L, (char_u *)0L}
2411#else
2412 (char_u *)NULL, PV_NONE,
2413 {(char_u *)0L, (char_u *)0L}
2414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002416 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417#ifdef FEAT_SYN_HL
2418 (char_u *)&p_syn, PV_SYN,
2419 {(char_u *)"", (char_u *)0L}
2420#else
2421 (char_u *)NULL, PV_NONE,
2422 {(char_u *)0L, (char_u *)0L}
2423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002425 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2426#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002427 (char_u *)&p_tal, PV_NONE,
2428#else
2429 (char_u *)NULL, PV_NONE,
2430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002432 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2433#ifdef FEAT_WINDOWS
2434 (char_u *)&p_tpm, PV_NONE,
2435#else
2436 (char_u *)NULL, PV_NONE,
2437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2440 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2443 (char_u *)&p_tbs, PV_NONE,
2444#ifdef VMS /* binary searching doesn't appear to work on VMS */
2445 {(char_u *)0L, (char_u *)0L}
2446#else
2447 {(char_u *)TRUE, (char_u *)0L}
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"taglength", "tl", P_NUM|P_VI_DEF,
2451 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"tagrelative", "tr", P_BOOL|P_VIM,
2454 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002457 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {
2459#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2460 (char_u *)"./tags,./TAGS,tags,TAGS",
2461#else
2462 (char_u *)"./tags,tags",
2463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2466 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2469 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2472#ifdef FEAT_ARABIC
2473 (char_u *)&p_tbidi, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2479#ifdef FEAT_MBYTE
2480 (char_u *)&p_tenc, PV_NONE,
2481 {(char_u *)"", (char_u *)0L}
2482#else
2483 (char_u *)NULL, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L}
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"terse", NULL, P_BOOL|P_VI_DEF,
2488 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"textauto", "ta", P_BOOL|P_VIM,
2491 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2493 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2495 (char_u *)&p_tx, PV_TX,
2496 {
2497#ifdef USE_CRNL
2498 (char_u *)TRUE,
2499#else
2500 (char_u *)FALSE,
2501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2504 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2507#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002508 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509#else
2510 (char_u *)NULL, PV_NONE,
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2514 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"timeout", "to", P_BOOL|P_VI_DEF,
2517 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2520 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"title", NULL, P_BOOL|P_VI_DEF,
2523#ifdef FEAT_TITLE
2524 (char_u *)&p_title, PV_NONE,
2525#else
2526 (char_u *)NULL, PV_NONE,
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"titlelen", NULL, P_NUM|P_VI_DEF,
2530#ifdef FEAT_TITLE
2531 (char_u *)&p_titlelen, PV_NONE,
2532#else
2533 (char_u *)NULL, PV_NONE,
2534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002536 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537#ifdef FEAT_TITLE
2538 (char_u *)&p_titleold, PV_NONE,
2539 {(char_u *)N_("Thanks for flying Vim"),
2540 (char_u *)0L}
2541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 {"titlestring", NULL, P_STRING|P_VI_DEF,
2547#ifdef FEAT_TITLE
2548 (char_u *)&p_titlestring, PV_NONE,
2549#else
2550 (char_u *)NULL, PV_NONE,
2551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2554 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2555 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)"icons,tooltips", (char_u *)0L}
2557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558#endif
2559#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2560 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2561 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563#endif
2564 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2565 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2568 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2571 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2574 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2577#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2578 (char_u *)&p_ttym, PV_NONE,
2579#else
2580 (char_u *)NULL, PV_NONE,
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2584 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2587 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"undolevels", "ul", P_NUM|P_VI_DEF,
2590 (char_u *)&p_ul, PV_NONE,
2591 {
2592#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2593 (char_u *)1000L,
2594#else
2595 (char_u *)100L,
2596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"updatecount", "uc", P_NUM|P_VI_DEF,
2599 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"updatetime", "ut", P_NUM|P_VI_DEF,
2602 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"verbose", "vbs", P_NUM|P_VI_DEF,
2605 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002607 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2608 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2611#ifdef FEAT_SESSION
2612 (char_u *)&p_vdir, PV_NONE,
2613 {(char_u *)DFLT_VDIR, (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2620#ifdef FEAT_SESSION
2621 (char_u *)&p_vop, PV_NONE,
2622 {(char_u *)"folds,options,cursor", (char_u *)0L}
2623#else
2624 (char_u *)NULL, PV_NONE,
2625 {(char_u *)0L, (char_u *)0L}
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2629#ifdef FEAT_VIMINFO
2630 (char_u *)&p_viminfo, PV_NONE,
2631#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002632 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#else
2634# ifdef AMIGA
2635 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002636 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002638 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639# endif
2640#endif
2641#else
2642 (char_u *)NULL, PV_NONE,
2643 {(char_u *)0L, (char_u *)0L}
2644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2647#ifdef FEAT_VIRTUALEDIT
2648 (char_u *)&p_ve, PV_NONE,
2649 {(char_u *)"", (char_u *)""}
2650#else
2651 (char_u *)NULL, PV_NONE,
2652 {(char_u *)0L, (char_u *)0L}
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2656 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"w300", NULL, P_NUM|P_VI_DEF,
2659 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"w1200", NULL, P_NUM|P_VI_DEF,
2662 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"w9600", NULL, P_NUM|P_VI_DEF,
2665 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"warn", NULL, P_BOOL|P_VI_DEF,
2668 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2671 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2674 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"wildchar", "wc", P_NUM|P_VIM,
2677 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2679 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2681 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2684#ifdef FEAT_WILDIGN
2685 (char_u *)&p_wig, PV_NONE,
2686#else
2687 (char_u *)NULL, PV_NONE,
2688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2691#ifdef FEAT_WILDMENU
2692 (char_u *)&p_wmnu, PV_NONE,
2693#else
2694 (char_u *)NULL, PV_NONE,
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2698 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002700 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2701#ifdef FEAT_CMDL_COMPL
2702 (char_u *)&p_wop, PV_NONE,
2703 {(char_u *)"", (char_u *)0L}
2704#else
2705 (char_u *)NULL, PV_NONE,
2706 {(char_u *)NULL, (char_u *)0L}
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2710#ifdef FEAT_WAK
2711 (char_u *)&p_wak, PV_NONE,
2712 {(char_u *)"menu", (char_u *)0L}
2713#else
2714 (char_u *)NULL, PV_NONE,
2715 {(char_u *)NULL, (char_u *)0L}
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002719 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"winheight", "wh", P_NUM|P_VI_DEF,
2722#ifdef FEAT_WINDOWS
2723 (char_u *)&p_wh, PV_NONE,
2724#else
2725 (char_u *)NULL, PV_NONE,
2726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002729#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 (char_u *)VAR_WIN, PV_WFH,
2731#else
2732 (char_u *)NULL, PV_NONE,
2733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002735 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2736#ifdef FEAT_VERTSPLIT
2737 (char_u *)VAR_WIN, PV_WFW,
2738#else
2739 (char_u *)NULL, PV_NONE,
2740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2743#ifdef FEAT_WINDOWS
2744 (char_u *)&p_wmh, PV_NONE,
2745#else
2746 (char_u *)NULL, PV_NONE,
2747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2750#ifdef FEAT_VERTSPLIT
2751 (char_u *)&p_wmw, PV_NONE,
2752#else
2753 (char_u *)NULL, PV_NONE,
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2757#ifdef FEAT_VERTSPLIT
2758 (char_u *)&p_wiw, PV_NONE,
2759#else
2760 (char_u *)NULL, PV_NONE,
2761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2764 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2767 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2770 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"write", NULL, P_BOOL|P_VI_DEF,
2773 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"writeany", "wa", P_BOOL|P_VI_DEF,
2776 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2779 (char_u *)&p_wb, PV_NONE,
2780 {
2781#ifdef FEAT_WRITEBACKUP
2782 (char_u *)TRUE,
2783#else
2784 (char_u *)FALSE,
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"writedelay", "wd", P_NUM|P_VI_DEF,
2788 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790
2791/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002792#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795
2796 p_term("t_AB", T_CAB)
2797 p_term("t_AF", T_CAF)
2798 p_term("t_AL", T_CAL)
2799 p_term("t_al", T_AL)
2800 p_term("t_bc", T_BC)
2801 p_term("t_cd", T_CD)
2802 p_term("t_ce", T_CE)
2803 p_term("t_cl", T_CL)
2804 p_term("t_cm", T_CM)
2805 p_term("t_Co", T_CCO)
2806 p_term("t_CS", T_CCS)
2807 p_term("t_cs", T_CS)
2808#ifdef FEAT_VERTSPLIT
2809 p_term("t_CV", T_CSV)
2810#endif
2811 p_term("t_ut", T_UT)
2812 p_term("t_da", T_DA)
2813 p_term("t_db", T_DB)
2814 p_term("t_DL", T_CDL)
2815 p_term("t_dl", T_DL)
2816 p_term("t_fs", T_FS)
2817 p_term("t_IE", T_CIE)
2818 p_term("t_IS", T_CIS)
2819 p_term("t_ke", T_KE)
2820 p_term("t_ks", T_KS)
2821 p_term("t_le", T_LE)
2822 p_term("t_mb", T_MB)
2823 p_term("t_md", T_MD)
2824 p_term("t_me", T_ME)
2825 p_term("t_mr", T_MR)
2826 p_term("t_ms", T_MS)
2827 p_term("t_nd", T_ND)
2828 p_term("t_op", T_OP)
2829 p_term("t_RI", T_CRI)
2830 p_term("t_RV", T_CRV)
2831 p_term("t_Sb", T_CSB)
2832 p_term("t_Sf", T_CSF)
2833 p_term("t_se", T_SE)
2834 p_term("t_so", T_SO)
2835 p_term("t_sr", T_SR)
2836 p_term("t_ts", T_TS)
2837 p_term("t_te", T_TE)
2838 p_term("t_ti", T_TI)
2839 p_term("t_ue", T_UE)
2840 p_term("t_us", T_US)
2841 p_term("t_vb", T_VB)
2842 p_term("t_ve", T_VE)
2843 p_term("t_vi", T_VI)
2844 p_term("t_vs", T_VS)
2845 p_term("t_WP", T_CWP)
2846 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002847 p_term("t_SI", T_CSI)
2848 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 p_term("t_xs", T_XS)
2850 p_term("t_ZH", T_CZH)
2851 p_term("t_ZR", T_CZR)
2852
2853/* terminal key codes are not in here */
2854
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 /* end marker */
2856 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857};
2858
2859#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2860
2861#ifdef FEAT_MBYTE
2862static char *(p_ambw_values[]) = {"single", "double", NULL};
2863#endif
2864static char *(p_bg_values[]) = {"light", "dark", NULL};
2865static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2866static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002867#ifdef FEAT_CMDL_COMPL
2868static char *(p_wop_values[]) = {"tagfile", NULL};
2869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870#ifdef FEAT_WAK
2871static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2872#endif
2873static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2874#ifdef FEAT_VISUAL
2875static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2876static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2877#endif
2878#ifdef FEAT_VISUAL
2879static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2880#endif
2881#ifdef FEAT_BROWSE
2882static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2883#endif
2884#ifdef FEAT_SCROLLBIND
2885static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2886#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002887static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888#ifdef FEAT_VERTSPLIT
2889static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2890#endif
2891#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002892# ifdef FEAT_AUTOCMD
2893static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2894# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002896# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2898#endif
2899static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2900#ifdef FEAT_FOLDING
2901static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002902# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002904# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 NULL};
2906static char *(p_fcl_values[]) = {"all", NULL};
2907#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002908#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002909static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002910#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911
2912static void set_option_default __ARGS((int, int opt_flags, int compatible));
2913static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002914static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002915static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916static char_u *illegal_char __ARGS((char_u *, int));
2917static int string_to_key __ARGS((char_u *arg));
2918#ifdef FEAT_CMDWIN
2919static char_u *check_cedit __ARGS((void));
2920#endif
2921#ifdef FEAT_TITLE
2922static void did_set_title __ARGS((int icon));
2923#endif
2924static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2925static void didset_options __ARGS((void));
2926static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002927#if defined(FEAT_EVAL) || defined(PROTO)
2928static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2929#else
2930# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2933static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2934static 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));
2935static char_u *set_chars_option __ARGS((char_u **varp));
2936#ifdef FEAT_CLIPBOARD
2937static char_u *check_clipboard_option __ARGS((void));
2938#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002939#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002940static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002941#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002942#ifdef FEAT_EVAL
2943static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2944#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002946static 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 +00002947static void check_redraw __ARGS((long_u flags));
2948static int findoption __ARGS((char_u *));
2949static int find_key_option __ARGS((char_u *));
2950static void showoptions __ARGS((int all, int opt_flags));
2951static int optval_default __ARGS((struct vimoption *, char_u *varp));
2952static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2953static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2954static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2955static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2956static int istermoption __ARGS((struct vimoption *));
2957static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2958static char_u *get_varp __ARGS((struct vimoption *));
2959static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2960static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2961#ifdef FEAT_LANGMAP
2962static void langmap_init __ARGS((void));
2963static void langmap_set __ARGS((void));
2964#endif
2965static void paste_option_changed __ARGS((void));
2966static void compatible_set __ARGS((void));
2967#ifdef FEAT_LINEBREAK
2968static void fill_breakat_flags __ARGS((void));
2969#endif
2970static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2971static int check_opt_strings __ARGS((char_u *val, char **values, int));
2972static int check_opt_wim __ARGS((void));
2973
2974/*
2975 * Initialize the options, first part.
2976 *
2977 * Called only once from main(), just after creating the first buffer.
2978 */
2979 void
2980set_init_1()
2981{
2982 char_u *p;
2983 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00002984 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985
2986#ifdef FEAT_LANGMAP
2987 langmap_init();
2988#endif
2989
2990 /* Be Vi compatible by default */
2991 p_cp = TRUE;
2992
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002993 /* Use POSIX compatibility when $VIM_POSIX is set. */
2994 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002995 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002996 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002997 set_string_default("shm", (char_u *)"A");
2998 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002999
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 /*
3001 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003002 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003004 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3006# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003007 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003009 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003011 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012# endif
3013#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003014 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 set_string_default("sh", p);
3016
3017#ifdef FEAT_WILDIGN
3018 /*
3019 * Set the default for 'backupskip' to include environment variables for
3020 * temp files.
3021 */
3022 {
3023# ifdef UNIX
3024 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3025# else
3026 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3027# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003028 int len;
3029 garray_T ga;
3030 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031
3032 ga_init2(&ga, 1, 100);
3033 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3034 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003035 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036# ifdef UNIX
3037 if (*names[n] == NUL)
3038 p = (char_u *)"/tmp";
3039 else
3040# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003041 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 if (p != NULL && *p != NUL)
3043 {
3044 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003045 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 if (ga_grow(&ga, len) == OK)
3047 {
3048 if (ga.ga_len > 0)
3049 STRCAT(ga.ga_data, ",");
3050 STRCAT(ga.ga_data, p);
3051 add_pathsep(ga.ga_data);
3052 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 ga.ga_len += len;
3054 }
3055 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003056 if (mustfree)
3057 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 }
3059 if (ga.ga_data != NULL)
3060 {
3061 set_string_default("bsk", ga.ga_data);
3062 vim_free(ga.ga_data);
3063 }
3064 }
3065#endif
3066
3067 /*
3068 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3069 */
3070 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003071 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003073#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3074 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3075#endif
3076 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003078 /* Use amount of memory available at this moment. */
3079 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080#else
3081# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003082 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003083 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003085 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086# endif
3087#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003089 opt_idx = findoption((char_u *)"maxmem");
3090 if (opt_idx >= 0)
3091 {
3092#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3093 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3094 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3095#endif
3096 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3097 }
3098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 }
3100
3101#ifdef FEAT_GUI_W32
3102 /* force 'shortname' for Win32s */
3103 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003104 {
3105 opt_idx = findoption((char_u *)"shortname");
3106 if (opt_idx >= 0)
3107 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3108 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109#endif
3110
3111#ifdef FEAT_SEARCHPATH
3112 {
3113 char_u *cdpath;
3114 char_u *buf;
3115 int i;
3116 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003117 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118
3119 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003120 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 if (cdpath != NULL)
3122 {
3123 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3124 if (buf != NULL)
3125 {
3126 buf[0] = ','; /* start with ",", current dir first */
3127 j = 1;
3128 for (i = 0; cdpath[i] != NUL; ++i)
3129 {
3130 if (vim_ispathlistsep(cdpath[i]))
3131 buf[j++] = ',';
3132 else
3133 {
3134 if (cdpath[i] == ' ' || cdpath[i] == ',')
3135 buf[j++] = '\\';
3136 buf[j++] = cdpath[i];
3137 }
3138 }
3139 buf[j] = NUL;
3140 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003141 if (opt_idx >= 0)
3142 {
3143 options[opt_idx].def_val[VI_DEFAULT] = buf;
3144 options[opt_idx].flags |= P_DEF_ALLOCED;
3145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003147 if (mustfree)
3148 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 }
3150 }
3151#endif
3152
3153#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3154 /* Set print encoding on platforms that don't default to latin1 */
3155 set_string_default("penc",
3156# if defined(MSWIN) || defined(OS2)
3157 (char_u *)"cp1252"
3158# else
3159# ifdef VMS
3160 (char_u *)"dec-mcs"
3161# else
3162# ifdef EBCDIC
3163 (char_u *)"ebcdic-uk"
3164# else
3165# ifdef MAC
3166 (char_u *)"mac-roman"
3167# else /* HPUX */
3168 (char_u *)"hp-roman8"
3169# endif
3170# endif
3171# endif
3172# endif
3173 );
3174#endif
3175
3176#ifdef FEAT_POSTSCRIPT
3177 /* 'printexpr' must be allocated to be able to evaluate it. */
3178 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003179# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3180 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181# else
3182# ifdef VMS
3183 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3184
3185# else
3186 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3187# endif
3188# endif
3189 );
3190#endif
3191
3192 /*
3193 * Set all the options (except the terminal options) to their default
3194 * value. Also set the global value for local options.
3195 */
3196 set_options_default(0);
3197
3198#ifdef FEAT_GUI
3199 if (found_reverse_arg)
3200 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3201#endif
3202
3203 curbuf->b_p_initialized = TRUE;
3204 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3205 check_buf_options(curbuf);
3206 check_win_options(curwin);
3207 check_options();
3208
3209 /* Must be before option_expand(), because that one needs vim_isIDc() */
3210 didset_options();
3211
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003212#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003213 /* Use the current chartab for the generic chartab. */
3214 init_spell_chartab();
3215#endif
3216
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217#ifdef FEAT_LINEBREAK
3218 /*
3219 * initialize the table for 'breakat'.
3220 */
3221 fill_breakat_flags();
3222#endif
3223
3224 /*
3225 * Expand environment variables and things like "~" for the defaults.
3226 * If option_expand() returns non-NULL the variable is expanded. This can
3227 * only happen for non-indirect options.
3228 * Also set the default to the expanded value, so ":set" does not list
3229 * them.
3230 * Don't set the P_ALLOCED flag, because we don't want to free the
3231 * default.
3232 */
3233 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3234 {
3235 if ((options[opt_idx].flags & P_GETTEXT)
3236 && options[opt_idx].var != NULL)
3237 p = (char_u *)_(*(char **)options[opt_idx].var);
3238 else
3239 p = option_expand(opt_idx, NULL);
3240 if (p != NULL && (p = vim_strsave(p)) != NULL)
3241 {
3242 *(char_u **)options[opt_idx].var = p;
3243 /* VIMEXP
3244 * Defaults for all expanded options are currently the same for Vi
3245 * and Vim. When this changes, add some code here! Also need to
3246 * split P_DEF_ALLOCED in two.
3247 */
3248 if (options[opt_idx].flags & P_DEF_ALLOCED)
3249 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3250 options[opt_idx].def_val[VI_DEFAULT] = p;
3251 options[opt_idx].flags |= P_DEF_ALLOCED;
3252 }
3253 }
3254
3255 /* Initialize the highlight_attr[] table. */
3256 highlight_changed();
3257
3258 save_file_ff(curbuf); /* Buffer is unchanged */
3259
3260 /* Parse default for 'wildmode' */
3261 check_opt_wim();
3262
3263#if defined(FEAT_ARABIC)
3264 /* Detect use of mlterm.
3265 * Mlterm is a terminal emulator akin to xterm that has some special
3266 * abilities (bidi namely).
3267 * NOTE: mlterm's author is being asked to 'set' a variable
3268 * instead of an environment variable due to inheritance.
3269 */
3270 if (mch_getenv((char_u *)"MLTERM") != NULL)
3271 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3272#endif
3273
3274#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3275 /* Parse default for 'fillchars'. */
3276 (void)set_chars_option(&p_fcs);
3277#endif
3278
3279#ifdef FEAT_CLIPBOARD
3280 /* Parse default for 'clipboard' */
3281 (void)check_clipboard_option();
3282#endif
3283
3284#ifdef FEAT_MBYTE
3285# if defined(WIN3264) && defined(FEAT_GETTEXT)
3286 /*
3287 * If $LANG isn't set, try to get a good value for it. This makes the
3288 * right language be used automatically. Don't do this for English.
3289 */
3290 if (mch_getenv((char_u *)"LANG") == NULL)
3291 {
3292 char buf[20];
3293
3294 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3295 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3296 * only the first two. */
3297 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3298 (LPTSTR)buf, 20);
3299 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3300 {
3301 /* There are a few exceptions (probably more) */
3302 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3303 STRCPY(buf, "zh_TW");
3304 else if (STRNICMP(buf, "chs", 3) == 0
3305 || STRNICMP(buf, "zhc", 3) == 0)
3306 STRCPY(buf, "zh_CN");
3307 else if (STRNICMP(buf, "jp", 2) == 0)
3308 STRCPY(buf, "ja");
3309 else
3310 buf[2] = NUL; /* truncate to two-letter code */
3311 vim_setenv("LANG", buf);
3312 }
3313 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003314# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003315# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003316 /* Moved to os_mac_conv.c to avoid dependency problems. */
3317 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003318# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319# endif
3320
3321 /* enc_locale() will try to find the encoding of the current locale. */
3322 p = enc_locale();
3323 if (p != NULL)
3324 {
3325 char_u *save_enc;
3326
3327 /* Try setting 'encoding' and check if the value is valid.
3328 * If not, go back to the default "latin1". */
3329 save_enc = p_enc;
3330 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003331 if (STRCMP(p_enc, "gb18030") == 0)
3332 {
3333 /* We don't support "gb18030", but "cp936" is a good substitute
3334 * for practical purposes, thus use that. It's not an alias to
3335 * still support conversion between gb18030 and utf-8. */
3336 p_enc = vim_strsave((char_u *)"cp936");
3337 vim_free(p);
3338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 if (mb_init() == NULL)
3340 {
3341 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003342 if (opt_idx >= 0)
3343 {
3344 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3345 options[opt_idx].flags |= P_DEF_ALLOCED;
3346 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003348#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3349 || defined(VMS)
3350 if (STRCMP(p_enc, "latin1") == 0
3351# ifdef FEAT_MBYTE
3352 || enc_utf8
3353# endif
3354 )
3355 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003356 /* Adjust the default for 'isprint' and 'iskeyword' to match
3357 * latin1. Also set the defaults for when 'nocompatible' is
3358 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003359 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003360 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003361 set_string_option_direct((char_u *)"isk", -1,
3362 ISK_LATIN1, OPT_FREE, SID_NONE);
3363 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003364 if (opt_idx >= 0)
3365 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003366 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003367 if (opt_idx >= 0)
3368 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003369 (void)init_chartab();
3370 }
3371#endif
3372
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373# if defined(WIN3264) && !defined(FEAT_GUI)
3374 /* Win32 console: When GetACP() returns a different value from
3375 * GetConsoleCP() set 'termencoding'. */
3376 if (GetACP() != GetConsoleCP())
3377 {
3378 char buf[50];
3379
3380 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3381 p_tenc = vim_strsave((char_u *)buf);
3382 if (p_tenc != NULL)
3383 {
3384 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003385 if (opt_idx >= 0)
3386 {
3387 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3388 options[opt_idx].flags |= P_DEF_ALLOCED;
3389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 convert_setup(&input_conv, p_tenc, p_enc);
3391 convert_setup(&output_conv, p_enc, p_tenc);
3392 }
3393 else
3394 p_tenc = empty_option;
3395 }
3396# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003397# if defined(WIN3264) && defined(FEAT_MBYTE)
3398 /* $HOME may have characters in active code page. */
3399 init_homedir();
3400# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 }
3402 else
3403 {
3404 vim_free(p_enc);
3405 p_enc = save_enc;
3406 }
3407 }
3408#endif
3409
3410#ifdef FEAT_MULTI_LANG
3411 /* Set the default for 'helplang'. */
3412 set_helplang_default(get_mess_lang());
3413#endif
3414}
3415
3416/*
3417 * Set an option to its default value.
3418 * This does not take care of side effects!
3419 */
3420 static void
3421set_option_default(opt_idx, opt_flags, compatible)
3422 int opt_idx;
3423 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3424 int compatible; /* use Vi default value */
3425{
3426 char_u *varp; /* pointer to variable for current option */
3427 int dvi; /* index in def_val[] */
3428 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003429 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3431
3432 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3433 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003434 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 {
3436 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3437 if (flags & P_STRING)
3438 {
3439 /* Use set_string_option_direct() for local options to handle
3440 * freeing and allocating the value. */
3441 if (options[opt_idx].indir != PV_NONE)
3442 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003443 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 else
3445 {
3446 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3447 free_string_option(*(char_u **)(varp));
3448 *(char_u **)varp = options[opt_idx].def_val[dvi];
3449 options[opt_idx].flags &= ~P_ALLOCED;
3450 }
3451 }
3452 else if (flags & P_NUM)
3453 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003454 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455 win_comp_scroll(curwin);
3456 else
3457 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003458 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 /* May also set global value for local option. */
3460 if (both)
3461 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3462 *(long *)varp;
3463 }
3464 }
3465 else /* P_BOOL */
3466 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003467 /* the cast to long is required for Manx C, long_i is needed for
3468 * MSVC */
3469 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003470#ifdef UNIX
3471 /* 'modeline' defaults to off for root */
3472 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3473 *(int *)varp = FALSE;
3474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 /* May also set global value for local option. */
3476 if (both)
3477 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3478 *(int *)varp;
3479 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003480
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003481 /* The default value is not insecure. */
3482 flagsp = insecure_flag(opt_idx, opt_flags);
3483 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484 }
3485
3486#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003487 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488#endif
3489}
3490
3491/*
3492 * Set all options (except terminal options) to their default value.
3493 */
3494 static void
3495set_options_default(opt_flags)
3496 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3497{
3498 int i;
3499#ifdef FEAT_WINDOWS
3500 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003501 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502#endif
3503
3504 for (i = 0; !istermoption(&options[i]); i++)
3505 if (!(options[i].flags & P_NODEFAULT))
3506 set_option_default(i, opt_flags, p_cp);
3507
3508#ifdef FEAT_WINDOWS
3509 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003510 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 win_comp_scroll(wp);
3512#else
3513 win_comp_scroll(curwin);
3514#endif
3515}
3516
3517/*
3518 * Set the Vi-default value of a string option.
3519 * Used for 'sh', 'backupskip' and 'term'.
3520 */
3521 void
3522set_string_default(name, val)
3523 char *name;
3524 char_u *val;
3525{
3526 char_u *p;
3527 int opt_idx;
3528
3529 p = vim_strsave(val);
3530 if (p != NULL) /* we don't want a NULL */
3531 {
3532 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003533 if (opt_idx >= 0)
3534 {
3535 if (options[opt_idx].flags & P_DEF_ALLOCED)
3536 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3537 options[opt_idx].def_val[VI_DEFAULT] = p;
3538 options[opt_idx].flags |= P_DEF_ALLOCED;
3539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 }
3541}
3542
3543/*
3544 * Set the Vi-default value of a number option.
3545 * Used for 'lines' and 'columns'.
3546 */
3547 void
3548set_number_default(name, val)
3549 char *name;
3550 long val;
3551{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003552 int opt_idx;
3553
3554 opt_idx = findoption((char_u *)name);
3555 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003556 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557}
3558
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003559#if defined(EXITFREE) || defined(PROTO)
3560/*
3561 * Free all options.
3562 */
3563 void
3564free_all_options()
3565{
3566 int i;
3567
3568 for (i = 0; !istermoption(&options[i]); i++)
3569 {
3570 if (options[i].indir == PV_NONE)
3571 {
3572 /* global option: free value and default value. */
3573 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3574 free_string_option(*(char_u **)options[i].var);
3575 if (options[i].flags & P_DEF_ALLOCED)
3576 free_string_option(options[i].def_val[VI_DEFAULT]);
3577 }
3578 else if (options[i].var != VAR_WIN
3579 && (options[i].flags & P_STRING))
3580 /* buffer-local option: free global value */
3581 free_string_option(*(char_u **)options[i].var);
3582 }
3583}
3584#endif
3585
3586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587/*
3588 * Initialize the options, part two: After getting Rows and Columns and
3589 * setting 'term'.
3590 */
3591 void
3592set_init_2()
3593{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003594 int idx;
3595
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 /*
3597 * 'scroll' defaults to half the window height. Note that this default is
3598 * wrong when the window height changes.
3599 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003600 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003601 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003602 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003603 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 comp_col();
3605
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003606 /*
3607 * 'window' is only for backwards compatibility with Vi.
3608 * Default is Rows - 1.
3609 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003610 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003611 p_window = Rows - 1;
3612 set_number_default("window", Rows - 1);
3613
Bram Moolenaarf740b292006-02-16 22:11:02 +00003614 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003616 /*
3617 * If 'background' wasn't set by the user, try guessing the value,
3618 * depending on the terminal name. Only need to check for terminals
3619 * with a dark background, that can handle color.
3620 */
3621 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003622 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3623 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003625 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003626 /* don't mark it as set, when starting the GUI it may be
3627 * changed again */
3628 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 }
3630#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003631
3632#ifdef CURSOR_SHAPE
3633 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3634#endif
3635#ifdef FEAT_MOUSESHAPE
3636 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3637#endif
3638#ifdef FEAT_PRINTER
3639 (void)parse_printoptions(); /* parse 'printoptions' default value */
3640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641}
3642
3643/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003644 * Return "dark" or "light" depending on the kind of terminal.
3645 * This is just guessing! Recognized are:
3646 * "linux" Linux console
3647 * "screen.linux" Linux console with screen
3648 * "cygwin" Cygwin shell
3649 * "putty" Putty program
3650 * We also check the COLORFGBG environment variable, which is set by
3651 * rxvt and derivatives. This variable contains either two or three
3652 * values separated by semicolons; we want the last value in either
3653 * case. If this value is 0-6 or 8, our background is dark.
3654 */
3655 static char_u *
3656term_bg_default()
3657{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3659 /* DOS console nearly always black */
3660 return (char_u *)"dark";
3661#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003662 char_u *p;
3663
Bram Moolenaarf740b292006-02-16 22:11:02 +00003664 if (STRCMP(T_NAME, "linux") == 0
3665 || STRCMP(T_NAME, "screen.linux") == 0
3666 || STRCMP(T_NAME, "cygwin") == 0
3667 || STRCMP(T_NAME, "putty") == 0
3668 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3669 && (p = vim_strrchr(p, ';')) != NULL
3670 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3671 && p[2] == NUL))
3672 return (char_u *)"dark";
3673 return (char_u *)"light";
3674#endif
3675}
3676
3677/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 * Initialize the options, part three: After reading the .vimrc
3679 */
3680 void
3681set_init_3()
3682{
3683#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3684/*
3685 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3686 * This is done after other initializations, where 'shell' might have been
3687 * set, but only if they have not been set before.
3688 */
3689 char_u *p;
3690 int idx_srr;
3691 int do_srr;
3692#ifdef FEAT_QUICKFIX
3693 int idx_sp;
3694 int do_sp;
3695#endif
3696
3697 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (idx_srr < 0)
3699 do_srr = FALSE;
3700 else
3701 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702#ifdef FEAT_QUICKFIX
3703 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003704 if (idx_sp < 0)
3705 do_sp = FALSE;
3706 else
3707 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708#endif
3709
3710 /*
3711 * Isolate the name of the shell:
3712 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3713 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003714 * But don't allow a space in the path, so that this works:
3715 * "/usr/bin/csh --rcfile ~/.cshrc"
3716 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003718#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719 p = gettail(p_sh);
3720 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003721#else
3722 p = skiptowhite(p_sh);
3723 if (*p == NUL)
3724 {
3725 /* No white space, use the tail. */
3726 p = vim_strsave(gettail(p_sh));
3727 }
3728 else
3729 {
3730 char_u *p1, *p2;
3731
3732 /* Find the last path separator before the space. */
3733 p1 = p_sh;
3734 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3735 if (vim_ispathsep(*p2))
3736 p1 = p2 + 1;
3737 p = vim_strnsave(p1, (int)(p - p1));
3738 }
3739#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 if (p != NULL)
3741 {
3742 /*
3743 * Default for p_sp is "| tee", for p_srr is ">".
3744 * For known shells it is changed here to include stderr.
3745 */
3746 if ( fnamecmp(p, "csh") == 0
3747 || fnamecmp(p, "tcsh") == 0
3748# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3749 || fnamecmp(p, "csh.exe") == 0
3750 || fnamecmp(p, "tcsh.exe") == 0
3751# endif
3752 )
3753 {
3754#if defined(FEAT_QUICKFIX)
3755 if (do_sp)
3756 {
3757# ifdef WIN3264
3758 p_sp = (char_u *)">&";
3759# else
3760 p_sp = (char_u *)"|& tee";
3761# endif
3762 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3763 }
3764#endif
3765 if (do_srr)
3766 {
3767 p_srr = (char_u *)">&";
3768 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3769 }
3770 }
3771 else
3772# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3773 if ( fnamecmp(p, "sh") == 0
3774 || fnamecmp(p, "ksh") == 0
3775 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003776 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 || fnamecmp(p, "bash") == 0
3778# ifdef WIN3264
3779 || fnamecmp(p, "cmd") == 0
3780 || fnamecmp(p, "sh.exe") == 0
3781 || fnamecmp(p, "ksh.exe") == 0
3782 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003783 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 || fnamecmp(p, "bash.exe") == 0
3785 || fnamecmp(p, "cmd.exe") == 0
3786# endif
3787 )
3788# endif
3789 {
3790#if defined(FEAT_QUICKFIX)
3791 if (do_sp)
3792 {
3793# ifdef WIN3264
3794 p_sp = (char_u *)">%s 2>&1";
3795# else
3796 p_sp = (char_u *)"2>&1| tee";
3797# endif
3798 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3799 }
3800#endif
3801 if (do_srr)
3802 {
3803 p_srr = (char_u *)">%s 2>&1";
3804 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3805 }
3806 }
3807 vim_free(p);
3808 }
3809#endif
3810
3811#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3812 /*
3813 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3814 * This is done after other initializations, where 'shell' might have been
3815 * set, but only if they have not been set before. Default for p_shcf is
3816 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3817 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3818 * command.com. And for Win32 we need to set p_sxq instead.
3819 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003820 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 {
3822 int idx3;
3823
3824 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003825 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 {
3827 p_shcf = (char_u *)"-c";
3828 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3829 }
3830
3831# ifndef DJGPP
3832# ifdef WIN3264
3833 /* Somehow Win32 requires the quotes around the redirection too */
3834 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003835 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 {
3837 p_sxq = (char_u *)"\"";
3838 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3839 }
3840# else
3841 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003842 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 {
3844 p_shq = (char_u *)"\"";
3845 options[idx3].def_val[VI_DEFAULT] = p_shq;
3846 }
3847# endif
3848# endif
3849 }
3850#endif
3851
3852#ifdef FEAT_TITLE
3853 set_title_defaults();
3854#endif
3855}
3856
3857#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3858/*
3859 * When 'helplang' is still at its default value, set it to "lang".
3860 * Only the first two characters of "lang" are used.
3861 */
3862 void
3863set_helplang_default(lang)
3864 char_u *lang;
3865{
3866 int idx;
3867
3868 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3869 return;
3870 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003871 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 {
3873 if (options[idx].flags & P_ALLOCED)
3874 free_string_option(p_hlg);
3875 p_hlg = vim_strsave(lang);
3876 if (p_hlg == NULL)
3877 p_hlg = empty_option;
3878 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003879 {
3880 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3881 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3882 {
3883 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3884 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 options[idx].flags |= P_ALLOCED;
3889 }
3890}
3891#endif
3892
3893#ifdef FEAT_GUI
3894static char_u *gui_bg_default __ARGS((void));
3895
3896 static char_u *
3897gui_bg_default()
3898{
3899 if (gui_get_lightness(gui.back_pixel) < 127)
3900 return (char_u *)"dark";
3901 return (char_u *)"light";
3902}
3903
3904/*
3905 * Option initializations that can only be done after opening the GUI window.
3906 */
3907 void
3908init_gui_options()
3909{
3910 /* Set the 'background' option according to the lightness of the
3911 * background color, unless the user has set it already. */
3912 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3913 {
3914 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3915 highlight_changed();
3916 }
3917}
3918#endif
3919
3920#ifdef FEAT_TITLE
3921/*
3922 * 'title' and 'icon' only default to true if they have not been set or reset
3923 * in .vimrc and we can read the old value.
3924 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3925 * they can be reset. This reduces startup time when using X on a remote
3926 * machine.
3927 */
3928 void
3929set_title_defaults()
3930{
3931 int idx1;
3932 long val;
3933
3934 /*
3935 * If GUI is (going to be) used, we can always set the window title and
3936 * icon name. Saves a bit of time, because the X11 display server does
3937 * not need to be contacted.
3938 */
3939 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003940 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 {
3942#ifdef FEAT_GUI
3943 if (gui.starting || gui.in_use)
3944 val = TRUE;
3945 else
3946#endif
3947 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003948 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 p_title = val;
3950 }
3951 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003952 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 {
3954#ifdef FEAT_GUI
3955 if (gui.starting || gui.in_use)
3956 val = TRUE;
3957 else
3958#endif
3959 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003960 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 p_icon = val;
3962 }
3963}
3964#endif
3965
3966/*
3967 * Parse 'arg' for option settings.
3968 *
3969 * 'arg' may be IObuff, but only when no errors can be present and option
3970 * does not need to be expanded with option_expand().
3971 * "opt_flags":
3972 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003973 * OPT_GLOBAL for ":setglobal"
3974 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003976 * OPT_WINONLY to only set window-local options
3977 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 *
3979 * returns FAIL if an error is detected, OK otherwise
3980 */
3981 int
3982do_set(arg, opt_flags)
3983 char_u *arg; /* option string (may be written to!) */
3984 int opt_flags;
3985{
3986 int opt_idx;
3987 char_u *errmsg;
3988 char_u errbuf[80];
3989 char_u *startarg;
3990 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3991 int nextchar; /* next non-white char after option name */
3992 int afterchar; /* character just after option name */
3993 int len;
3994 int i;
3995 long value;
3996 int key;
3997 long_u flags; /* flags for current option */
3998 char_u *varp = NULL; /* pointer to variable for current option */
3999 int did_show = FALSE; /* already showed one value */
4000 int adding; /* "opt+=arg" */
4001 int prepending; /* "opt^=arg" */
4002 int removing; /* "opt-=arg" */
4003 int cp_val = 0;
4004 char_u key_name[2];
4005
4006 if (*arg == NUL)
4007 {
4008 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004009 did_show = TRUE;
4010 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 }
4012
4013 while (*arg != NUL) /* loop to process all options */
4014 {
4015 errmsg = NULL;
4016 startarg = arg; /* remember for error message */
4017
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004018 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4019 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 {
4021 /*
4022 * ":set all" show all options.
4023 * ":set all&" set all options to their default value.
4024 */
4025 arg += 3;
4026 if (*arg == '&')
4027 {
4028 ++arg;
4029 /* Only for :set command set global value of local options. */
4030 set_options_default(OPT_FREE | opt_flags);
4031 }
4032 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004033 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004035 did_show = TRUE;
4036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004038 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 {
4040 showoptions(2, opt_flags);
4041 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004042 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 arg += 7;
4044 }
4045 else
4046 {
4047 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004048 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 {
4050 prefix = 0;
4051 arg += 2;
4052 }
4053 else if (STRNCMP(arg, "inv", 3) == 0)
4054 {
4055 prefix = 2;
4056 arg += 3;
4057 }
4058
4059 /* find end of name */
4060 key = 0;
4061 if (*arg == '<')
4062 {
4063 nextchar = 0;
4064 opt_idx = -1;
4065 /* look out for <t_>;> */
4066 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4067 len = 5;
4068 else
4069 {
4070 len = 1;
4071 while (arg[len] != NUL && arg[len] != '>')
4072 ++len;
4073 }
4074 if (arg[len] != '>')
4075 {
4076 errmsg = e_invarg;
4077 goto skip;
4078 }
4079 arg[len] = NUL; /* put NUL after name */
4080 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4081 opt_idx = findoption(arg + 1);
4082 arg[len++] = '>'; /* restore '>' */
4083 if (opt_idx == -1)
4084 key = find_key_option(arg + 1);
4085 }
4086 else
4087 {
4088 len = 0;
4089 /*
4090 * The two characters after "t_" may not be alphanumeric.
4091 */
4092 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4093 len = 4;
4094 else
4095 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4096 ++len;
4097 nextchar = arg[len];
4098 arg[len] = NUL; /* put NUL after name */
4099 opt_idx = findoption(arg);
4100 arg[len] = nextchar; /* restore nextchar */
4101 if (opt_idx == -1)
4102 key = find_key_option(arg);
4103 }
4104
4105 /* remember character after option name */
4106 afterchar = arg[len];
4107
4108 /* skip white space, allow ":set ai ?" */
4109 while (vim_iswhite(arg[len]))
4110 ++len;
4111
4112 adding = FALSE;
4113 prepending = FALSE;
4114 removing = FALSE;
4115 if (arg[len] != NUL && arg[len + 1] == '=')
4116 {
4117 if (arg[len] == '+')
4118 {
4119 adding = TRUE; /* "+=" */
4120 ++len;
4121 }
4122 else if (arg[len] == '^')
4123 {
4124 prepending = TRUE; /* "^=" */
4125 ++len;
4126 }
4127 else if (arg[len] == '-')
4128 {
4129 removing = TRUE; /* "-=" */
4130 ++len;
4131 }
4132 }
4133 nextchar = arg[len];
4134
4135 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4136 {
4137 errmsg = (char_u *)N_("E518: Unknown option");
4138 goto skip;
4139 }
4140
4141 if (opt_idx >= 0)
4142 {
4143 if (options[opt_idx].var == NULL) /* hidden option: skip */
4144 {
4145 /* Only give an error message when requesting the value of
4146 * a hidden option, ignore setting it. */
4147 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4148 && (!(options[opt_idx].flags & P_BOOL)
4149 || nextchar == '?'))
4150 errmsg = (char_u *)N_("E519: Option not supported");
4151 goto skip;
4152 }
4153
4154 flags = options[opt_idx].flags;
4155 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4156 }
4157 else
4158 {
4159 flags = P_STRING;
4160 if (key < 0)
4161 {
4162 key_name[0] = KEY2TERMCAP0(key);
4163 key_name[1] = KEY2TERMCAP1(key);
4164 }
4165 else
4166 {
4167 key_name[0] = KS_KEY;
4168 key_name[1] = (key & 0xff);
4169 }
4170 }
4171
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004172 /* Skip all options that are not window-local (used when showing
4173 * an already loaded buffer in a window). */
4174 if ((opt_flags & OPT_WINONLY)
4175 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4176 goto skip;
4177
Bram Moolenaara3227e22006-03-08 21:32:40 +00004178 /* Skip all options that are window-local (used for :vimgrep). */
4179 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4180 && options[opt_idx].var == VAR_WIN)
4181 goto skip;
4182
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004183 /* Disallow changing some options from modelines. */
4184 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004186 if (flags & P_SECURE)
4187 {
4188 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4189 goto skip;
4190 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004191#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004192 /* In diff mode some options are overruled. This avoids that
4193 * 'foldmethod' becomes "marker" instead of "diff" and that
4194 * "wrap" gets set. */
4195 if (curwin->w_p_diff
4196 && (options[opt_idx].indir == PV_FDM
4197 || options[opt_idx].indir == PV_WRAP))
4198 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 }
4201
4202#ifdef HAVE_SANDBOX
4203 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004204 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 {
4206 errmsg = (char_u *)_(e_sandbox);
4207 goto skip;
4208 }
4209#endif
4210
4211 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4212 {
4213 arg += len;
4214 cp_val = p_cp;
4215 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4216 {
4217 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4218 {
4219 cp_val = FALSE;
4220 arg += 3;
4221 }
4222 else /* "opt&vi": set to Vi default */
4223 {
4224 cp_val = TRUE;
4225 arg += 2;
4226 }
4227 }
4228 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4229 && arg[1] != NUL && !vim_iswhite(arg[1]))
4230 {
4231 errmsg = e_trailing;
4232 goto skip;
4233 }
4234 }
4235
4236 /*
4237 * allow '=' and ':' as MSDOS command.com allows only one
4238 * '=' character per "set" command line. grrr. (jw)
4239 */
4240 if (nextchar == '?'
4241 || (prefix == 1
4242 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4243 && !(flags & P_BOOL)))
4244 {
4245 /*
4246 * print value
4247 */
4248 if (did_show)
4249 msg_putchar('\n'); /* cursor below last one */
4250 else
4251 {
4252 gotocmdline(TRUE); /* cursor at status line */
4253 did_show = TRUE; /* remember that we did a line */
4254 }
4255 if (opt_idx >= 0)
4256 {
4257 showoneopt(&options[opt_idx], opt_flags);
4258#ifdef FEAT_EVAL
4259 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004260 {
4261 /* Mention where the option was last set. */
4262 if (varp == options[opt_idx].var)
4263 last_set_msg(options[opt_idx].scriptID);
4264 else if ((int)options[opt_idx].indir & PV_WIN)
4265 last_set_msg(curwin->w_p_scriptID[
4266 (int)options[opt_idx].indir & PV_MASK]);
4267 else if ((int)options[opt_idx].indir & PV_BUF)
4268 last_set_msg(curbuf->b_p_scriptID[
4269 (int)options[opt_idx].indir & PV_MASK]);
4270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271#endif
4272 }
4273 else
4274 {
4275 char_u *p;
4276
4277 p = find_termcode(key_name);
4278 if (p == NULL)
4279 {
4280 errmsg = (char_u *)N_("E518: Unknown option");
4281 goto skip;
4282 }
4283 else
4284 (void)show_one_termcode(key_name, p, TRUE);
4285 }
4286 if (nextchar != '?'
4287 && nextchar != NUL && !vim_iswhite(afterchar))
4288 errmsg = e_trailing;
4289 }
4290 else
4291 {
4292 if (flags & P_BOOL) /* boolean */
4293 {
4294 if (nextchar == '=' || nextchar == ':')
4295 {
4296 errmsg = e_invarg;
4297 goto skip;
4298 }
4299
4300 /*
4301 * ":set opt!": invert
4302 * ":set opt&": reset to default value
4303 * ":set opt<": reset to global value
4304 */
4305 if (nextchar == '!')
4306 value = *(int *)(varp) ^ 1;
4307 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004308 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 ((flags & P_VI_DEF) || cp_val)
4310 ? VI_DEFAULT : VIM_DEFAULT];
4311 else if (nextchar == '<')
4312 {
4313 /* For 'autoread' -1 means to use global value. */
4314 if ((int *)varp == &curbuf->b_p_ar
4315 && opt_flags == OPT_LOCAL)
4316 value = -1;
4317 else
4318 value = *(int *)get_varp_scope(&(options[opt_idx]),
4319 OPT_GLOBAL);
4320 }
4321 else
4322 {
4323 /*
4324 * ":set invopt": invert
4325 * ":set opt" or ":set noopt": set or reset
4326 */
4327 if (nextchar != NUL && !vim_iswhite(afterchar))
4328 {
4329 errmsg = e_trailing;
4330 goto skip;
4331 }
4332 if (prefix == 2) /* inv */
4333 value = *(int *)(varp) ^ 1;
4334 else
4335 value = prefix;
4336 }
4337
4338 errmsg = set_bool_option(opt_idx, varp, (int)value,
4339 opt_flags);
4340 }
4341 else /* numeric or string */
4342 {
4343 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4344 || prefix != 1)
4345 {
4346 errmsg = e_invarg;
4347 goto skip;
4348 }
4349
4350 if (flags & P_NUM) /* numeric */
4351 {
4352 /*
4353 * Different ways to set a number option:
4354 * & set to default value
4355 * < set to global value
4356 * <xx> accept special key codes for 'wildchar'
4357 * c accept any non-digit for 'wildchar'
4358 * [-]0-9 set number
4359 * other error
4360 */
4361 ++arg;
4362 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004363 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364 ((flags & P_VI_DEF) || cp_val)
4365 ? VI_DEFAULT : VIM_DEFAULT];
4366 else if (nextchar == '<')
4367 value = *(long *)get_varp_scope(&(options[opt_idx]),
4368 OPT_GLOBAL);
4369 else if (((long *)varp == &p_wc
4370 || (long *)varp == &p_wcm)
4371 && (*arg == '<'
4372 || *arg == '^'
4373 || ((!arg[1] || vim_iswhite(arg[1]))
4374 && !VIM_ISDIGIT(*arg))))
4375 {
4376 value = string_to_key(arg);
4377 if (value == 0 && (long *)varp != &p_wcm)
4378 {
4379 errmsg = e_invarg;
4380 goto skip;
4381 }
4382 }
4383 /* allow negative numbers (for 'undolevels') */
4384 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4385 {
4386 i = 0;
4387 if (*arg == '-')
4388 i = 1;
4389#ifdef HAVE_STRTOL
4390 value = strtol((char *)arg, NULL, 0);
4391 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4392 i += 2;
4393#else
4394 value = atol((char *)arg);
4395#endif
4396 while (VIM_ISDIGIT(arg[i]))
4397 ++i;
4398 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4399 {
4400 errmsg = e_invarg;
4401 goto skip;
4402 }
4403 }
4404 else
4405 {
4406 errmsg = (char_u *)N_("E521: Number required after =");
4407 goto skip;
4408 }
4409
4410 if (adding)
4411 value = *(long *)varp + value;
4412 if (prepending)
4413 value = *(long *)varp * value;
4414 if (removing)
4415 value = *(long *)varp - value;
4416 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004417 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 }
4419 else if (opt_idx >= 0) /* string */
4420 {
4421 char_u *save_arg = NULL;
4422 char_u *s = NULL;
4423 char_u *oldval; /* previous value if *varp */
4424 char_u *newval;
4425 char_u *origval;
4426 unsigned newlen;
4427 int comma;
4428 int bs;
4429 int new_value_alloced; /* new string option
4430 was allocated */
4431
4432 /* When using ":set opt=val" for a global option
4433 * with a local value the local value will be
4434 * reset, use the global value here. */
4435 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004436 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 varp = options[opt_idx].var;
4438
4439 /* The old value is kept until we are sure that the
4440 * new value is valid. */
4441 oldval = *(char_u **)varp;
4442 if (nextchar == '&') /* set to default val */
4443 {
4444 newval = options[opt_idx].def_val[
4445 ((flags & P_VI_DEF) || cp_val)
4446 ? VI_DEFAULT : VIM_DEFAULT];
4447 if ((char_u **)varp == &p_bg)
4448 {
4449 /* guess the value of 'background' */
4450#ifdef FEAT_GUI
4451 if (gui.in_use)
4452 newval = gui_bg_default();
4453 else
4454#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004455 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456 }
4457
4458 /* expand environment variables and ~ (since the
4459 * default value was already expanded, only
4460 * required when an environment variable was set
4461 * later */
4462 if (newval == NULL)
4463 newval = empty_option;
4464 else
4465 {
4466 s = option_expand(opt_idx, newval);
4467 if (s == NULL)
4468 s = newval;
4469 newval = vim_strsave(s);
4470 }
4471 new_value_alloced = TRUE;
4472 }
4473 else if (nextchar == '<') /* set to global val */
4474 {
4475 newval = vim_strsave(*(char_u **)get_varp_scope(
4476 &(options[opt_idx]), OPT_GLOBAL));
4477 new_value_alloced = TRUE;
4478 }
4479 else
4480 {
4481 ++arg; /* jump to after the '=' or ':' */
4482
4483 /*
4484 * Set 'keywordprg' to ":help" if an empty
4485 * value was passed to :set by the user.
4486 * Misuse errbuf[] for the resulting string.
4487 */
4488 if (varp == (char_u *)&p_kp
4489 && (*arg == NUL || *arg == ' '))
4490 {
4491 STRCPY(errbuf, ":help");
4492 save_arg = arg;
4493 arg = errbuf;
4494 }
4495 /*
4496 * Convert 'whichwrap' number to string, for
4497 * backwards compatibility with Vim 3.0.
4498 * Misuse errbuf[] for the resulting string.
4499 */
4500 else if (varp == (char_u *)&p_ww
4501 && VIM_ISDIGIT(*arg))
4502 {
4503 *errbuf = NUL;
4504 i = getdigits(&arg);
4505 if (i & 1)
4506 STRCAT(errbuf, "b,");
4507 if (i & 2)
4508 STRCAT(errbuf, "s,");
4509 if (i & 4)
4510 STRCAT(errbuf, "h,l,");
4511 if (i & 8)
4512 STRCAT(errbuf, "<,>,");
4513 if (i & 16)
4514 STRCAT(errbuf, "[,],");
4515 if (*errbuf != NUL) /* remove trailing , */
4516 errbuf[STRLEN(errbuf) - 1] = NUL;
4517 save_arg = arg;
4518 arg = errbuf;
4519 }
4520 /*
4521 * Remove '>' before 'dir' and 'bdir', for
4522 * backwards compatibility with version 3.0
4523 */
4524 else if ( *arg == '>'
4525 && (varp == (char_u *)&p_dir
4526 || varp == (char_u *)&p_bdir))
4527 {
4528 ++arg;
4529 }
4530
4531 /* When setting the local value of a global
4532 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004533 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004534 && (opt_flags & OPT_LOCAL))
4535 origval = *(char_u **)get_varp(
4536 &options[opt_idx]);
4537 else
4538 origval = oldval;
4539
4540 /*
4541 * Copy the new string into allocated memory.
4542 * Can't use set_string_option_direct(), because
4543 * we need to remove the backslashes.
4544 */
4545 /* get a bit too much */
4546 newlen = (unsigned)STRLEN(arg) + 1;
4547 if (adding || prepending || removing)
4548 newlen += (unsigned)STRLEN(origval) + 1;
4549 newval = alloc(newlen);
4550 if (newval == NULL) /* out of mem, don't change */
4551 break;
4552 s = newval;
4553
4554 /*
4555 * Copy the string, skip over escaped chars.
4556 * For MS-DOS and WIN32 backslashes before normal
4557 * file name characters are not removed, and keep
4558 * backslash at start, for "\\machine\path", but
4559 * do remove it for "\\\\machine\\path".
4560 * The reverse is found in ExpandOldSetting().
4561 */
4562 while (*arg && !vim_iswhite(*arg))
4563 {
4564 if (*arg == '\\' && arg[1] != NUL
4565#ifdef BACKSLASH_IN_FILENAME
4566 && !((flags & P_EXPAND)
4567 && vim_isfilec(arg[1])
4568 && (arg[1] != '\\'
4569 || (s == newval
4570 && arg[2] != '\\')))
4571#endif
4572 )
4573 ++arg; /* remove backslash */
4574#ifdef FEAT_MBYTE
4575 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004576 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004577 {
4578 /* copy multibyte char */
4579 mch_memmove(s, arg, (size_t)i);
4580 arg += i;
4581 s += i;
4582 }
4583 else
4584#endif
4585 *s++ = *arg++;
4586 }
4587 *s = NUL;
4588
4589 /*
4590 * Expand environment variables and ~.
4591 * Don't do it when adding without inserting a
4592 * comma.
4593 */
4594 if (!(adding || prepending || removing)
4595 || (flags & P_COMMA))
4596 {
4597 s = option_expand(opt_idx, newval);
4598 if (s != NULL)
4599 {
4600 vim_free(newval);
4601 newlen = (unsigned)STRLEN(s) + 1;
4602 if (adding || prepending || removing)
4603 newlen += (unsigned)STRLEN(origval) + 1;
4604 newval = alloc(newlen);
4605 if (newval == NULL)
4606 break;
4607 STRCPY(newval, s);
4608 }
4609 }
4610
4611 /* locate newval[] in origval[] when removing it
4612 * and when adding to avoid duplicates */
4613 i = 0; /* init for GCC */
4614 if (removing || (flags & P_NODUP))
4615 {
4616 i = (int)STRLEN(newval);
4617 bs = 0;
4618 for (s = origval; *s; ++s)
4619 {
4620 if ((!(flags & P_COMMA)
4621 || s == origval
4622 || (s[-1] == ',' && !(bs & 1)))
4623 && STRNCMP(s, newval, i) == 0
4624 && (!(flags & P_COMMA)
4625 || s[i] == ','
4626 || s[i] == NUL))
4627 break;
4628 /* Count backspaces. Only a comma with an
4629 * even number of backspaces before it is
4630 * recognized as a separator */
4631 if (s > origval && s[-1] == '\\')
4632 ++bs;
4633 else
4634 bs = 0;
4635 }
4636
4637 /* do not add if already there */
4638 if ((adding || prepending) && *s)
4639 {
4640 prepending = FALSE;
4641 adding = FALSE;
4642 STRCPY(newval, origval);
4643 }
4644 }
4645
4646 /* concatenate the two strings; add a ',' if
4647 * needed */
4648 if (adding || prepending)
4649 {
4650 comma = ((flags & P_COMMA) && *origval != NUL
4651 && *newval != NUL);
4652 if (adding)
4653 {
4654 i = (int)STRLEN(origval);
4655 mch_memmove(newval + i + comma, newval,
4656 STRLEN(newval) + 1);
4657 mch_memmove(newval, origval, (size_t)i);
4658 }
4659 else
4660 {
4661 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004662 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004663 }
4664 if (comma)
4665 newval[i] = ',';
4666 }
4667
4668 /* Remove newval[] from origval[]. (Note: "i" has
4669 * been set above and is used here). */
4670 if (removing)
4671 {
4672 STRCPY(newval, origval);
4673 if (*s)
4674 {
4675 /* may need to remove a comma */
4676 if (flags & P_COMMA)
4677 {
4678 if (s == origval)
4679 {
4680 /* include comma after string */
4681 if (s[i] == ',')
4682 ++i;
4683 }
4684 else
4685 {
4686 /* include comma before string */
4687 --s;
4688 ++i;
4689 }
4690 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004691 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004692 }
4693 }
4694
4695 if (flags & P_FLAGLIST)
4696 {
4697 /* Remove flags that appear twice. */
4698 for (s = newval; *s; ++s)
4699 if ((!(flags & P_COMMA) || *s != ',')
4700 && vim_strchr(s + 1, *s) != NULL)
4701 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004702 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703 --s;
4704 }
4705 }
4706
4707 if (save_arg != NULL) /* number for 'whichwrap' */
4708 arg = save_arg;
4709 new_value_alloced = TRUE;
4710 }
4711
4712 /* Set the new value. */
4713 *(char_u **)(varp) = newval;
4714
4715 /* Handle side effects, and set the global value for
4716 * ":set" on local options. */
4717 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4718 new_value_alloced, oldval, errbuf, opt_flags);
4719
4720 /* If error detected, print the error message. */
4721 if (errmsg != NULL)
4722 goto skip;
4723 }
4724 else /* key code option */
4725 {
4726 char_u *p;
4727
4728 if (nextchar == '&')
4729 {
4730 if (add_termcap_entry(key_name, TRUE) == FAIL)
4731 errmsg = (char_u *)N_("E522: Not found in termcap");
4732 }
4733 else
4734 {
4735 ++arg; /* jump to after the '=' or ':' */
4736 for (p = arg; *p && !vim_iswhite(*p); ++p)
4737 if (*p == '\\' && p[1] != NUL)
4738 ++p;
4739 nextchar = *p;
4740 *p = NUL;
4741 add_termcode(key_name, arg, FALSE);
4742 *p = nextchar;
4743 }
4744 if (full_screen)
4745 ttest(FALSE);
4746 redraw_all_later(CLEAR);
4747 }
4748 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004749
Bram Moolenaar071d4272004-06-13 20:20:40 +00004750 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004751 did_set_option(opt_idx, opt_flags,
4752 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 }
4754
4755skip:
4756 /*
4757 * Advance to next argument.
4758 * - skip until a blank found, taking care of backslashes
4759 * - skip blanks
4760 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4761 */
4762 for (i = 0; i < 2 ; ++i)
4763 {
4764 while (*arg != NUL && !vim_iswhite(*arg))
4765 if (*arg++ == '\\' && *arg != NUL)
4766 ++arg;
4767 arg = skipwhite(arg);
4768 if (*arg != '=')
4769 break;
4770 }
4771 }
4772
4773 if (errmsg != NULL)
4774 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004775 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004776 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004777 if (i + (arg - startarg) < IOSIZE)
4778 {
4779 /* append the argument with the error */
4780 STRCAT(IObuff, ": ");
4781 mch_memmove(IObuff + i, startarg, (arg - startarg));
4782 IObuff[i + (arg - startarg)] = NUL;
4783 }
4784 /* make sure all characters are printable */
4785 trans_characters(IObuff, IOSIZE);
4786
4787 ++no_wait_return; /* wait_return done later */
4788 emsg(IObuff); /* show error highlighted */
4789 --no_wait_return;
4790
4791 return FAIL;
4792 }
4793
4794 arg = skipwhite(arg);
4795 }
4796
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004797theend:
4798 if (silent_mode && did_show)
4799 {
4800 /* After displaying option values in silent mode. */
4801 silent_mode = FALSE;
4802 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4803 msg_putchar('\n');
4804 cursor_on(); /* msg_start() switches it off */
4805 out_flush();
4806 silent_mode = TRUE;
4807 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4808 }
4809
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 return OK;
4811}
4812
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004813/*
4814 * Call this when an option has been given a new value through a user command.
4815 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4816 */
4817 static void
4818did_set_option(opt_idx, opt_flags, new_value)
4819 int opt_idx;
4820 int opt_flags; /* possibly with OPT_MODELINE */
4821 int new_value; /* value was replaced completely */
4822{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004823 long_u *p;
4824
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004825 options[opt_idx].flags |= P_WAS_SET;
4826
4827 /* When an option is set in the sandbox, from a modeline or in secure mode
4828 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004829 * flag. */
4830 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004831 if (secure
4832#ifdef HAVE_SANDBOX
4833 || sandbox != 0
4834#endif
4835 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004836 *p = *p | P_INSECURE;
4837 else if (new_value)
4838 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004839}
4840
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 static char_u *
4842illegal_char(errbuf, c)
4843 char_u *errbuf;
4844 int c;
4845{
4846 if (errbuf == NULL)
4847 return (char_u *)"";
4848 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004849 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004850 return errbuf;
4851}
4852
4853/*
4854 * Convert a key name or string into a key value.
4855 * Used for 'wildchar' and 'cedit' options.
4856 */
4857 static int
4858string_to_key(arg)
4859 char_u *arg;
4860{
4861 if (*arg == '<')
4862 return find_key_option(arg + 1);
4863 if (*arg == '^')
4864 return Ctrl_chr(arg[1]);
4865 return *arg;
4866}
4867
4868#ifdef FEAT_CMDWIN
4869/*
4870 * Check value of 'cedit' and set cedit_key.
4871 * Returns NULL if value is OK, error message otherwise.
4872 */
4873 static char_u *
4874check_cedit()
4875{
4876 int n;
4877
4878 if (*p_cedit == NUL)
4879 cedit_key = -1;
4880 else
4881 {
4882 n = string_to_key(p_cedit);
4883 if (vim_isprintc(n))
4884 return e_invarg;
4885 cedit_key = n;
4886 }
4887 return NULL;
4888}
4889#endif
4890
4891#ifdef FEAT_TITLE
4892/*
4893 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4894 * maketitle() to create and display it.
4895 * When switching the title or icon off, call mch_restore_title() to get
4896 * the old value back.
4897 */
4898 static void
4899did_set_title(icon)
4900 int icon; /* Did set icon instead of title */
4901{
4902 if (starting != NO_SCREEN
4903#ifdef FEAT_GUI
4904 && !gui.starting
4905#endif
4906 )
4907 {
4908 maketitle();
4909 if (icon)
4910 {
4911 if (!p_icon)
4912 mch_restore_title(2);
4913 }
4914 else
4915 {
4916 if (!p_title)
4917 mch_restore_title(1);
4918 }
4919 }
4920}
4921#endif
4922
4923/*
4924 * set_options_bin - called when 'bin' changes value.
4925 */
4926 void
4927set_options_bin(oldval, newval, opt_flags)
4928 int oldval;
4929 int newval;
4930 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4931{
4932 /*
4933 * The option values that are changed when 'bin' changes are
4934 * copied when 'bin is set and restored when 'bin' is reset.
4935 */
4936 if (newval)
4937 {
4938 if (!oldval) /* switched on */
4939 {
4940 if (!(opt_flags & OPT_GLOBAL))
4941 {
4942 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4943 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4944 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4945 curbuf->b_p_et_nobin = curbuf->b_p_et;
4946 }
4947 if (!(opt_flags & OPT_LOCAL))
4948 {
4949 p_tw_nobin = p_tw;
4950 p_wm_nobin = p_wm;
4951 p_ml_nobin = p_ml;
4952 p_et_nobin = p_et;
4953 }
4954 }
4955
4956 if (!(opt_flags & OPT_GLOBAL))
4957 {
4958 curbuf->b_p_tw = 0; /* no automatic line wrap */
4959 curbuf->b_p_wm = 0; /* no automatic line wrap */
4960 curbuf->b_p_ml = 0; /* no modelines */
4961 curbuf->b_p_et = 0; /* no expandtab */
4962 }
4963 if (!(opt_flags & OPT_LOCAL))
4964 {
4965 p_tw = 0;
4966 p_wm = 0;
4967 p_ml = FALSE;
4968 p_et = FALSE;
4969 p_bin = TRUE; /* needed when called for the "-b" argument */
4970 }
4971 }
4972 else if (oldval) /* switched off */
4973 {
4974 if (!(opt_flags & OPT_GLOBAL))
4975 {
4976 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4977 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4978 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4979 curbuf->b_p_et = curbuf->b_p_et_nobin;
4980 }
4981 if (!(opt_flags & OPT_LOCAL))
4982 {
4983 p_tw = p_tw_nobin;
4984 p_wm = p_wm_nobin;
4985 p_ml = p_ml_nobin;
4986 p_et = p_et_nobin;
4987 }
4988 }
4989}
4990
4991#ifdef FEAT_VIMINFO
4992/*
4993 * Find the parameter represented by the given character (eg ', :, ", or /),
4994 * and return its associated value in the 'viminfo' string.
4995 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004996 * If the parameter is not specified in the string or there is no following
4997 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 */
4999 int
5000get_viminfo_parameter(type)
5001 int type;
5002{
5003 char_u *p;
5004
5005 p = find_viminfo_parameter(type);
5006 if (p != NULL && VIM_ISDIGIT(*p))
5007 return atoi((char *)p);
5008 return -1;
5009}
5010
5011/*
5012 * Find the parameter represented by the given character (eg ''', ':', '"', or
5013 * '/') in the 'viminfo' option and return a pointer to the string after it.
5014 * Return NULL if the parameter is not specified in the string.
5015 */
5016 char_u *
5017find_viminfo_parameter(type)
5018 int type;
5019{
5020 char_u *p;
5021
5022 for (p = p_viminfo; *p; ++p)
5023 {
5024 if (*p == type)
5025 return p + 1;
5026 if (*p == 'n') /* 'n' is always the last one */
5027 break;
5028 p = vim_strchr(p, ','); /* skip until next ',' */
5029 if (p == NULL) /* hit the end without finding parameter */
5030 break;
5031 }
5032 return NULL;
5033}
5034#endif
5035
5036/*
5037 * Expand environment variables for some string options.
5038 * These string options cannot be indirect!
5039 * If "val" is NULL expand the current value of the option.
5040 * Return pointer to NameBuff, or NULL when not expanded.
5041 */
5042 static char_u *
5043option_expand(opt_idx, val)
5044 int opt_idx;
5045 char_u *val;
5046{
5047 /* if option doesn't need expansion nothing to do */
5048 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5049 return NULL;
5050
5051 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5052 * expand_env() would truncate the string. */
5053 if (val != NULL && STRLEN(val) > MAXPATHL)
5054 return NULL;
5055
5056 if (val == NULL)
5057 val = *(char_u **)options[opt_idx].var;
5058
5059 /*
5060 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5061 * Escape spaces when expanding 'tags', they are used to separate file
5062 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005063 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 */
5065 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005066 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005067#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005068 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5069#endif
5070 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005071 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5072 return NULL;
5073
5074 return NameBuff;
5075}
5076
5077/*
5078 * After setting various option values: recompute variables that depend on
5079 * option values.
5080 */
5081 static void
5082didset_options()
5083{
5084 /* initialize the table for 'iskeyword' et.al. */
5085 (void)init_chartab();
5086
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005087#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5091#ifdef FEAT_SESSION
5092 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5093 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5094#endif
5095#ifdef FEAT_FOLDING
5096 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5097#endif
5098 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5099#ifdef FEAT_VIRTUALEDIT
5100 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5101#endif
5102#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5103 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5104#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005105#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005106 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005107 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005108 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005110#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5111 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5112#endif
5113#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5114 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5115#endif
5116#ifdef FEAT_CMDWIN
5117 /* set cedit_key */
5118 (void)check_cedit();
5119#endif
5120}
5121
5122/*
5123 * Check for string options that are NULL (normally only termcap options).
5124 */
5125 void
5126check_options()
5127{
5128 int opt_idx;
5129
5130 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5131 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5132 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5133}
5134
5135/*
5136 * Check string options in a buffer for NULL value.
5137 */
5138 void
5139check_buf_options(buf)
5140 buf_T *buf;
5141{
5142#if defined(FEAT_QUICKFIX)
5143 check_string_option(&buf->b_p_bh);
5144 check_string_option(&buf->b_p_bt);
5145#endif
5146#ifdef FEAT_MBYTE
5147 check_string_option(&buf->b_p_fenc);
5148#endif
5149 check_string_option(&buf->b_p_ff);
5150#ifdef FEAT_FIND_ID
5151 check_string_option(&buf->b_p_def);
5152 check_string_option(&buf->b_p_inc);
5153# ifdef FEAT_EVAL
5154 check_string_option(&buf->b_p_inex);
5155# endif
5156#endif
5157#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5158 check_string_option(&buf->b_p_inde);
5159 check_string_option(&buf->b_p_indk);
5160#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005161#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5162 check_string_option(&buf->b_p_bexpr);
5163#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005164#if defined(FEAT_EVAL)
5165 check_string_option(&buf->b_p_fex);
5166#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167#ifdef FEAT_CRYPT
5168 check_string_option(&buf->b_p_key);
5169#endif
5170 check_string_option(&buf->b_p_kp);
5171 check_string_option(&buf->b_p_mps);
5172 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005173 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005174 check_string_option(&buf->b_p_isk);
5175#ifdef FEAT_COMMENTS
5176 check_string_option(&buf->b_p_com);
5177#endif
5178#ifdef FEAT_FOLDING
5179 check_string_option(&buf->b_p_cms);
5180#endif
5181 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005182#ifdef FEAT_TEXTOBJ
5183 check_string_option(&buf->b_p_qe);
5184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185#ifdef FEAT_SYN_HL
5186 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005187#endif
5188#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005189 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005190 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005191 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192#endif
5193#ifdef FEAT_SEARCHPATH
5194 check_string_option(&buf->b_p_sua);
5195#endif
5196#ifdef FEAT_CINDENT
5197 check_string_option(&buf->b_p_cink);
5198 check_string_option(&buf->b_p_cino);
5199#endif
5200#ifdef FEAT_AUTOCMD
5201 check_string_option(&buf->b_p_ft);
5202#endif
5203#ifdef FEAT_OSFILETYPE
5204 check_string_option(&buf->b_p_oft);
5205#endif
5206#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5207 check_string_option(&buf->b_p_cinw);
5208#endif
5209#ifdef FEAT_INS_EXPAND
5210 check_string_option(&buf->b_p_cpt);
5211#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005212#ifdef FEAT_COMPL_FUNC
5213 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005214 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005216#ifdef FEAT_KEYMAP
5217 check_string_option(&buf->b_p_keymap);
5218#endif
5219#ifdef FEAT_QUICKFIX
5220 check_string_option(&buf->b_p_gp);
5221 check_string_option(&buf->b_p_mp);
5222 check_string_option(&buf->b_p_efm);
5223#endif
5224 check_string_option(&buf->b_p_ep);
5225 check_string_option(&buf->b_p_path);
5226 check_string_option(&buf->b_p_tags);
5227#ifdef FEAT_INS_EXPAND
5228 check_string_option(&buf->b_p_dict);
5229 check_string_option(&buf->b_p_tsr);
5230#endif
5231}
5232
5233/*
5234 * Free the string allocated for an option.
5235 * Checks for the string being empty_option. This may happen if we're out of
5236 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5237 * check_options().
5238 * Does NOT check for P_ALLOCED flag!
5239 */
5240 void
5241free_string_option(p)
5242 char_u *p;
5243{
5244 if (p != empty_option)
5245 vim_free(p);
5246}
5247
5248 void
5249clear_string_option(pp)
5250 char_u **pp;
5251{
5252 if (*pp != empty_option)
5253 vim_free(*pp);
5254 *pp = empty_option;
5255}
5256
5257 static void
5258check_string_option(pp)
5259 char_u **pp;
5260{
5261 if (*pp == NULL)
5262 *pp = empty_option;
5263}
5264
5265/*
5266 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5267 */
5268 void
5269set_term_option_alloced(p)
5270 char_u **p;
5271{
5272 int opt_idx;
5273
5274 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5275 if (options[opt_idx].var == (char_u *)p)
5276 {
5277 options[opt_idx].flags |= P_ALLOCED;
5278 return;
5279 }
5280 return; /* cannot happen: didn't find it! */
5281}
5282
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005283#if defined(FEAT_EVAL) || defined(PROTO)
5284/*
5285 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5286 * Return FALSE when it wasn't.
5287 * Return -1 for an unknown option.
5288 */
5289 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005290was_set_insecurely(opt, opt_flags)
5291 char_u *opt;
5292 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005293{
5294 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005295 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296
5297 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005298 {
5299 flagp = insecure_flag(idx, opt_flags);
5300 return (*flagp & P_INSECURE) != 0;
5301 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005302 EMSG2(_(e_intern2), "was_set_insecurely()");
5303 return -1;
5304}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005305
5306/*
5307 * Get a pointer to the flags used for the P_INSECURE flag of option
5308 * "opt_idx". For some local options a local flags field is used.
5309 */
5310 static long_u *
5311insecure_flag(opt_idx, opt_flags)
5312 int opt_idx;
5313 int opt_flags;
5314{
5315 if (opt_flags & OPT_LOCAL)
5316 switch ((int)options[opt_idx].indir)
5317 {
5318#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005319 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005320#endif
5321#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005322# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005323 case PV_FDE: return &curwin->w_p_fde_flags;
5324 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005325# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005326# ifdef FEAT_BEVAL
5327 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5328# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005329# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005330 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005331# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005332 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005333# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005334 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005335# endif
5336#endif
5337 }
5338
5339 /* Nothing special, return global flags field. */
5340 return &options[opt_idx].flags;
5341}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005342#endif
5343
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005344#ifdef FEAT_TITLE
5345static void redraw_titles __ARGS((void));
5346
5347/*
5348 * Redraw the window title and/or tab page text later.
5349 */
5350static void redraw_titles()
5351{
5352 need_maketitle = TRUE;
5353# ifdef FEAT_WINDOWS
5354 redraw_tabline = TRUE;
5355# endif
5356}
5357#endif
5358
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359/*
5360 * Set a string option to a new value (without checking the effect).
5361 * The string is copied into allocated memory.
5362 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005363 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005364 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 */
5366 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005367set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368 char_u *name;
5369 int opt_idx;
5370 char_u *val;
5371 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005372 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373{
5374 char_u *s;
5375 char_u **varp;
5376 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005377 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378
Bram Moolenaar89d40322006-08-29 15:30:07 +00005379 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005381 idx = findoption(name);
5382 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005383 {
5384 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 }
5388
Bram Moolenaar89d40322006-08-29 15:30:07 +00005389 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005390 return;
5391
5392 s = vim_strsave(val);
5393 if (s != NULL)
5394 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005395 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005397 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398 free_string_option(*varp);
5399 *varp = s;
5400
5401 /* For buffer/window local option may also set the global value. */
5402 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005403 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404
Bram Moolenaar89d40322006-08-29 15:30:07 +00005405 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406
5407 /* When setting both values of a global option with a local value,
5408 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005409 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005410 {
5411 free_string_option(*varp);
5412 *varp = empty_option;
5413 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005414# ifdef FEAT_EVAL
5415 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005416 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005417 set_sid == 0 ? current_SID : set_sid);
5418# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419 }
5420}
5421
5422/*
5423 * Set global value for string option when it's a local option.
5424 */
5425 static void
5426set_string_option_global(opt_idx, varp)
5427 int opt_idx; /* option index */
5428 char_u **varp; /* pointer to option variable */
5429{
5430 char_u **p, *s;
5431
5432 /* the global value is always allocated */
5433 if (options[opt_idx].var == VAR_WIN)
5434 p = (char_u **)GLOBAL_WO(varp);
5435 else
5436 p = (char_u **)options[opt_idx].var;
5437 if (options[opt_idx].indir != PV_NONE
5438 && p != varp
5439 && (s = vim_strsave(*varp)) != NULL)
5440 {
5441 free_string_option(*p);
5442 *p = s;
5443 }
5444}
5445
5446/*
5447 * Set a string option to a new value, and handle the effects.
5448 */
5449 static void
5450set_string_option(opt_idx, value, opt_flags)
5451 int opt_idx;
5452 char_u *value;
5453 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5454{
5455 char_u *s;
5456 char_u **varp;
5457 char_u *oldval;
5458
5459 if (options[opt_idx].var == NULL) /* don't set hidden option */
5460 return;
5461
5462 s = vim_strsave(value);
5463 if (s != NULL)
5464 {
5465 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5466 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005467 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468 ? OPT_GLOBAL : OPT_LOCAL)
5469 : opt_flags);
5470 oldval = *varp;
5471 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005472 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5473 opt_flags) == NULL)
5474 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475 }
5476}
5477
5478/*
5479 * Handle string options that need some action to perform when changed.
5480 * Returns NULL for success, or an error message for an error.
5481 */
5482 static char_u *
5483did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5484 opt_flags)
5485 int opt_idx; /* index in options[] table */
5486 char_u **varp; /* pointer to the option variable */
5487 int new_value_alloced; /* new value was allocated */
5488 char_u *oldval; /* previous value of the option */
5489 char_u *errbuf; /* buffer for errors, or NULL */
5490 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5491{
5492 char_u *errmsg = NULL;
5493 char_u *s, *p;
5494 int did_chartab = FALSE;
5495 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005496 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005497#ifdef FEAT_GUI
5498 /* set when changing an option that only requires a redraw in the GUI */
5499 int redraw_gui_only = FALSE;
5500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501
5502 /* Get the global option to compare with, otherwise we would have to check
5503 * two values for all local options. */
5504 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5505
5506 /* Disallow changing some options from secure mode */
5507 if ((secure
5508#ifdef HAVE_SANDBOX
5509 || sandbox != 0
5510#endif
5511 ) && (options[opt_idx].flags & P_SECURE))
5512 {
5513 errmsg = e_secure;
5514 }
5515
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005516 /* Check for a "normal" file name in some options. Disallow a path
5517 * separator (slash and/or backslash), wildcards and characters that are
5518 * often illegal in a file name. */
5519 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005520 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005521 {
5522 errmsg = e_invarg;
5523 }
5524
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525 /* 'term' */
5526 else if (varp == &T_NAME)
5527 {
5528 if (T_NAME[0] == NUL)
5529 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5530#ifdef FEAT_GUI
5531 if (gui.in_use)
5532 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5533 else if (term_is_gui(T_NAME))
5534 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5535#endif
5536 else if (set_termname(T_NAME) == FAIL)
5537 errmsg = (char_u *)N_("E522: Not found in termcap");
5538 else
5539 /* Screen colors may have changed. */
5540 redraw_later_clear();
5541 }
5542
5543 /* 'backupcopy' */
5544 else if (varp == &p_bkc)
5545 {
5546 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5547 errmsg = e_invarg;
5548 if (((bkc_flags & BKC_AUTO) != 0)
5549 + ((bkc_flags & BKC_YES) != 0)
5550 + ((bkc_flags & BKC_NO) != 0) != 1)
5551 {
5552 /* Must have exactly one of "auto", "yes" and "no". */
5553 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5554 errmsg = e_invarg;
5555 }
5556 }
5557
5558 /* 'backupext' and 'patchmode' */
5559 else if (varp == &p_bex || varp == &p_pm)
5560 {
5561 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5562 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5563 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5564 }
5565
5566 /*
5567 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5568 * If the new option is invalid, use old value. 'lisp' option: refill
5569 * chartab[] for '-' char
5570 */
5571 else if ( varp == &p_isi
5572 || varp == &(curbuf->b_p_isk)
5573 || varp == &p_isp
5574 || varp == &p_isf)
5575 {
5576 if (init_chartab() == FAIL)
5577 {
5578 did_chartab = TRUE; /* need to restore it below */
5579 errmsg = e_invarg; /* error in value */
5580 }
5581 }
5582
5583 /* 'helpfile' */
5584 else if (varp == &p_hf)
5585 {
5586 /* May compute new values for $VIM and $VIMRUNTIME */
5587 if (didset_vim)
5588 {
5589 vim_setenv((char_u *)"VIM", (char_u *)"");
5590 didset_vim = FALSE;
5591 }
5592 if (didset_vimruntime)
5593 {
5594 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5595 didset_vimruntime = FALSE;
5596 }
5597 }
5598
5599#ifdef FEAT_MULTI_LANG
5600 /* 'helplang' */
5601 else if (varp == &p_hlg)
5602 {
5603 /* Check for "", "ab", "ab,cd", etc. */
5604 for (s = p_hlg; *s != NUL; s += 3)
5605 {
5606 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5607 {
5608 errmsg = e_invarg;
5609 break;
5610 }
5611 if (s[2] == NUL)
5612 break;
5613 }
5614 }
5615#endif
5616
5617 /* 'highlight' */
5618 else if (varp == &p_hl)
5619 {
5620 if (highlight_changed() == FAIL)
5621 errmsg = e_invarg; /* invalid flags */
5622 }
5623
5624 /* 'nrformats' */
5625 else if (gvarp == &p_nf)
5626 {
5627 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5628 errmsg = e_invarg;
5629 }
5630
5631#ifdef FEAT_SESSION
5632 /* 'sessionoptions' */
5633 else if (varp == &p_ssop)
5634 {
5635 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5636 errmsg = e_invarg;
5637 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5638 {
5639 /* Don't allow both "sesdir" and "curdir". */
5640 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5641 errmsg = e_invarg;
5642 }
5643 }
5644 /* 'viewoptions' */
5645 else if (varp == &p_vop)
5646 {
5647 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5648 errmsg = e_invarg;
5649 }
5650#endif
5651
5652 /* 'scrollopt' */
5653#ifdef FEAT_SCROLLBIND
5654 else if (varp == &p_sbo)
5655 {
5656 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5657 errmsg = e_invarg;
5658 }
5659#endif
5660
5661 /* 'ambiwidth' */
5662#ifdef FEAT_MBYTE
5663 else if (varp == &p_ambw)
5664 {
5665 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5666 errmsg = e_invarg;
5667 }
5668#endif
5669
5670 /* 'background' */
5671 else if (varp == &p_bg)
5672 {
5673 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5674 {
5675#ifdef FEAT_EVAL
5676 int dark = (*p_bg == 'd');
5677#endif
5678
5679 init_highlight(FALSE, FALSE);
5680
5681#ifdef FEAT_EVAL
5682 if (dark != (*p_bg == 'd')
5683 && get_var_value((char_u *)"g:colors_name") != NULL)
5684 {
5685 /* The color scheme must have set 'background' back to another
5686 * value, that's not what we want here. Disable the color
5687 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005688 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 free_string_option(p_bg);
5690 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5691 check_string_option(&p_bg);
5692 init_highlight(FALSE, FALSE);
5693 }
5694#endif
5695 }
5696 else
5697 errmsg = e_invarg;
5698 }
5699
5700 /* 'wildmode' */
5701 else if (varp == &p_wim)
5702 {
5703 if (check_opt_wim() == FAIL)
5704 errmsg = e_invarg;
5705 }
5706
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005707#ifdef FEAT_CMDL_COMPL
5708 /* 'wildoptions' */
5709 else if (varp == &p_wop)
5710 {
5711 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5712 errmsg = e_invarg;
5713 }
5714#endif
5715
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716#ifdef FEAT_WAK
5717 /* 'winaltkeys' */
5718 else if (varp == &p_wak)
5719 {
5720 if (*p_wak == NUL
5721 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5722 errmsg = e_invarg;
5723# ifdef FEAT_MENU
5724# ifdef FEAT_GUI_MOTIF
5725 else if (gui.in_use)
5726 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5727# else
5728# ifdef FEAT_GUI_GTK
5729 else if (gui.in_use)
5730 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5731# endif
5732# endif
5733# endif
5734 }
5735#endif
5736
5737#ifdef FEAT_AUTOCMD
5738 /* 'eventignore' */
5739 else if (varp == &p_ei)
5740 {
5741 if (check_ei() == FAIL)
5742 errmsg = e_invarg;
5743 }
5744#endif
5745
5746#ifdef FEAT_MBYTE
5747 /* 'encoding' and 'fileencoding' */
5748 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5749 {
5750 if (gvarp == &p_fenc)
5751 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005752 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 errmsg = e_modifiable;
5754 else if (vim_strchr(*varp, ',') != NULL)
5755 /* No comma allowed in 'fileencoding'; catches confusing it
5756 * with 'fileencodings'. */
5757 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005759 {
5760# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005762 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005764 /* Add 'fileencoding' to the swap file. */
5765 ml_setflags(curbuf);
5766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767 }
5768 if (errmsg == NULL)
5769 {
5770 /* canonize the value, so that STRCMP() can be used on it */
5771 p = enc_canonize(*varp);
5772 if (p != NULL)
5773 {
5774 vim_free(*varp);
5775 *varp = p;
5776 }
5777 if (varp == &p_enc)
5778 {
5779 errmsg = mb_init();
5780# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005781 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782# endif
5783 }
5784 }
5785
5786# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5787 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5788 {
5789 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5790 if (STRCMP(p_tenc, "utf-8") != 0)
5791 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5792 }
5793# endif
5794
5795 if (errmsg == NULL)
5796 {
5797# ifdef FEAT_KEYMAP
5798 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5799 * (with another encoding). */
5800 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5801 (void)keymap_init();
5802# endif
5803
5804 /* When 'termencoding' is not empty and 'encoding' changes or when
5805 * 'termencoding' changes, need to setup for keyboard input and
5806 * display output conversion. */
5807 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5808 {
5809 convert_setup(&input_conv, p_tenc, p_enc);
5810 convert_setup(&output_conv, p_enc, p_tenc);
5811 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005812
5813# if defined(WIN3264) && defined(FEAT_MBYTE)
5814 /* $HOME may have characters in active code page. */
5815 if (varp == &p_enc)
5816 init_homedir();
5817# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818 }
5819 }
5820#endif
5821
5822#if defined(FEAT_POSTSCRIPT)
5823 else if (varp == &p_penc)
5824 {
5825 /* Canonize printencoding if VIM standard one */
5826 p = enc_canonize(p_penc);
5827 if (p != NULL)
5828 {
5829 vim_free(p_penc);
5830 p_penc = p;
5831 }
5832 else
5833 {
5834 /* Ensure lower case and '-' for '_' */
5835 for (s = p_penc; *s != NUL; s++)
5836 {
5837 if (*s == '_')
5838 *s = '-';
5839 else
5840 *s = TOLOWER_ASC(*s);
5841 }
5842 }
5843 }
5844#endif
5845
Bram Moolenaar9372a112005-12-06 19:59:18 +00005846#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 else if (varp == &p_imak)
5848 {
5849 if (gui.in_use && !im_xim_isvalid_imactivate())
5850 errmsg = e_invarg;
5851 }
5852#endif
5853
5854#ifdef FEAT_KEYMAP
5855 else if (varp == &curbuf->b_p_keymap)
5856 {
5857 /* load or unload key mapping tables */
5858 errmsg = keymap_init();
5859
Bram Moolenaarfab06232009-03-04 03:13:35 +00005860 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005862 if (*curbuf->b_p_keymap != NUL)
5863 {
5864 /* Installed a new keymap, switch on using it. */
5865 curbuf->b_p_iminsert = B_IMODE_LMAP;
5866 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5867 curbuf->b_p_imsearch = B_IMODE_LMAP;
5868 }
5869 else
5870 {
5871 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5872 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5873 curbuf->b_p_iminsert = B_IMODE_NONE;
5874 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5875 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5876 }
5877 if ((opt_flags & OPT_LOCAL) == 0)
5878 {
5879 set_iminsert_global();
5880 set_imsearch_global();
5881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882# ifdef FEAT_WINDOWS
5883 status_redraw_curbuf();
5884# endif
5885 }
5886 }
5887#endif
5888
5889 /* 'fileformat' */
5890 else if (gvarp == &p_ff)
5891 {
5892 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5893 errmsg = e_modifiable;
5894 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5895 errmsg = e_invarg;
5896 else
5897 {
5898 /* may also change 'textmode' */
5899 if (get_fileformat(curbuf) == EOL_DOS)
5900 curbuf->b_p_tx = TRUE;
5901 else
5902 curbuf->b_p_tx = FALSE;
5903#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005904 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005906 /* update flag in swap file */
5907 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005908 /* Redraw needed when switching to/from "mac": a CR in the text
5909 * will be displayed differently. */
5910 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5911 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 }
5913 }
5914
5915 /* 'fileformats' */
5916 else if (varp == &p_ffs)
5917 {
5918 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5919 errmsg = e_invarg;
5920 else
5921 {
5922 /* also change 'textauto' */
5923 if (*p_ffs == NUL)
5924 p_ta = FALSE;
5925 else
5926 p_ta = TRUE;
5927 }
5928 }
5929
5930#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5931 /* 'cryptkey' */
5932 else if (gvarp == &p_key)
5933 {
5934 /* Make sure the ":set" command doesn't show the new value in the
5935 * history. */
5936 remove_key_from_history();
5937 }
5938#endif
5939
5940 /* 'matchpairs' */
5941 else if (gvarp == &p_mps)
5942 {
5943 /* Check for "x:y,x:y" */
5944 for (p = *varp; *p != NUL; p += 4)
5945 {
5946 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5947 {
5948 errmsg = e_invarg;
5949 break;
5950 }
5951 if (p[3] == NUL)
5952 break;
5953 }
5954 }
5955
5956#ifdef FEAT_COMMENTS
5957 /* 'comments' */
5958 else if (gvarp == &p_com)
5959 {
5960 for (s = *varp; *s; )
5961 {
5962 while (*s && *s != ':')
5963 {
5964 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5965 && !VIM_ISDIGIT(*s) && *s != '-')
5966 {
5967 errmsg = illegal_char(errbuf, *s);
5968 break;
5969 }
5970 ++s;
5971 }
5972 if (*s++ == NUL)
5973 errmsg = (char_u *)N_("E524: Missing colon");
5974 else if (*s == ',' || *s == NUL)
5975 errmsg = (char_u *)N_("E525: Zero length string");
5976 if (errmsg != NULL)
5977 break;
5978 while (*s && *s != ',')
5979 {
5980 if (*s == '\\' && s[1] != NUL)
5981 ++s;
5982 ++s;
5983 }
5984 s = skip_to_option_part(s);
5985 }
5986 }
5987#endif
5988
5989 /* 'listchars' */
5990 else if (varp == &p_lcs)
5991 {
5992 errmsg = set_chars_option(varp);
5993 }
5994
5995#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5996 /* 'fillchars' */
5997 else if (varp == &p_fcs)
5998 {
5999 errmsg = set_chars_option(varp);
6000 }
6001#endif
6002
6003#ifdef FEAT_CMDWIN
6004 /* 'cedit' */
6005 else if (varp == &p_cedit)
6006 {
6007 errmsg = check_cedit();
6008 }
6009#endif
6010
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006011 /* 'verbosefile' */
6012 else if (varp == &p_vfile)
6013 {
6014 verbose_stop();
6015 if (*p_vfile != NUL && verbose_open() == FAIL)
6016 errmsg = e_invarg;
6017 }
6018
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019#ifdef FEAT_VIMINFO
6020 /* 'viminfo' */
6021 else if (varp == &p_viminfo)
6022 {
6023 for (s = p_viminfo; *s;)
6024 {
6025 /* Check it's a valid character */
6026 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6027 {
6028 errmsg = illegal_char(errbuf, *s);
6029 break;
6030 }
6031 if (*s == 'n') /* name is always last one */
6032 {
6033 break;
6034 }
6035 else if (*s == 'r') /* skip until next ',' */
6036 {
6037 while (*++s && *s != ',')
6038 ;
6039 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006040 else if (*s == '%')
6041 {
6042 /* optional number */
6043 while (vim_isdigit(*++s))
6044 ;
6045 }
6046 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 ++s; /* no extra chars */
6048 else /* must have a number */
6049 {
6050 while (vim_isdigit(*++s))
6051 ;
6052
6053 if (!VIM_ISDIGIT(*(s - 1)))
6054 {
6055 if (errbuf != NULL)
6056 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006057 sprintf((char *)errbuf,
6058 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059 transchar_byte(*(s - 1)));
6060 errmsg = errbuf;
6061 }
6062 else
6063 errmsg = (char_u *)"";
6064 break;
6065 }
6066 }
6067 if (*s == ',')
6068 ++s;
6069 else if (*s)
6070 {
6071 if (errbuf != NULL)
6072 errmsg = (char_u *)N_("E527: Missing comma");
6073 else
6074 errmsg = (char_u *)"";
6075 break;
6076 }
6077 }
6078 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6079 errmsg = (char_u *)N_("E528: Must specify a ' value");
6080 }
6081#endif /* FEAT_VIMINFO */
6082
6083 /* terminal options */
6084 else if (istermoption(&options[opt_idx]) && full_screen)
6085 {
6086 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6087 if (varp == &T_CCO)
6088 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006089 int colors = atoi((char *)T_CCO);
6090
6091 /* Only reinitialize colors if t_Co value has really changed to
6092 * avoid expensive reload of colorscheme if t_Co is set to the
6093 * same value multiple times. */
6094 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006096 t_colors = colors;
6097 if (t_colors <= 1)
6098 {
6099 if (new_value_alloced)
6100 vim_free(T_CCO);
6101 T_CCO = empty_option;
6102 }
6103 /* We now have a different color setup, initialize it again. */
6104 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 }
6107 ttest(FALSE);
6108 if (varp == &T_ME)
6109 {
6110 out_str(T_ME);
6111 redraw_later(CLEAR);
6112#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6113 /* Since t_me has been set, this probably means that the user
6114 * wants to use this as default colors. Need to reset default
6115 * background/foreground colors. */
6116 mch_set_normal_colors();
6117#endif
6118 }
6119 }
6120
6121#ifdef FEAT_LINEBREAK
6122 /* 'showbreak' */
6123 else if (varp == &p_sbr)
6124 {
6125 for (s = p_sbr; *s; )
6126 {
6127 if (ptr2cells(s) != 1)
6128 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006129 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 }
6131 }
6132#endif
6133
6134#ifdef FEAT_GUI
6135 /* 'guifont' */
6136 else if (varp == &p_guifont)
6137 {
6138 if (gui.in_use)
6139 {
6140 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006141# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 /*
6143 * Put up a font dialog and let the user select a new value.
6144 * If this is cancelled go back to the old value but don't
6145 * give an error message.
6146 */
6147 if (STRCMP(p, "*") == 0)
6148 {
6149 p = gui_mch_font_dialog(oldval);
6150
6151 if (new_value_alloced)
6152 free_string_option(p_guifont);
6153
6154 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6155 new_value_alloced = TRUE;
6156 }
6157# endif
6158 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6159 {
6160# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6161 if (STRCMP(p_guifont, "*") == 0)
6162 {
6163 /* Dialog was cancelled: Keep the old value without giving
6164 * an error message. */
6165 if (new_value_alloced)
6166 free_string_option(p_guifont);
6167 p_guifont = vim_strsave(oldval);
6168 new_value_alloced = TRUE;
6169 }
6170 else
6171# endif
6172 errmsg = (char_u *)N_("E596: Invalid font(s)");
6173 }
6174 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006175 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006176 }
6177# ifdef FEAT_XFONTSET
6178 else if (varp == &p_guifontset)
6179 {
6180 if (STRCMP(p_guifontset, "*") == 0)
6181 errmsg = (char_u *)N_("E597: can't select fontset");
6182 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6183 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006184 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 }
6186# endif
6187# ifdef FEAT_MBYTE
6188 else if (varp == &p_guifontwide)
6189 {
6190 if (STRCMP(p_guifontwide, "*") == 0)
6191 errmsg = (char_u *)N_("E533: can't select wide font");
6192 else if (gui_get_wide_font() == FAIL)
6193 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006194 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 }
6196# endif
6197#endif
6198
6199#ifdef CURSOR_SHAPE
6200 /* 'guicursor' */
6201 else if (varp == &p_guicursor)
6202 errmsg = parse_shape_opt(SHAPE_CURSOR);
6203#endif
6204
6205#ifdef FEAT_MOUSESHAPE
6206 /* 'mouseshape' */
6207 else if (varp == &p_mouseshape)
6208 {
6209 errmsg = parse_shape_opt(SHAPE_MOUSE);
6210 update_mouseshape(-1);
6211 }
6212#endif
6213
6214#ifdef FEAT_PRINTER
6215 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006216 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006217# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006218 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006219 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006220# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221#endif
6222
6223#ifdef FEAT_LANGMAP
6224 /* 'langmap' */
6225 else if (varp == &p_langmap)
6226 langmap_set();
6227#endif
6228
6229#ifdef FEAT_LINEBREAK
6230 /* 'breakat' */
6231 else if (varp == &p_breakat)
6232 fill_breakat_flags();
6233#endif
6234
6235#ifdef FEAT_TITLE
6236 /* 'titlestring' and 'iconstring' */
6237 else if (varp == &p_titlestring || varp == &p_iconstring)
6238 {
6239# ifdef FEAT_STL_OPT
6240 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6241
6242 /* NULL => statusline syntax */
6243 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6244 stl_syntax |= flagval;
6245 else
6246 stl_syntax &= ~flagval;
6247# endif
6248 did_set_title(varp == &p_iconstring);
6249
6250 }
6251#endif
6252
6253#ifdef FEAT_GUI
6254 /* 'guioptions' */
6255 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006256 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006258 redraw_gui_only = TRUE;
6259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006260#endif
6261
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006262#if defined(FEAT_GUI_TABLINE)
6263 /* 'guitablabel' */
6264 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006265 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006266 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006267 redraw_gui_only = TRUE;
6268 }
6269 /* 'guitabtooltip' */
6270 else if (varp == &p_gtt)
6271 {
6272 redraw_gui_only = TRUE;
6273 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006274#endif
6275
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6277 /* 'ttymouse' */
6278 else if (varp == &p_ttym)
6279 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006280 /* Switch the mouse off before changing the escape sequences used for
6281 * that. */
6282 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6284 errmsg = e_invarg;
6285 else
6286 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006287 if (termcap_active)
6288 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289 }
6290#endif
6291
6292#ifdef FEAT_VISUAL
6293 /* 'selection' */
6294 else if (varp == &p_sel)
6295 {
6296 if (*p_sel == NUL
6297 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6298 errmsg = e_invarg;
6299 }
6300
6301 /* 'selectmode' */
6302 else if (varp == &p_slm)
6303 {
6304 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6305 errmsg = e_invarg;
6306 }
6307#endif
6308
6309#ifdef FEAT_BROWSE
6310 /* 'browsedir' */
6311 else if (varp == &p_bsdir)
6312 {
6313 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6314 && !mch_isdir(p_bsdir))
6315 errmsg = e_invarg;
6316 }
6317#endif
6318
6319#ifdef FEAT_VISUAL
6320 /* 'keymodel' */
6321 else if (varp == &p_km)
6322 {
6323 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6324 errmsg = e_invarg;
6325 else
6326 {
6327 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6328 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6329 }
6330 }
6331#endif
6332
6333 /* 'mousemodel' */
6334 else if (varp == &p_mousem)
6335 {
6336 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6337 errmsg = e_invarg;
6338#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6339 else if (*p_mousem != *oldval)
6340 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6341 * to create or delete the popup menus. */
6342 gui_motif_update_mousemodel(root_menu);
6343#endif
6344 }
6345
6346 /* 'switchbuf' */
6347 else if (varp == &p_swb)
6348 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006349 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 errmsg = e_invarg;
6351 }
6352
6353 /* 'debug' */
6354 else if (varp == &p_debug)
6355 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006356 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 errmsg = e_invarg;
6358 }
6359
6360 /* 'display' */
6361 else if (varp == &p_dy)
6362 {
6363 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6364 errmsg = e_invarg;
6365 else
6366 (void)init_chartab();
6367
6368 }
6369
6370#ifdef FEAT_VERTSPLIT
6371 /* 'eadirection' */
6372 else if (varp == &p_ead)
6373 {
6374 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6375 errmsg = e_invarg;
6376 }
6377#endif
6378
6379#ifdef FEAT_CLIPBOARD
6380 /* 'clipboard' */
6381 else if (varp == &p_cb)
6382 errmsg = check_clipboard_option();
6383#endif
6384
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006385#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006386 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6387 * buffer in which 'spell' is set load the wordlists. */
6388 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006389 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006390 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006391 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006392
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006393 if (varp == &(curbuf->b_p_spf))
6394 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006395 l = (int)STRLEN(curbuf->b_p_spf);
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006396 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6397 ".add") != 0))
6398 errmsg = e_invarg;
6399 }
6400
6401 if (errmsg == NULL)
6402 {
6403 FOR_ALL_WINDOWS(wp)
6404 if (wp->w_buffer == curbuf && wp->w_p_spell)
6405 {
6406 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006407# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006408 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006409# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006410 }
6411 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006412 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006413 /* When 'spellcapcheck' is set compile the regexp program. */
6414 else if (varp == &(curbuf->b_p_spc))
6415 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006416 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006417 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006418 /* 'spellsuggest' */
6419 else if (varp == &p_sps)
6420 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006421 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006422 errmsg = e_invarg;
6423 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006424 /* 'mkspellmem' */
6425 else if (varp == &p_msm)
6426 {
6427 if (spell_check_msm() != OK)
6428 errmsg = e_invarg;
6429 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006430#endif
6431
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432#ifdef FEAT_QUICKFIX
6433 /* When 'bufhidden' is set, check for valid value. */
6434 else if (gvarp == &p_bh)
6435 {
6436 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6437 errmsg = e_invarg;
6438 }
6439
6440 /* When 'buftype' is set, check for valid value. */
6441 else if (gvarp == &p_bt)
6442 {
6443 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6444 errmsg = e_invarg;
6445 else
6446 {
6447# ifdef FEAT_WINDOWS
6448 if (curwin->w_status_height)
6449 {
6450 curwin->w_redr_status = TRUE;
6451 redraw_later(VALID);
6452 }
6453# endif
6454 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006455# ifdef FEAT_TITLE
6456 redraw_titles();
6457# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 }
6459 }
6460#endif
6461
6462#ifdef FEAT_STL_OPT
6463 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006464 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465 {
6466 int wid;
6467
6468 if (varp == &p_ruf) /* reset ru_wid first */
6469 ru_wid = 0;
6470 s = *varp;
6471 if (varp == &p_ruf && *s == '%')
6472 {
6473 /* set ru_wid if 'ruf' starts with "%99(" */
6474 if (*++s == '-') /* ignore a '-' */
6475 s++;
6476 wid = getdigits(&s);
6477 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6478 ru_wid = wid;
6479 else
6480 errmsg = check_stl_option(p_ruf);
6481 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006482 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006483 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006485 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 comp_col();
6487 }
6488#endif
6489
6490#ifdef FEAT_INS_EXPAND
6491 /* check if it is a valid value for 'complete' -- Acevedo */
6492 else if (gvarp == &p_cpt)
6493 {
6494 for (s = *varp; *s;)
6495 {
6496 while(*s == ',' || *s == ' ')
6497 s++;
6498 if (!*s)
6499 break;
6500 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6501 {
6502 errmsg = illegal_char(errbuf, *s);
6503 break;
6504 }
6505 if (*++s != NUL && *s != ',' && *s != ' ')
6506 {
6507 if (s[-1] == 'k' || s[-1] == 's')
6508 {
6509 /* skip optional filename after 'k' and 's' */
6510 while (*s && *s != ',' && *s != ' ')
6511 {
6512 if (*s == '\\')
6513 ++s;
6514 ++s;
6515 }
6516 }
6517 else
6518 {
6519 if (errbuf != NULL)
6520 {
6521 sprintf((char *)errbuf,
6522 _("E535: Illegal character after <%c>"),
6523 *--s);
6524 errmsg = errbuf;
6525 }
6526 else
6527 errmsg = (char_u *)"";
6528 break;
6529 }
6530 }
6531 }
6532 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006533
6534 /* 'completeopt' */
6535 else if (varp == &p_cot)
6536 {
6537 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6538 errmsg = e_invarg;
6539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540#endif /* FEAT_INS_EXPAND */
6541
6542
6543#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6544 else if (varp == &p_toolbar)
6545 {
6546 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6547 &toolbar_flags, TRUE) != OK)
6548 errmsg = e_invarg;
6549 else
6550 {
6551 out_flush();
6552 gui_mch_show_toolbar((toolbar_flags &
6553 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6554 }
6555 }
6556#endif
6557
6558#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6559 /* 'toolbariconsize': GTK+ 2 only */
6560 else if (varp == &p_tbis)
6561 {
6562 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6563 errmsg = e_invarg;
6564 else
6565 {
6566 out_flush();
6567 gui_mch_show_toolbar((toolbar_flags &
6568 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6569 }
6570 }
6571#endif
6572
6573 /* 'pastetoggle': translate key codes like in a mapping */
6574 else if (varp == &p_pt)
6575 {
6576 if (*p_pt)
6577 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006578 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 if (p != NULL)
6580 {
6581 if (new_value_alloced)
6582 free_string_option(p_pt);
6583 p_pt = p;
6584 new_value_alloced = TRUE;
6585 }
6586 }
6587 }
6588
6589 /* 'backspace' */
6590 else if (varp == &p_bs)
6591 {
6592 if (VIM_ISDIGIT(*p_bs))
6593 {
6594 if (*p_bs >'2' || p_bs[1] != NUL)
6595 errmsg = e_invarg;
6596 }
6597 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6598 errmsg = e_invarg;
6599 }
6600
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006601#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602 /* 'casemap' */
6603 else if (varp == &p_cmp)
6604 {
6605 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6606 errmsg = e_invarg;
6607 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609
6610#ifdef FEAT_DIFF
6611 /* 'diffopt' */
6612 else if (varp == &p_dip)
6613 {
6614 if (diffopt_changed() == FAIL)
6615 errmsg = e_invarg;
6616 }
6617#endif
6618
6619#ifdef FEAT_FOLDING
6620 /* 'foldmethod' */
6621 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6622 {
6623 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6624 || *curwin->w_p_fdm == NUL)
6625 errmsg = e_invarg;
6626 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006627 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006629 if (foldmethodIsDiff(curwin))
6630 newFoldLevel();
6631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006632 }
6633# ifdef FEAT_EVAL
6634 /* 'foldexpr' */
6635 else if (varp == &curwin->w_p_fde)
6636 {
6637 if (foldmethodIsExpr(curwin))
6638 foldUpdateAll(curwin);
6639 }
6640# endif
6641 /* 'foldmarker' */
6642 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6643 {
6644 p = vim_strchr(*varp, ',');
6645 if (p == NULL)
6646 errmsg = (char_u *)N_("E536: comma required");
6647 else if (p == *varp || p[1] == NUL)
6648 errmsg = e_invarg;
6649 else if (foldmethodIsMarker(curwin))
6650 foldUpdateAll(curwin);
6651 }
6652 /* 'commentstring' */
6653 else if (gvarp == &p_cms)
6654 {
6655 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6656 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6657 }
6658 /* 'foldopen' */
6659 else if (varp == &p_fdo)
6660 {
6661 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6662 errmsg = e_invarg;
6663 }
6664 /* 'foldclose' */
6665 else if (varp == &p_fcl)
6666 {
6667 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6668 errmsg = e_invarg;
6669 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006670 /* 'foldignore' */
6671 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6672 {
6673 if (foldmethodIsIndent(curwin))
6674 foldUpdateAll(curwin);
6675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006676#endif
6677
6678#ifdef FEAT_VIRTUALEDIT
6679 /* 'virtualedit' */
6680 else if (varp == &p_ve)
6681 {
6682 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6683 errmsg = e_invarg;
6684 else if (STRCMP(p_ve, oldval) != 0)
6685 {
6686 /* Recompute cursor position in case the new 've' setting
6687 * changes something. */
6688 validate_virtcol();
6689 coladvance(curwin->w_virtcol);
6690 }
6691 }
6692#endif
6693
6694#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6695 else if (varp == &p_csqf)
6696 {
6697 if (p_csqf != NULL)
6698 {
6699 p = p_csqf;
6700 while (*p != NUL)
6701 {
6702 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6703 || p[1] == NUL
6704 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6705 || (p[2] != NUL && p[2] != ','))
6706 {
6707 errmsg = e_invarg;
6708 break;
6709 }
6710 else if (p[2] == NUL)
6711 break;
6712 else
6713 p += 3;
6714 }
6715 }
6716 }
6717#endif
6718
6719 /* Options that are a list of flags. */
6720 else
6721 {
6722 p = NULL;
6723 if (varp == &p_ww)
6724 p = (char_u *)WW_ALL;
6725 if (varp == &p_shm)
6726 p = (char_u *)SHM_ALL;
6727 else if (varp == &(p_cpo))
6728 p = (char_u *)CPO_ALL;
6729 else if (varp == &(curbuf->b_p_fo))
6730 p = (char_u *)FO_ALL;
6731 else if (varp == &p_mouse)
6732 {
6733#ifdef FEAT_MOUSE
6734 p = (char_u *)MOUSE_ALL;
6735#else
6736 if (*p_mouse != NUL)
6737 errmsg = (char_u *)N_("E538: No mouse support");
6738#endif
6739 }
6740#if defined(FEAT_GUI)
6741 else if (varp == &p_go)
6742 p = (char_u *)GO_ALL;
6743#endif
6744 if (p != NULL)
6745 {
6746 for (s = *varp; *s; ++s)
6747 if (vim_strchr(p, *s) == NULL)
6748 {
6749 errmsg = illegal_char(errbuf, *s);
6750 break;
6751 }
6752 }
6753 }
6754
6755 /*
6756 * If error detected, restore the previous value.
6757 */
6758 if (errmsg != NULL)
6759 {
6760 if (new_value_alloced)
6761 free_string_option(*varp);
6762 *varp = oldval;
6763 /*
6764 * When resetting some values, need to act on it.
6765 */
6766 if (did_chartab)
6767 (void)init_chartab();
6768 if (varp == &p_hl)
6769 (void)highlight_changed();
6770 }
6771 else
6772 {
6773#ifdef FEAT_EVAL
6774 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006775 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776#endif
6777 /*
6778 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006779 * Use "free_oldval", because recursiveness may change the flags under
6780 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006782 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 free_string_option(oldval);
6784 if (new_value_alloced)
6785 options[opt_idx].flags |= P_ALLOCED;
6786 else
6787 options[opt_idx].flags &= ~P_ALLOCED;
6788
6789 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006790 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 {
6792 /* global option with local value set to use global value; free
6793 * the local value and make it empty */
6794 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6795 free_string_option(*(char_u **)p);
6796 *(char_u **)p = empty_option;
6797 }
6798
6799 /* May set global value for local option. */
6800 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6801 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006802
6803#ifdef FEAT_AUTOCMD
6804 /*
6805 * Trigger the autocommand only after setting the flags.
6806 */
6807# ifdef FEAT_SYN_HL
6808 /* When 'syntax' is set, load the syntax of that name */
6809 if (varp == &(curbuf->b_p_syn))
6810 {
6811 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6812 curbuf->b_fname, TRUE, curbuf);
6813 }
6814# endif
6815 else if (varp == &(curbuf->b_p_ft))
6816 {
6817 /* 'filetype' is set, trigger the FileType autocommand */
6818 did_filetype = TRUE;
6819 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6820 curbuf->b_fname, TRUE, curbuf);
6821 }
6822#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006823#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006824 if (varp == &(curbuf->b_p_spl))
6825 {
6826 char_u fname[200];
6827
6828 /*
6829 * Source the spell/LANG.vim in 'runtimepath'.
6830 * They could set 'spellcapcheck' depending on the language.
6831 * Use the first name in 'spelllang' up to '_region' or
6832 * '.encoding'.
6833 */
6834 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6835 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6836 break;
6837 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6838 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6839 source_runtime(fname, TRUE);
6840 }
6841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 }
6843
6844#ifdef FEAT_MOUSE
6845 if (varp == &p_mouse)
6846 {
6847# ifdef FEAT_MOUSE_TTY
6848 if (*p_mouse == NUL)
6849 mch_setmouse(FALSE); /* switch mouse off */
6850 else
6851# endif
6852 setmouse(); /* in case 'mouse' changed */
6853 }
6854#endif
6855
6856 if (curwin->w_curswant != MAXCOL)
6857 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006858#ifdef FEAT_GUI
6859 /* check redraw when it's not a GUI option or the GUI is active. */
6860 if (!redraw_gui_only || gui.in_use)
6861#endif
6862 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863
6864 return errmsg;
6865}
6866
6867/*
6868 * Handle setting 'listchars' or 'fillchars'.
6869 * Returns error message, NULL if it's OK.
6870 */
6871 static char_u *
6872set_chars_option(varp)
6873 char_u **varp;
6874{
6875 int round, i, len, entries;
6876 char_u *p, *s;
6877 int c1, c2 = 0;
6878 struct charstab
6879 {
6880 int *cp;
6881 char *name;
6882 };
6883#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6884 static struct charstab filltab[] =
6885 {
6886 {&fill_stl, "stl"},
6887 {&fill_stlnc, "stlnc"},
6888 {&fill_vert, "vert"},
6889 {&fill_fold, "fold"},
6890 {&fill_diff, "diff"},
6891 };
6892#endif
6893 static struct charstab lcstab[] =
6894 {
6895 {&lcs_eol, "eol"},
6896 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006897 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 {&lcs_prec, "precedes"},
6899 {&lcs_tab2, "tab"},
6900 {&lcs_trail, "trail"},
6901 };
6902 struct charstab *tab;
6903
6904#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6905 if (varp == &p_lcs)
6906#endif
6907 {
6908 tab = lcstab;
6909 entries = sizeof(lcstab) / sizeof(struct charstab);
6910 }
6911#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6912 else
6913 {
6914 tab = filltab;
6915 entries = sizeof(filltab) / sizeof(struct charstab);
6916 }
6917#endif
6918
6919 /* first round: check for valid value, second round: assign values */
6920 for (round = 0; round <= 1; ++round)
6921 {
6922 if (round)
6923 {
6924 /* After checking that the value is valid: set defaults: space for
6925 * 'fillchars', NUL for 'listchars' */
6926 for (i = 0; i < entries; ++i)
6927 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6928 if (varp == &p_lcs)
6929 lcs_tab1 = NUL;
6930#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6931 else
6932 fill_diff = '-';
6933#endif
6934 }
6935 p = *varp;
6936 while (*p)
6937 {
6938 for (i = 0; i < entries; ++i)
6939 {
6940 len = (int)STRLEN(tab[i].name);
6941 if (STRNCMP(p, tab[i].name, len) == 0
6942 && p[len] == ':'
6943 && p[len + 1] != NUL)
6944 {
6945 s = p + len + 1;
6946#ifdef FEAT_MBYTE
6947 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006948 if (mb_char2cells(c1) > 1)
6949 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950#else
6951 c1 = *s++;
6952#endif
6953 if (tab[i].cp == &lcs_tab2)
6954 {
6955 if (*s == NUL)
6956 continue;
6957#ifdef FEAT_MBYTE
6958 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006959 if (mb_char2cells(c2) > 1)
6960 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961#else
6962 c2 = *s++;
6963#endif
6964 }
6965 if (*s == ',' || *s == NUL)
6966 {
6967 if (round)
6968 {
6969 if (tab[i].cp == &lcs_tab2)
6970 {
6971 lcs_tab1 = c1;
6972 lcs_tab2 = c2;
6973 }
6974 else
6975 *(tab[i].cp) = c1;
6976
6977 }
6978 p = s;
6979 break;
6980 }
6981 }
6982 }
6983
6984 if (i == entries)
6985 return e_invarg;
6986 if (*p == ',')
6987 ++p;
6988 }
6989 }
6990
6991 return NULL; /* no error */
6992}
6993
6994#ifdef FEAT_STL_OPT
6995/*
6996 * Check validity of options with the 'statusline' format.
6997 * Return error message or NULL.
6998 */
6999 char_u *
7000check_stl_option(s)
7001 char_u *s;
7002{
7003 int itemcnt = 0;
7004 int groupdepth = 0;
7005 static char_u errbuf[80];
7006
7007 while (*s && itemcnt < STL_MAX_ITEM)
7008 {
7009 /* Check for valid keys after % sequences */
7010 while (*s && *s != '%')
7011 s++;
7012 if (!*s)
7013 break;
7014 s++;
7015 if (*s != '%' && *s != ')')
7016 ++itemcnt;
7017 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7018 {
7019 s++;
7020 continue;
7021 }
7022 if (*s == ')')
7023 {
7024 s++;
7025 if (--groupdepth < 0)
7026 break;
7027 continue;
7028 }
7029 if (*s == '-')
7030 s++;
7031 while (VIM_ISDIGIT(*s))
7032 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007033 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 continue;
7035 if (*s == '.')
7036 {
7037 s++;
7038 while (*s && VIM_ISDIGIT(*s))
7039 s++;
7040 }
7041 if (*s == '(')
7042 {
7043 groupdepth++;
7044 continue;
7045 }
7046 if (vim_strchr(STL_ALL, *s) == NULL)
7047 {
7048 return illegal_char(errbuf, *s);
7049 }
7050 if (*s == '{')
7051 {
7052 s++;
7053 while (*s != '}' && *s)
7054 s++;
7055 if (*s != '}')
7056 return (char_u *)N_("E540: Unclosed expression sequence");
7057 }
7058 }
7059 if (itemcnt >= STL_MAX_ITEM)
7060 return (char_u *)N_("E541: too many items");
7061 if (groupdepth != 0)
7062 return (char_u *)N_("E542: unbalanced groups");
7063 return NULL;
7064}
7065#endif
7066
7067#ifdef FEAT_CLIPBOARD
7068/*
7069 * Extract the items in the 'clipboard' option and set global values.
7070 */
7071 static char_u *
7072check_clipboard_option()
7073{
7074 int new_unnamed = FALSE;
7075 int new_autoselect = FALSE;
7076 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007077 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 regprog_T *new_exclude_prog = NULL;
7079 char_u *errmsg = NULL;
7080 char_u *p;
7081
7082 for (p = p_cb; *p != NUL; )
7083 {
7084 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7085 {
7086 new_unnamed = TRUE;
7087 p += 7;
7088 }
7089 else if (STRNCMP(p, "autoselect", 10) == 0
7090 && (p[10] == ',' || p[10] == NUL))
7091 {
7092 new_autoselect = TRUE;
7093 p += 10;
7094 }
7095 else if (STRNCMP(p, "autoselectml", 12) == 0
7096 && (p[12] == ',' || p[12] == NUL))
7097 {
7098 new_autoselectml = TRUE;
7099 p += 12;
7100 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007101 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7102 {
7103 new_html = TRUE;
7104 p += 4;
7105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7107 {
7108 p += 8;
7109 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7110 if (new_exclude_prog == NULL)
7111 errmsg = e_invarg;
7112 break;
7113 }
7114 else
7115 {
7116 errmsg = e_invarg;
7117 break;
7118 }
7119 if (*p == ',')
7120 ++p;
7121 }
7122 if (errmsg == NULL)
7123 {
7124 clip_unnamed = new_unnamed;
7125 clip_autoselect = new_autoselect;
7126 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007127 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128 vim_free(clip_exclude_prog);
7129 clip_exclude_prog = new_exclude_prog;
7130 }
7131 else
7132 vim_free(new_exclude_prog);
7133
7134 return errmsg;
7135}
7136#endif
7137
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007138#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007139/*
7140 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7141 * Return error message when failed, NULL when OK.
7142 */
7143 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007144compile_cap_prog(buf)
7145 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007146{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007147 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007148 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007149
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007150 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007151 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007152 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007153 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007154 /* Prepend a ^ so that we only match at one column */
7155 re = concat_str((char_u *)"^", buf->b_p_spc);
7156 if (re != NULL)
7157 {
7158 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7159 if (buf->b_cap_prog == NULL)
7160 {
7161 buf->b_cap_prog = rp; /* restore the previous program */
7162 return e_invarg;
7163 }
7164 vim_free(re);
7165 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007166 }
7167
7168 vim_free(rp);
7169 return NULL;
7170}
7171#endif
7172
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007173#if defined(FEAT_EVAL) || defined(PROTO)
7174/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007175 * Set the scriptID for an option, taking care of setting the buffer- or
7176 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007177 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007178 static void
7179set_option_scriptID_idx(opt_idx, opt_flags, id)
7180 int opt_idx;
7181 int opt_flags;
7182 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007183{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007184 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7185 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007186
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007187 /* Remember where the option was set. For local options need to do that
7188 * in the buffer or window structure. */
7189 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007190 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007191 if (both || (opt_flags & OPT_LOCAL))
7192 {
7193 if (indir & PV_BUF)
7194 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7195 else if (indir & PV_WIN)
7196 curwin->w_p_scriptID[indir & PV_MASK] = id;
7197 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007198}
7199#endif
7200
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201/*
7202 * Set the value of a boolean option, and take care of side effects.
7203 * Returns NULL for success, or an error message for an error.
7204 */
7205 static char_u *
7206set_bool_option(opt_idx, varp, value, opt_flags)
7207 int opt_idx; /* index in options[] table */
7208 char_u *varp; /* pointer to the option variable */
7209 int value; /* new value */
7210 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7211{
7212 int old_value = *(int *)varp;
7213
Bram Moolenaar071d4272004-06-13 20:20:40 +00007214 /* Disallow changing some options from secure mode */
7215 if ((secure
7216#ifdef HAVE_SANDBOX
7217 || sandbox != 0
7218#endif
7219 ) && (options[opt_idx].flags & P_SECURE))
7220 return e_secure;
7221
7222 *(int *)varp = value; /* set the new value */
7223#ifdef FEAT_EVAL
7224 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007225 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226#endif
7227
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007228#ifdef FEAT_GUI
7229 need_mouse_correct = TRUE;
7230#endif
7231
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 /* May set global value for local option. */
7233 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7234 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7235
7236 /*
7237 * Handle side effects of changing a bool option.
7238 */
7239
7240 /* 'compatible' */
7241 if ((int *)varp == &p_cp)
7242 {
7243 compatible_set();
7244 }
7245
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007246 /* 'list', 'number' */
7247 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007248 || (int *)varp == &curwin->w_p_nu
7249 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007250 {
7251 if (curwin->w_curswant != MAXCOL)
7252 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007253
7254 /* If 'number' is set, reset 'relativenumber'. */
7255 /* If 'relativenumber' is set, reset 'number'. */
7256 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7257 curwin->w_p_rnu = FALSE;
7258 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7259 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007260 }
7261
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 else if ((int *)varp == &curbuf->b_p_ro)
7263 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007264 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7266 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007267
7268 /* when 'readonly' is set may give W10 again */
7269 if (curbuf->b_p_ro)
7270 curbuf->b_did_warn = FALSE;
7271
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007273 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274#endif
7275 }
7276
7277#ifdef FEAT_TITLE
7278 /* when 'modifiable' is changed, redraw the window title */
7279 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007280 {
7281 redraw_titles();
7282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283 /* when 'endofline' is changed, redraw the window title */
7284 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007285 {
7286 redraw_titles();
7287 }
7288# ifdef FEAT_MBYTE
7289 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007290 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007291 {
7292 redraw_titles();
7293 }
7294# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007295#endif
7296
7297 /* when 'bin' is set also set some other options */
7298 else if ((int *)varp == &curbuf->b_p_bin)
7299 {
7300 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7301#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007302 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303#endif
7304 }
7305
7306#ifdef FEAT_AUTOCMD
7307 /* when 'buflisted' changes, trigger autocommands */
7308 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7309 {
7310 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7311 NULL, NULL, TRUE, curbuf);
7312 }
7313#endif
7314
7315 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7316 else if ((int *)varp == &curbuf->b_p_swf)
7317 {
7318 if (curbuf->b_p_swf && p_uc)
7319 ml_open_file(curbuf); /* create the swap file */
7320 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007321 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7322 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 mf_close_file(curbuf, TRUE); /* remove the swap file */
7324 }
7325
7326 /* when 'terse' is set change 'shortmess' */
7327 else if ((int *)varp == &p_terse)
7328 {
7329 char_u *p;
7330
7331 p = vim_strchr(p_shm, SHM_SEARCH);
7332
7333 /* insert 's' in p_shm */
7334 if (p_terse && p == NULL)
7335 {
7336 STRCPY(IObuff, p_shm);
7337 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007338 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 }
7340 /* remove 's' from p_shm */
7341 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007342 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 }
7344
7345 /* when 'paste' is set or reset also change other options */
7346 else if ((int *)varp == &p_paste)
7347 {
7348 paste_option_changed();
7349 }
7350
7351 /* when 'insertmode' is set from an autocommand need to do work here */
7352 else if ((int *)varp == &p_im)
7353 {
7354 if (p_im)
7355 {
7356 if ((State & INSERT) == 0)
7357 need_start_insertmode = TRUE;
7358 stop_insert_mode = FALSE;
7359 }
7360 else
7361 {
7362 need_start_insertmode = FALSE;
7363 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007364 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007365 clear_cmdline = TRUE; /* remove "(insert)" */
7366 restart_edit = 0;
7367 }
7368 }
7369
7370 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7371 else if ((int *)varp == &p_ic && p_hls)
7372 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007373 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 }
7375
7376#ifdef FEAT_SEARCH_EXTRA
7377 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7378 else if ((int *)varp == &p_hls)
7379 {
7380 no_hlsearch = FALSE;
7381 }
7382#endif
7383
7384#ifdef FEAT_SCROLLBIND
7385 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7386 * at the end of normal_cmd() */
7387 else if ((int *)varp == &curwin->w_p_scb)
7388 {
7389 if (curwin->w_p_scb)
7390 do_check_scrollbind(FALSE);
7391 }
7392#endif
7393
7394#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7395 /* There can be only one window with 'previewwindow' set. */
7396 else if ((int *)varp == &curwin->w_p_pvw)
7397 {
7398 if (curwin->w_p_pvw)
7399 {
7400 win_T *win;
7401
7402 for (win = firstwin; win != NULL; win = win->w_next)
7403 if (win->w_p_pvw && win != curwin)
7404 {
7405 curwin->w_p_pvw = FALSE;
7406 return (char_u *)N_("E590: A preview window already exists");
7407 }
7408 }
7409 }
7410#endif
7411
7412 /* when 'textmode' is set or reset also change 'fileformat' */
7413 else if ((int *)varp == &curbuf->b_p_tx)
7414 {
7415 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7416 }
7417
7418 /* when 'textauto' is set or reset also change 'fileformats' */
7419 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007420 set_string_option_direct((char_u *)"ffs", -1,
7421 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007422 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007423
7424 /*
7425 * When 'lisp' option changes include/exclude '-' in
7426 * keyword characters.
7427 */
7428#ifdef FEAT_LISP
7429 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7430 {
7431 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7432 }
7433#endif
7434
7435#ifdef FEAT_TITLE
7436 /* when 'title' changed, may need to change the title; same for 'icon' */
7437 else if ((int *)varp == &p_title)
7438 {
7439 did_set_title(FALSE);
7440 }
7441
7442 else if ((int *)varp == &p_icon)
7443 {
7444 did_set_title(TRUE);
7445 }
7446#endif
7447
7448 else if ((int *)varp == &curbuf->b_changed)
7449 {
7450 if (!value)
7451 save_file_ff(curbuf); /* Buffer is unchanged */
7452#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007453 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454#endif
7455#ifdef FEAT_AUTOCMD
7456 modified_was_set = value;
7457#endif
7458 }
7459
7460#ifdef BACKSLASH_IN_FILENAME
7461 else if ((int *)varp == &p_ssl)
7462 {
7463 if (p_ssl)
7464 {
7465 psepc = '/';
7466 psepcN = '\\';
7467 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007468 }
7469 else
7470 {
7471 psepc = '\\';
7472 psepcN = '/';
7473 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007474 }
7475
7476 /* need to adjust the file name arguments and buffer names. */
7477 buflist_slash_adjust();
7478 alist_slash_adjust();
7479# ifdef FEAT_EVAL
7480 scriptnames_slash_adjust();
7481# endif
7482 }
7483#endif
7484
7485 /* If 'wrap' is set, set w_leftcol to zero. */
7486 else if ((int *)varp == &curwin->w_p_wrap)
7487 {
7488 if (curwin->w_p_wrap)
7489 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007490 if (curwin->w_curswant != MAXCOL)
7491 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 }
7493
7494#ifdef FEAT_WINDOWS
7495 else if ((int *)varp == &p_ea)
7496 {
7497 if (p_ea && !old_value)
7498 win_equal(curwin, FALSE, 0);
7499 }
7500#endif
7501
7502 else if ((int *)varp == &p_wiv)
7503 {
7504 /*
7505 * When 'weirdinvert' changed, set/reset 't_xs'.
7506 * Then set 'weirdinvert' according to value of 't_xs'.
7507 */
7508 if (p_wiv && !old_value)
7509 T_XS = (char_u *)"y";
7510 else if (!p_wiv && old_value)
7511 T_XS = empty_option;
7512 p_wiv = (*T_XS != NUL);
7513 }
7514
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007515#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 else if ((int *)varp == &p_beval)
7517 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 if (p_beval == TRUE)
7519 gui_mch_enable_beval_area(balloonEval);
7520 else
7521 gui_mch_disable_beval_area(balloonEval);
7522 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007525#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526 else if ((int *)varp == &p_acd)
7527 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007528 /* Change directories when the 'acd' option is set now. */
7529 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 }
7531#endif
7532
7533#ifdef FEAT_DIFF
7534 /* 'diff' */
7535 else if ((int *)varp == &curwin->w_p_diff)
7536 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007537 /* May add or remove the buffer from the list of diff buffers. */
7538 diff_buf_adjust(curwin);
7539# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 if (foldmethodIsDiff(curwin))
7541 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007542# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 }
7544#endif
7545
7546#ifdef USE_IM_CONTROL
7547 /* 'imdisable' */
7548 else if ((int *)varp == &p_imdisable)
7549 {
7550 /* Only de-activate it here, it will be enabled when changing mode. */
7551 if (p_imdisable)
7552 im_set_active(FALSE);
7553 }
7554#endif
7555
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007556#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007557 /* 'spell' */
7558 else if ((int *)varp == &curwin->w_p_spell)
7559 {
7560 if (curwin->w_p_spell)
7561 {
7562 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007563
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007564 if (errmsg != NULL)
7565 EMSG(_(errmsg));
7566 }
7567 }
7568#endif
7569
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570#ifdef FEAT_FKMAP
7571 else if ((int *)varp == &p_altkeymap)
7572 {
7573 if (old_value != p_altkeymap)
7574 {
7575 if (!p_altkeymap)
7576 {
7577 p_hkmap = p_fkmap;
7578 p_fkmap = 0;
7579 }
7580 else
7581 {
7582 p_fkmap = p_hkmap;
7583 p_hkmap = 0;
7584 }
7585 (void)init_chartab();
7586 }
7587 }
7588
7589 /*
7590 * In case some second language keymapping options have changed, check
7591 * and correct the setting in a consistent way.
7592 */
7593
7594 /*
7595 * If hkmap or fkmap are set, reset Arabic keymapping.
7596 */
7597 if ((p_hkmap || p_fkmap) && p_altkeymap)
7598 {
7599 p_altkeymap = p_fkmap;
7600# ifdef FEAT_ARABIC
7601 curwin->w_p_arab = FALSE;
7602# endif
7603 (void)init_chartab();
7604 }
7605
7606 /*
7607 * If hkmap set, reset Farsi keymapping.
7608 */
7609 if (p_hkmap && p_altkeymap)
7610 {
7611 p_altkeymap = 0;
7612 p_fkmap = 0;
7613# ifdef FEAT_ARABIC
7614 curwin->w_p_arab = FALSE;
7615# endif
7616 (void)init_chartab();
7617 }
7618
7619 /*
7620 * If fkmap set, reset Hebrew keymapping.
7621 */
7622 if (p_fkmap && !p_altkeymap)
7623 {
7624 p_altkeymap = 1;
7625 p_hkmap = 0;
7626# ifdef FEAT_ARABIC
7627 curwin->w_p_arab = FALSE;
7628# endif
7629 (void)init_chartab();
7630 }
7631#endif
7632
7633#ifdef FEAT_ARABIC
7634 if ((int *)varp == &curwin->w_p_arab)
7635 {
7636 if (curwin->w_p_arab)
7637 {
7638 /*
7639 * 'arabic' is set, handle various sub-settings.
7640 */
7641 if (!p_tbidi)
7642 {
7643 /* set rightleft mode */
7644 if (!curwin->w_p_rl)
7645 {
7646 curwin->w_p_rl = TRUE;
7647 changed_window_setting();
7648 }
7649
7650 /* Enable Arabic shaping (major part of what Arabic requires) */
7651 if (!p_arshape)
7652 {
7653 p_arshape = TRUE;
7654 redraw_later_clear();
7655 }
7656 }
7657
7658 /* Arabic requires a utf-8 encoding, inform the user if its not
7659 * set. */
7660 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007661 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007662 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7663
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007664 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007665 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7666#ifdef FEAT_EVAL
7667 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7668#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670
7671# ifdef FEAT_MBYTE
7672 /* set 'delcombine' */
7673 p_deco = TRUE;
7674# endif
7675
7676# ifdef FEAT_KEYMAP
7677 /* Force-set the necessary keymap for arabic */
7678 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7679 OPT_LOCAL);
7680# endif
7681# ifdef FEAT_FKMAP
7682 p_altkeymap = 0;
7683 p_hkmap = 0;
7684 p_fkmap = 0;
7685 (void)init_chartab();
7686# endif
7687 }
7688 else
7689 {
7690 /*
7691 * 'arabic' is reset, handle various sub-settings.
7692 */
7693 if (!p_tbidi)
7694 {
7695 /* reset rightleft mode */
7696 if (curwin->w_p_rl)
7697 {
7698 curwin->w_p_rl = FALSE;
7699 changed_window_setting();
7700 }
7701
7702 /* 'arabicshape' isn't reset, it is a global option and
7703 * another window may still need it "on". */
7704 }
7705
7706 /* 'delcombine' isn't reset, it is a global option and another
7707 * window may still want it "on". */
7708
7709# ifdef FEAT_KEYMAP
7710 /* Revert to the default keymap */
7711 curbuf->b_p_iminsert = B_IMODE_NONE;
7712 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7713# endif
7714 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007715 if (curwin->w_curswant != MAXCOL)
7716 curwin->w_set_curswant = TRUE;
7717 }
7718
7719 else if ((int *)varp == &p_arshape)
7720 {
7721 if (curwin->w_curswant != MAXCOL)
7722 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 }
7724#endif
7725
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007726#ifdef FEAT_LINEBREAK
7727 if ((int *)varp == &curwin->w_p_lbr)
7728 {
7729 if (curwin->w_curswant != MAXCOL)
7730 curwin->w_set_curswant = TRUE;
7731 }
7732#endif
7733
7734#ifdef FEAT_RIGHTLEFT
7735 if ((int *)varp == &curwin->w_p_rl)
7736 {
7737 if (curwin->w_curswant != MAXCOL)
7738 curwin->w_set_curswant = TRUE;
7739 }
7740#endif
7741
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742 /*
7743 * End of handling side effects for bool options.
7744 */
7745
7746 options[opt_idx].flags |= P_WAS_SET;
7747
7748 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007749
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 check_redraw(options[opt_idx].flags);
7751
7752 return NULL;
7753}
7754
7755/*
7756 * Set the value of a number option, and take care of side effects.
7757 * Returns NULL for success, or an error message for an error.
7758 */
7759 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007760set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 int opt_idx; /* index in options[] table */
7762 char_u *varp; /* pointer to the option variable */
7763 long value; /* new value */
7764 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007765 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7767 OPT_MODELINE */
7768{
7769 char_u *errmsg = NULL;
7770 long old_value = *(long *)varp;
7771 long old_Rows = Rows; /* remember old Rows */
7772 long old_Columns = Columns; /* remember old Columns */
7773 long *pp = (long *)varp;
7774
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007775 /* Disallow changing some options from secure mode. */
7776 if ((secure
7777#ifdef HAVE_SANDBOX
7778 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007780 ) && (options[opt_idx].flags & P_SECURE))
7781 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007782
7783 *pp = value;
7784#ifdef FEAT_EVAL
7785 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007786 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007788#ifdef FEAT_GUI
7789 need_mouse_correct = TRUE;
7790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791
7792 if (curbuf->b_p_sw <= 0)
7793 {
7794 errmsg = e_positive;
7795 curbuf->b_p_sw = curbuf->b_p_ts;
7796 }
7797
7798 /*
7799 * Number options that need some action when changed
7800 */
7801#ifdef FEAT_WINDOWS
7802 if (pp == &p_wh || pp == &p_hh)
7803 {
7804 if (p_wh < 1)
7805 {
7806 errmsg = e_positive;
7807 p_wh = 1;
7808 }
7809 if (p_wmh > p_wh)
7810 {
7811 errmsg = e_winheight;
7812 p_wh = p_wmh;
7813 }
7814 if (p_hh < 0)
7815 {
7816 errmsg = e_positive;
7817 p_hh = 0;
7818 }
7819
7820 /* Change window height NOW */
7821 if (lastwin != firstwin)
7822 {
7823 if (pp == &p_wh && curwin->w_height < p_wh)
7824 win_setheight((int)p_wh);
7825 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7826 win_setheight((int)p_hh);
7827 }
7828 }
7829
7830 /* 'winminheight' */
7831 else if (pp == &p_wmh)
7832 {
7833 if (p_wmh < 0)
7834 {
7835 errmsg = e_positive;
7836 p_wmh = 0;
7837 }
7838 if (p_wmh > p_wh)
7839 {
7840 errmsg = e_winheight;
7841 p_wmh = p_wh;
7842 }
7843 win_setminheight();
7844 }
7845
7846# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007847 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 {
7849 if (p_wiw < 1)
7850 {
7851 errmsg = e_positive;
7852 p_wiw = 1;
7853 }
7854 if (p_wmw > p_wiw)
7855 {
7856 errmsg = e_winwidth;
7857 p_wiw = p_wmw;
7858 }
7859
7860 /* Change window width NOW */
7861 if (lastwin != firstwin && curwin->w_width < p_wiw)
7862 win_setwidth((int)p_wiw);
7863 }
7864
7865 /* 'winminwidth' */
7866 else if (pp == &p_wmw)
7867 {
7868 if (p_wmw < 0)
7869 {
7870 errmsg = e_positive;
7871 p_wmw = 0;
7872 }
7873 if (p_wmw > p_wiw)
7874 {
7875 errmsg = e_winwidth;
7876 p_wmw = p_wiw;
7877 }
7878 win_setminheight();
7879 }
7880# endif
7881
7882#endif
7883
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007884#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007885 else if (pp == &curbuf->b_p_cm)
7886 {
7887 if (curbuf->b_p_cm < 0)
7888 {
7889 errmsg = e_positive;
7890 curbuf->b_p_cm = 0;
7891 }
7892 if (curbuf->b_p_cm > 1)
7893 {
7894 errmsg = e_invarg;
7895 curbuf->b_p_cm = 1;
7896 }
7897 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
7898 curbuf->b_p_cm = 0;
7899 }
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007900#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007901
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902#ifdef FEAT_WINDOWS
7903 /* (re)set last window status line */
7904 else if (pp == &p_ls)
7905 {
7906 last_status(FALSE);
7907 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007908
7909 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007910 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007911 {
7912 shell_new_rows(); /* recompute window positions and heights */
7913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914#endif
7915
7916#ifdef FEAT_GUI
7917 else if (pp == &p_linespace)
7918 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007919 /* Recompute gui.char_height and resize the Vim window to keep the
7920 * same number of lines. */
7921 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007922 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 }
7924#endif
7925
7926#ifdef FEAT_FOLDING
7927 /* 'foldlevel' */
7928 else if (pp == &curwin->w_p_fdl)
7929 {
7930 if (curwin->w_p_fdl < 0)
7931 curwin->w_p_fdl = 0;
7932 newFoldLevel();
7933 }
7934
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007935 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 else if (pp == &curwin->w_p_fml)
7937 {
7938 foldUpdateAll(curwin);
7939 }
7940
7941 /* 'foldnestmax' */
7942 else if (pp == &curwin->w_p_fdn)
7943 {
7944 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7945 foldUpdateAll(curwin);
7946 }
7947
7948 /* 'foldcolumn' */
7949 else if (pp == &curwin->w_p_fdc)
7950 {
7951 if (curwin->w_p_fdc < 0)
7952 {
7953 errmsg = e_positive;
7954 curwin->w_p_fdc = 0;
7955 }
7956 else if (curwin->w_p_fdc > 12)
7957 {
7958 errmsg = e_invarg;
7959 curwin->w_p_fdc = 12;
7960 }
7961 }
7962
7963 /* 'shiftwidth' or 'tabstop' */
7964 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7965 {
7966 if (foldmethodIsIndent(curwin))
7967 foldUpdateAll(curwin);
7968 }
7969#endif /* FEAT_FOLDING */
7970
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007971#ifdef FEAT_MBYTE
7972 /* 'maxcombine' */
7973 else if (pp == &p_mco)
7974 {
7975 if (p_mco > MAX_MCO)
7976 p_mco = MAX_MCO;
7977 else if (p_mco < 0)
7978 p_mco = 0;
7979 screenclear(); /* will re-allocate the screen */
7980 }
7981#endif
7982
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 else if (pp == &curbuf->b_p_iminsert)
7984 {
7985 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7986 {
7987 errmsg = e_invarg;
7988 curbuf->b_p_iminsert = B_IMODE_NONE;
7989 }
7990 p_iminsert = curbuf->b_p_iminsert;
7991 if (termcap_active) /* don't do this in the alternate screen */
7992 showmode();
7993#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7994 /* Show/unshow value of 'keymap' in status lines. */
7995 status_redraw_curbuf();
7996#endif
7997 }
7998
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007999 else if (pp == &p_window)
8000 {
8001 if (p_window < 1)
8002 p_window = 1;
8003 else if (p_window >= Rows)
8004 p_window = Rows - 1;
8005 }
8006
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 else if (pp == &curbuf->b_p_imsearch)
8008 {
8009 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8010 {
8011 errmsg = e_invarg;
8012 curbuf->b_p_imsearch = B_IMODE_NONE;
8013 }
8014 p_imsearch = curbuf->b_p_imsearch;
8015 }
8016
8017#ifdef FEAT_TITLE
8018 /* if 'titlelen' has changed, redraw the title */
8019 else if (pp == &p_titlelen)
8020 {
8021 if (p_titlelen < 0)
8022 {
8023 errmsg = e_positive;
8024 p_titlelen = 85;
8025 }
8026 if (starting != NO_SCREEN && old_value != p_titlelen)
8027 need_maketitle = TRUE;
8028 }
8029#endif
8030
8031 /* if p_ch changed value, change the command line height */
8032 else if (pp == &p_ch)
8033 {
8034 if (p_ch < 1)
8035 {
8036 errmsg = e_positive;
8037 p_ch = 1;
8038 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008039 if (p_ch > Rows - min_rows() + 1)
8040 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041
8042 /* Only compute the new window layout when startup has been
8043 * completed. Otherwise the frame sizes may be wrong. */
8044 if (p_ch != old_value && full_screen
8045#ifdef FEAT_GUI
8046 && !gui.starting
8047#endif
8048 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008049 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 }
8051
8052 /* when 'updatecount' changes from zero to non-zero, open swap files */
8053 else if (pp == &p_uc)
8054 {
8055 if (p_uc < 0)
8056 {
8057 errmsg = e_positive;
8058 p_uc = 100;
8059 }
8060 if (p_uc && !old_value)
8061 ml_open_files();
8062 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008063#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008064 else if (pp == &p_mzq)
8065 mzvim_reset_timer();
8066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067
8068 /* sync undo before 'undolevels' changes */
8069 else if (pp == &p_ul)
8070 {
8071 /* use the old value, otherwise u_sync() may not work properly */
8072 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008073 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 p_ul = value;
8075 }
8076
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008077#ifdef FEAT_LINEBREAK
8078 /* 'numberwidth' must be positive */
8079 else if (pp == &curwin->w_p_nuw)
8080 {
8081 if (curwin->w_p_nuw < 1)
8082 {
8083 errmsg = e_positive;
8084 curwin->w_p_nuw = 1;
8085 }
8086 if (curwin->w_p_nuw > 10)
8087 {
8088 errmsg = e_invarg;
8089 curwin->w_p_nuw = 10;
8090 }
8091 curwin->w_nrwidth_line_count = 0;
8092 }
8093#endif
8094
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 /*
8096 * Check the bounds for numeric options here
8097 */
8098 if (Rows < min_rows() && full_screen)
8099 {
8100 if (errbuf != NULL)
8101 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008102 vim_snprintf((char *)errbuf, errbuflen,
8103 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 errmsg = errbuf;
8105 }
8106 Rows = min_rows();
8107 }
8108 if (Columns < MIN_COLUMNS && full_screen)
8109 {
8110 if (errbuf != NULL)
8111 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008112 vim_snprintf((char *)errbuf, errbuflen,
8113 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 errmsg = errbuf;
8115 }
8116 Columns = MIN_COLUMNS;
8117 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008118 /* Limit the values to avoid an overflow in Rows * Columns. */
8119 if (Columns > 10000)
8120 Columns = 10000;
8121 if (Rows > 1000)
8122 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123
8124#ifdef DJGPP
8125 /* avoid a crash by checking for a too large value of 'columns' */
8126 if (old_Columns != Columns && full_screen && term_console)
8127 mch_check_columns();
8128#endif
8129
8130 /*
8131 * If the screen (shell) height has been changed, assume it is the
8132 * physical screenheight.
8133 */
8134 if (old_Rows != Rows || old_Columns != Columns)
8135 {
8136 /* Changing the screen size is not allowed while updating the screen. */
8137 if (updating_screen)
8138 *pp = old_value;
8139 else if (full_screen
8140#ifdef FEAT_GUI
8141 && !gui.starting
8142#endif
8143 )
8144 set_shellsize((int)Columns, (int)Rows, TRUE);
8145 else
8146 {
8147 /* Postpone the resizing; check the size and cmdline position for
8148 * messages. */
8149 check_shellsize();
8150 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8151 cmdline_row = Rows - p_ch;
8152 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008153 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008154 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 }
8156
8157 if (curbuf->b_p_sts < 0)
8158 {
8159 errmsg = e_positive;
8160 curbuf->b_p_sts = 0;
8161 }
8162 if (curbuf->b_p_ts <= 0)
8163 {
8164 errmsg = e_positive;
8165 curbuf->b_p_ts = 8;
8166 }
8167 if (curbuf->b_p_tw < 0)
8168 {
8169 errmsg = e_positive;
8170 curbuf->b_p_tw = 0;
8171 }
8172 if (p_tm < 0)
8173 {
8174 errmsg = e_positive;
8175 p_tm = 0;
8176 }
8177 if ((curwin->w_p_scr <= 0
8178 || (curwin->w_p_scr > curwin->w_height
8179 && curwin->w_height > 0))
8180 && full_screen)
8181 {
8182 if (pp == &(curwin->w_p_scr))
8183 {
8184 if (curwin->w_p_scr != 0)
8185 errmsg = e_scroll;
8186 win_comp_scroll(curwin);
8187 }
8188 /* If 'scroll' became invalid because of a side effect silently adjust
8189 * it. */
8190 else if (curwin->w_p_scr <= 0)
8191 curwin->w_p_scr = 1;
8192 else /* curwin->w_p_scr > curwin->w_height */
8193 curwin->w_p_scr = curwin->w_height;
8194 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008195 if (p_hi < 0)
8196 {
8197 errmsg = e_positive;
8198 p_hi = 0;
8199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 if (p_report < 0)
8201 {
8202 errmsg = e_positive;
8203 p_report = 1;
8204 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008205 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 {
8207 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8208 p_sj = Rows / 2;
8209 else
8210 {
8211 errmsg = e_scroll;
8212 p_sj = 1;
8213 }
8214 }
8215 if (p_so < 0 && full_screen)
8216 {
8217 errmsg = e_scroll;
8218 p_so = 0;
8219 }
8220 if (p_siso < 0 && full_screen)
8221 {
8222 errmsg = e_positive;
8223 p_siso = 0;
8224 }
8225#ifdef FEAT_CMDWIN
8226 if (p_cwh < 1)
8227 {
8228 errmsg = e_positive;
8229 p_cwh = 1;
8230 }
8231#endif
8232 if (p_ut < 0)
8233 {
8234 errmsg = e_positive;
8235 p_ut = 2000;
8236 }
8237 if (p_ss < 0)
8238 {
8239 errmsg = e_positive;
8240 p_ss = 0;
8241 }
8242
8243 /* May set global value for local option. */
8244 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8245 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8246
8247 options[opt_idx].flags |= P_WAS_SET;
8248
8249 comp_col(); /* in case 'columns' or 'ls' changed */
8250 if (curwin->w_curswant != MAXCOL)
8251 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8252 check_redraw(options[opt_idx].flags);
8253
8254 return errmsg;
8255}
8256
8257/*
8258 * Called after an option changed: check if something needs to be redrawn.
8259 */
8260 static void
8261check_redraw(flags)
8262 long_u flags;
8263{
8264 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8265 int clear = (flags & P_RCLR) == P_RCLR;
8266 int all = ((flags & P_RALL) == P_RALL || clear);
8267
8268#ifdef FEAT_WINDOWS
8269 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8270 status_redraw_all();
8271#endif
8272
8273 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8274 changed_window_setting();
8275 if (flags & P_RBUF)
8276 redraw_curbuf_later(NOT_VALID);
8277 if (clear)
8278 redraw_all_later(CLEAR);
8279 else if (all)
8280 redraw_all_later(NOT_VALID);
8281}
8282
8283/*
8284 * Find index for option 'arg'.
8285 * Return -1 if not found.
8286 */
8287 static int
8288findoption(arg)
8289 char_u *arg;
8290{
8291 int opt_idx;
8292 char *s, *p;
8293 static short quick_tab[27] = {0, 0}; /* quick access table */
8294 int is_term_opt;
8295
8296 /*
8297 * For first call: Initialize the quick-access table.
8298 * It contains the index for the first option that starts with a certain
8299 * letter. There are 26 letters, plus the first "t_" option.
8300 */
8301 if (quick_tab[1] == 0)
8302 {
8303 p = options[0].fullname;
8304 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8305 {
8306 if (s[0] != p[0])
8307 {
8308 if (s[0] == 't' && s[1] == '_')
8309 quick_tab[26] = opt_idx;
8310 else
8311 quick_tab[CharOrdLow(s[0])] = opt_idx;
8312 }
8313 p = s;
8314 }
8315 }
8316
8317 /*
8318 * Check for name starting with an illegal character.
8319 */
8320#ifdef EBCDIC
8321 if (!islower(arg[0]))
8322#else
8323 if (arg[0] < 'a' || arg[0] > 'z')
8324#endif
8325 return -1;
8326
8327 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8328 if (is_term_opt)
8329 opt_idx = quick_tab[26];
8330 else
8331 opt_idx = quick_tab[CharOrdLow(arg[0])];
8332 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8333 {
8334 if (STRCMP(arg, s) == 0) /* match full name */
8335 break;
8336 }
8337 if (s == NULL && !is_term_opt)
8338 {
8339 opt_idx = quick_tab[CharOrdLow(arg[0])];
8340 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8341 {
8342 s = options[opt_idx].shortname;
8343 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8344 break;
8345 s = NULL;
8346 }
8347 }
8348 if (s == NULL)
8349 opt_idx = -1;
8350 return opt_idx;
8351}
8352
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008353#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354/*
8355 * Get the value for an option.
8356 *
8357 * Returns:
8358 * Number or Toggle option: 1, *numval gets value.
8359 * String option: 0, *stringval gets allocated string.
8360 * Hidden Number or Toggle option: -1.
8361 * hidden String option: -2.
8362 * unknown option: -3.
8363 */
8364 int
8365get_option_value(name, numval, stringval, opt_flags)
8366 char_u *name;
8367 long *numval;
8368 char_u **stringval; /* NULL when only checking existance */
8369 int opt_flags;
8370{
8371 int opt_idx;
8372 char_u *varp;
8373
8374 opt_idx = findoption(name);
8375 if (opt_idx < 0) /* unknown option */
8376 return -3;
8377
8378 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8379
8380 if (options[opt_idx].flags & P_STRING)
8381 {
8382 if (varp == NULL) /* hidden option */
8383 return -2;
8384 if (stringval != NULL)
8385 {
8386#ifdef FEAT_CRYPT
8387 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008388 if ((char_u **)varp == &curbuf->b_p_key
8389 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 *stringval = vim_strsave((char_u *)"*****");
8391 else
8392#endif
8393 *stringval = vim_strsave(*(char_u **)(varp));
8394 }
8395 return 0;
8396 }
8397
8398 if (varp == NULL) /* hidden option */
8399 return -1;
8400 if (options[opt_idx].flags & P_NUM)
8401 *numval = *(long *)varp;
8402 else
8403 {
8404 /* Special case: 'modified' is b_changed, but we also want to consider
8405 * it set when 'ff' or 'fenc' changed. */
8406 if ((int *)varp == &curbuf->b_changed)
8407 *numval = curbufIsChanged();
8408 else
8409 *numval = *(int *)varp;
8410 }
8411 return 1;
8412}
8413#endif
8414
8415/*
8416 * Set the value of option "name".
8417 * Use "string" for string options, use "number" for other options.
8418 */
8419 void
8420set_option_value(name, number, string, opt_flags)
8421 char_u *name;
8422 long number;
8423 char_u *string;
8424 int opt_flags; /* OPT_LOCAL or 0 (both) */
8425{
8426 int opt_idx;
8427 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008428 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429
8430 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008431 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432 EMSG2(_("E355: Unknown option: %s"), name);
8433 else
8434 {
8435 flags = options[opt_idx].flags;
8436#ifdef HAVE_SANDBOX
8437 /* Disallow changing some options in the sandbox */
8438 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008439 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008441 return;
8442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008444 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008445 set_string_option(opt_idx, string, opt_flags);
8446 else
8447 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008448 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 if (varp != NULL) /* hidden option is not changed */
8450 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008451 if (number == 0 && string != NULL)
8452 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008453 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008454
8455 /* Either we are given a string or we are setting option
8456 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008457 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008458 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008459 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008460 {
8461 /* There's another character after zeros or the string
8462 * is empty. In both cases, we are trying to set a
8463 * num option using a string. */
8464 EMSG3(_("E521: Number required: &%s = '%s'"),
8465 name, string);
8466 return; /* do nothing as we hit an error */
8467
8468 }
8469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008471 (void)set_num_option(opt_idx, varp, number,
8472 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008474 (void)set_bool_option(opt_idx, varp, (int)number,
8475 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 }
8477 }
8478 }
8479}
8480
8481/*
8482 * Get the terminal code for a terminal option.
8483 * Returns NULL when not found.
8484 */
8485 char_u *
8486get_term_code(tname)
8487 char_u *tname;
8488{
8489 int opt_idx;
8490 char_u *varp;
8491
8492 if (tname[0] != 't' || tname[1] != '_' ||
8493 tname[2] == NUL || tname[3] == NUL)
8494 return NULL;
8495 if ((opt_idx = findoption(tname)) >= 0)
8496 {
8497 varp = get_varp(&(options[opt_idx]));
8498 if (varp != NULL)
8499 varp = *(char_u **)(varp);
8500 return varp;
8501 }
8502 return find_termcode(tname + 2);
8503}
8504
8505 char_u *
8506get_highlight_default()
8507{
8508 int i;
8509
8510 i = findoption((char_u *)"hl");
8511 if (i >= 0)
8512 return options[i].def_val[VI_DEFAULT];
8513 return (char_u *)NULL;
8514}
8515
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008516#if defined(FEAT_MBYTE) || defined(PROTO)
8517 char_u *
8518get_encoding_default()
8519{
8520 int i;
8521
8522 i = findoption((char_u *)"enc");
8523 if (i >= 0)
8524 return options[i].def_val[VI_DEFAULT];
8525 return (char_u *)NULL;
8526}
8527#endif
8528
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529/*
8530 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8531 */
8532 static int
8533find_key_option(arg)
8534 char_u *arg;
8535{
8536 int key;
8537 int modifiers;
8538
8539 /*
8540 * Don't use get_special_key_code() for t_xx, we don't want it to call
8541 * add_termcap_entry().
8542 */
8543 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8544 key = TERMCAP2KEY(arg[2], arg[3]);
8545 else
8546 {
8547 --arg; /* put arg at the '<' */
8548 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008549 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550 if (modifiers) /* can't handle modifiers here */
8551 key = 0;
8552 }
8553 return key;
8554}
8555
8556/*
8557 * if 'all' == 0: show changed options
8558 * if 'all' == 1: show all normal options
8559 * if 'all' == 2: show all terminal options
8560 */
8561 static void
8562showoptions(all, opt_flags)
8563 int all;
8564 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8565{
8566 struct vimoption *p;
8567 int col;
8568 int isterm;
8569 char_u *varp;
8570 struct vimoption **items;
8571 int item_count;
8572 int run;
8573 int row, rows;
8574 int cols;
8575 int i;
8576 int len;
8577
8578#define INC 20
8579#define GAP 3
8580
8581 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8582 PARAM_COUNT));
8583 if (items == NULL)
8584 return;
8585
8586 /* Highlight title */
8587 if (all == 2)
8588 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8589 else if (opt_flags & OPT_GLOBAL)
8590 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8591 else if (opt_flags & OPT_LOCAL)
8592 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8593 else
8594 MSG_PUTS_TITLE(_("\n--- Options ---"));
8595
8596 /*
8597 * do the loop two times:
8598 * 1. display the short items
8599 * 2. display the long items (only strings and numbers)
8600 */
8601 for (run = 1; run <= 2 && !got_int; ++run)
8602 {
8603 /*
8604 * collect the items in items[]
8605 */
8606 item_count = 0;
8607 for (p = &options[0]; p->fullname != NULL; p++)
8608 {
8609 varp = NULL;
8610 isterm = istermoption(p);
8611 if (opt_flags != 0)
8612 {
8613 if (p->indir != PV_NONE && !isterm)
8614 varp = get_varp_scope(p, opt_flags);
8615 }
8616 else
8617 varp = get_varp(p);
8618 if (varp != NULL
8619 && ((all == 2 && isterm)
8620 || (all == 1 && !isterm)
8621 || (all == 0 && !optval_default(p, varp))))
8622 {
8623 if (p->flags & P_BOOL)
8624 len = 1; /* a toggle option fits always */
8625 else
8626 {
8627 option_value2string(p, opt_flags);
8628 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8629 }
8630 if ((len <= INC - GAP && run == 1) ||
8631 (len > INC - GAP && run == 2))
8632 items[item_count++] = p;
8633 }
8634 }
8635
8636 /*
8637 * display the items
8638 */
8639 if (run == 1)
8640 {
8641 cols = (Columns + GAP - 3) / INC;
8642 if (cols == 0)
8643 cols = 1;
8644 rows = (item_count + cols - 1) / cols;
8645 }
8646 else /* run == 2 */
8647 rows = item_count;
8648 for (row = 0; row < rows && !got_int; ++row)
8649 {
8650 msg_putchar('\n'); /* go to next line */
8651 if (got_int) /* 'q' typed in more */
8652 break;
8653 col = 0;
8654 for (i = row; i < item_count; i += rows)
8655 {
8656 msg_col = col; /* make columns */
8657 showoneopt(items[i], opt_flags);
8658 col += INC;
8659 }
8660 out_flush();
8661 ui_breakcheck();
8662 }
8663 }
8664 vim_free(items);
8665}
8666
8667/*
8668 * Return TRUE if option "p" has its default value.
8669 */
8670 static int
8671optval_default(p, varp)
8672 struct vimoption *p;
8673 char_u *varp;
8674{
8675 int dvi;
8676
8677 if (varp == NULL)
8678 return TRUE; /* hidden option is always at default */
8679 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8680 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008681 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008683 /* the cast to long is required for Manx C, long_i is
8684 * needed for MSVC */
8685 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686 /* P_STRING */
8687 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8688}
8689
8690/*
8691 * showoneopt: show the value of one option
8692 * must not be called with a hidden option!
8693 */
8694 static void
8695showoneopt(p, opt_flags)
8696 struct vimoption *p;
8697 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8698{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008699 char_u *varp;
8700 int save_silent = silent_mode;
8701
8702 silent_mode = FALSE;
8703 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704
8705 varp = get_varp_scope(p, opt_flags);
8706
8707 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8708 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8709 ? !curbufIsChanged() : !*(int *)varp))
8710 MSG_PUTS("no");
8711 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8712 MSG_PUTS("--");
8713 else
8714 MSG_PUTS(" ");
8715 MSG_PUTS(p->fullname);
8716 if (!(p->flags & P_BOOL))
8717 {
8718 msg_putchar('=');
8719 /* put value string in NameBuff */
8720 option_value2string(p, opt_flags);
8721 msg_outtrans(NameBuff);
8722 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008723
8724 silent_mode = save_silent;
8725 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726}
8727
8728/*
8729 * Write modified options as ":set" commands to a file.
8730 *
8731 * There are three values for "opt_flags":
8732 * OPT_GLOBAL: Write global option values and fresh values of
8733 * buffer-local options (used for start of a session
8734 * file).
8735 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8736 * curwin (used for a vimrc file).
8737 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8738 * and local values for window-local options of
8739 * curwin. Local values are also written when at the
8740 * default value, because a modeline or autocommand
8741 * may have set them when doing ":edit file" and the
8742 * user has set them back at the default or fresh
8743 * value.
8744 * When "local_only" is TRUE, don't write fresh
8745 * values, only local values (for ":mkview").
8746 * (fresh value = value used for a new buffer or window for a local option).
8747 *
8748 * Return FAIL on error, OK otherwise.
8749 */
8750 int
8751makeset(fd, opt_flags, local_only)
8752 FILE *fd;
8753 int opt_flags;
8754 int local_only;
8755{
8756 struct vimoption *p;
8757 char_u *varp; /* currently used value */
8758 char_u *varp_fresh; /* local value */
8759 char_u *varp_local = NULL; /* fresh value */
8760 char *cmd;
8761 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008762 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763
8764 /*
8765 * The options that don't have a default (terminal name, columns, lines)
8766 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008767 * Do the loop over "options[]" twice: once for options with the
8768 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008770 for (pri = 1; pri >= 0; --pri)
8771 {
8772 for (p = &options[0]; !istermoption(p); p++)
8773 if (!(p->flags & P_NO_MKRC)
8774 && !istermoption(p)
8775 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 {
8777 /* skip global option when only doing locals */
8778 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8779 continue;
8780
8781 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8782 * file, they are always buffer-specific. */
8783 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8784 continue;
8785
8786 /* Global values are only written when not at the default value. */
8787 varp = get_varp_scope(p, opt_flags);
8788 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8789 continue;
8790
8791 round = 2;
8792 if (p->indir != PV_NONE)
8793 {
8794 if (p->var == VAR_WIN)
8795 {
8796 /* skip window-local option when only doing globals */
8797 if (!(opt_flags & OPT_LOCAL))
8798 continue;
8799 /* When fresh value of window-local option is not at the
8800 * default, need to write it too. */
8801 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8802 {
8803 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8804 if (!optval_default(p, varp_fresh))
8805 {
8806 round = 1;
8807 varp_local = varp;
8808 varp = varp_fresh;
8809 }
8810 }
8811 }
8812 }
8813
8814 /* Round 1: fresh value for window-local options.
8815 * Round 2: other values */
8816 for ( ; round <= 2; varp = varp_local, ++round)
8817 {
8818 if (round == 1 || (opt_flags & OPT_GLOBAL))
8819 cmd = "set";
8820 else
8821 cmd = "setlocal";
8822
8823 if (p->flags & P_BOOL)
8824 {
8825 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8826 return FAIL;
8827 }
8828 else if (p->flags & P_NUM)
8829 {
8830 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8831 return FAIL;
8832 }
8833 else /* P_STRING */
8834 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008835#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8836 int do_endif = FALSE;
8837
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 /* Don't set 'syntax' and 'filetype' again if the value is
8839 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008840 if (
8841# if defined(FEAT_SYN_HL)
8842 p->indir == PV_SYN
8843# if defined(FEAT_AUTOCMD)
8844 ||
8845# endif
8846# endif
8847# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008848 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008849# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008850 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 {
8852 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8853 *(char_u **)(varp)) < 0
8854 || put_eol(fd) < 0)
8855 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008856 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008858#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8860 (p->flags & P_EXPAND) != 0) == FAIL)
8861 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008862#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8863 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 {
8865 if (put_line(fd, "endif") == FAIL)
8866 return FAIL;
8867 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 }
8870 }
8871 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873 return OK;
8874}
8875
8876#if defined(FEAT_FOLDING) || defined(PROTO)
8877/*
8878 * Generate set commands for the local fold options only. Used when
8879 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8880 */
8881 int
8882makefoldset(fd)
8883 FILE *fd;
8884{
8885 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8886# ifdef FEAT_EVAL
8887 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8888 == FAIL
8889# endif
8890 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8891 == FAIL
8892 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8893 == FAIL
8894 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8895 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8896 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8897 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8898 )
8899 return FAIL;
8900
8901 return OK;
8902}
8903#endif
8904
8905 static int
8906put_setstring(fd, cmd, name, valuep, expand)
8907 FILE *fd;
8908 char *cmd;
8909 char *name;
8910 char_u **valuep;
8911 int expand;
8912{
8913 char_u *s;
8914 char_u buf[MAXPATHL];
8915
8916 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8917 return FAIL;
8918 if (*valuep != NULL)
8919 {
8920 /* Output 'pastetoggle' as key names. For other
8921 * options some characters have to be escaped with
8922 * CTRL-V or backslash */
8923 if (valuep == &p_pt)
8924 {
8925 s = *valuep;
8926 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00008927 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 return FAIL;
8929 }
8930 else if (expand)
8931 {
8932 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8933 if (put_escstr(fd, buf, 2) == FAIL)
8934 return FAIL;
8935 }
8936 else if (put_escstr(fd, *valuep, 2) == FAIL)
8937 return FAIL;
8938 }
8939 if (put_eol(fd) < 0)
8940 return FAIL;
8941 return OK;
8942}
8943
8944 static int
8945put_setnum(fd, cmd, name, valuep)
8946 FILE *fd;
8947 char *cmd;
8948 char *name;
8949 long *valuep;
8950{
8951 long wc;
8952
8953 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8954 return FAIL;
8955 if (wc_use_keyname((char_u *)valuep, &wc))
8956 {
8957 /* print 'wildchar' and 'wildcharm' as a key name */
8958 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8959 return FAIL;
8960 }
8961 else if (fprintf(fd, "%ld", *valuep) < 0)
8962 return FAIL;
8963 if (put_eol(fd) < 0)
8964 return FAIL;
8965 return OK;
8966}
8967
8968 static int
8969put_setbool(fd, cmd, name, value)
8970 FILE *fd;
8971 char *cmd;
8972 char *name;
8973 int value;
8974{
Bram Moolenaar893de922007-10-02 18:40:57 +00008975 if (value < 0) /* global/local option using global value */
8976 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8978 || put_eol(fd) < 0)
8979 return FAIL;
8980 return OK;
8981}
8982
8983/*
8984 * Clear all the terminal options.
8985 * If the option has been allocated, free the memory.
8986 * Terminal options are never hidden or indirect.
8987 */
8988 void
8989clear_termoptions()
8990{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 /*
8992 * Reset a few things before clearing the old options. This may cause
8993 * outputting a few things that the terminal doesn't understand, but the
8994 * screen will be cleared later, so this is OK.
8995 */
8996#ifdef FEAT_MOUSE_TTY
8997 mch_setmouse(FALSE); /* switch mouse off */
8998#endif
8999#ifdef FEAT_TITLE
9000 mch_restore_title(3); /* restore window titles */
9001#endif
9002#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9003 /* When starting the GUI close the display opened for the clipboard.
9004 * After restoring the title, because that will need the display. */
9005 if (gui.starting)
9006 clear_xterm_clip();
9007#endif
9008#ifdef WIN3264
9009 /*
9010 * Check if this is allowed now.
9011 */
9012 if (can_end_termcap_mode(FALSE) == TRUE)
9013#endif
9014 stoptermcap(); /* stop termcap mode */
9015
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009016 free_termoptions();
9017}
9018
9019 void
9020free_termoptions()
9021{
9022 struct vimoption *p;
9023
Bram Moolenaar071d4272004-06-13 20:20:40 +00009024 for (p = &options[0]; p->fullname != NULL; p++)
9025 if (istermoption(p))
9026 {
9027 if (p->flags & P_ALLOCED)
9028 free_string_option(*(char_u **)(p->var));
9029 if (p->flags & P_DEF_ALLOCED)
9030 free_string_option(p->def_val[VI_DEFAULT]);
9031 *(char_u **)(p->var) = empty_option;
9032 p->def_val[VI_DEFAULT] = empty_option;
9033 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9034 }
9035 clear_termcodes();
9036}
9037
9038/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009039 * Free the string for one term option, if it was allocated.
9040 * Set the string to empty_option and clear allocated flag.
9041 * "var" points to the option value.
9042 */
9043 void
9044free_one_termoption(var)
9045 char_u *var;
9046{
9047 struct vimoption *p;
9048
9049 for (p = &options[0]; p->fullname != NULL; p++)
9050 if (p->var == var)
9051 {
9052 if (p->flags & P_ALLOCED)
9053 free_string_option(*(char_u **)(p->var));
9054 *(char_u **)(p->var) = empty_option;
9055 p->flags &= ~P_ALLOCED;
9056 break;
9057 }
9058}
9059
9060/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 * Set the terminal option defaults to the current value.
9062 * Used after setting the terminal name.
9063 */
9064 void
9065set_term_defaults()
9066{
9067 struct vimoption *p;
9068
9069 for (p = &options[0]; p->fullname != NULL; p++)
9070 {
9071 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9072 {
9073 if (p->flags & P_DEF_ALLOCED)
9074 {
9075 free_string_option(p->def_val[VI_DEFAULT]);
9076 p->flags &= ~P_DEF_ALLOCED;
9077 }
9078 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9079 if (p->flags & P_ALLOCED)
9080 {
9081 p->flags |= P_DEF_ALLOCED;
9082 p->flags &= ~P_ALLOCED; /* don't free the value now */
9083 }
9084 }
9085 }
9086}
9087
9088/*
9089 * return TRUE if 'p' starts with 't_'
9090 */
9091 static int
9092istermoption(p)
9093 struct vimoption *p;
9094{
9095 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9096}
9097
9098/*
9099 * Compute columns for ruler and shown command. 'sc_col' is also used to
9100 * decide what the maximum length of a message on the status line can be.
9101 * If there is a status line for the last window, 'sc_col' is independent
9102 * of 'ru_col'.
9103 */
9104
9105#define COL_RULER 17 /* columns needed by standard ruler */
9106
9107 void
9108comp_col()
9109{
9110#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9111 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9112
9113 sc_col = 0;
9114 ru_col = 0;
9115 if (p_ru)
9116 {
9117#ifdef FEAT_STL_OPT
9118 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9119#else
9120 ru_col = COL_RULER + 1;
9121#endif
9122 /* no last status line, adjust sc_col */
9123 if (!last_has_status)
9124 sc_col = ru_col;
9125 }
9126 if (p_sc)
9127 {
9128 sc_col += SHOWCMD_COLS;
9129 if (!p_ru || last_has_status) /* no need for separating space */
9130 ++sc_col;
9131 }
9132 sc_col = Columns - sc_col;
9133 ru_col = Columns - ru_col;
9134 if (sc_col <= 0) /* screen too narrow, will become a mess */
9135 sc_col = 1;
9136 if (ru_col <= 0)
9137 ru_col = 1;
9138#else
9139 sc_col = Columns;
9140 ru_col = Columns;
9141#endif
9142}
9143
9144/*
9145 * Get pointer to option variable, depending on local or global scope.
9146 */
9147 static char_u *
9148get_varp_scope(p, opt_flags)
9149 struct vimoption *p;
9150 int opt_flags;
9151{
9152 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9153 {
9154 if (p->var == VAR_WIN)
9155 return (char_u *)GLOBAL_WO(get_varp(p));
9156 return p->var;
9157 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009158 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 {
9160 switch ((int)p->indir)
9161 {
9162#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009163 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9164 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9165 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009167 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9168 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9169 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009170 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009171 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009173 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9174 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175#endif
9176#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009177 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9178 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009180#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9181 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9182#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009183#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009184 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 }
9187 return NULL; /* "cannot happen" */
9188 }
9189 return get_varp(p);
9190}
9191
9192/*
9193 * Get pointer to option variable.
9194 */
9195 static char_u *
9196get_varp(p)
9197 struct vimoption *p;
9198{
9199 /* hidden option, always return NULL */
9200 if (p->var == NULL)
9201 return NULL;
9202
9203 switch ((int)p->indir)
9204 {
9205 case PV_NONE: return p->var;
9206
9207 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009208 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009209 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009210 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009211 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009212 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009214 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009216 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9218#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009219 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009221 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009222 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9223#endif
9224#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009225 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009226 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009227 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9229#endif
9230#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009231 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009233 case PV_GP: return *curbuf->b_p_gp != NUL
9234 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9235 case PV_MP: return *curbuf->b_p_mp != NUL
9236 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009238#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9239 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9240 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9241#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009242#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009243 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009244 ? (char_u *)&(curwin->w_p_stl) : p->var;
9245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246
9247#ifdef FEAT_ARABIC
9248 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9249#endif
9250 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009251#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009252 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9253#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009254#ifdef FEAT_SYN_HL
9255 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9256 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258#ifdef FEAT_DIFF
9259 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9260#endif
9261#ifdef FEAT_FOLDING
9262 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9263 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9264 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9265 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9266 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9267 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9268 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9269# ifdef FEAT_EVAL
9270 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9271 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9272# endif
9273 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9274#endif
9275 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009276 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009277#ifdef FEAT_LINEBREAK
9278 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9279#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009280#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009281 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9282#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009283#ifdef FEAT_VERTSPLIT
9284 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009286#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9287 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9288#endif
9289#ifdef FEAT_RIGHTLEFT
9290 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9291 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9292#endif
9293 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9294 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9295#ifdef FEAT_LINEBREAK
9296 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9297#endif
9298#ifdef FEAT_SCROLLBIND
9299 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9300#endif
9301
9302 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9303 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9304#ifdef FEAT_MBYTE
9305 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9306#endif
9307#if defined(FEAT_QUICKFIX)
9308 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9309 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9310#endif
9311 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9312 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9313#ifdef FEAT_CINDENT
9314 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9315 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9316 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9317#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009318#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009319 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9322 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9323#endif
9324#ifdef FEAT_COMMENTS
9325 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9326#endif
9327#ifdef FEAT_FOLDING
9328 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9329#endif
9330#ifdef FEAT_INS_EXPAND
9331 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9332#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009333#ifdef FEAT_COMPL_FUNC
9334 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009335 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9338 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9339#ifdef FEAT_MBYTE
9340 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9341#endif
9342 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9343#ifdef FEAT_AUTOCMD
9344 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9345#endif
9346 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009347 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009348 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9349 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9350 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9351 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9352#ifdef FEAT_FIND_ID
9353# ifdef FEAT_EVAL
9354 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9355# endif
9356#endif
9357#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9358 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9359 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9360#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009361#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009362 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364#ifdef FEAT_CRYPT
9365 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9366#endif
9367#ifdef FEAT_LISP
9368 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9369#endif
9370 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9371 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9372 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9373 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9374 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9375#ifdef FEAT_OSFILETYPE
9376 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9377#endif
9378 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009379#ifdef FEAT_TEXTOBJ
9380 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9383#ifdef FEAT_SMARTINDENT
9384 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9385#endif
9386#ifndef SHORT_FNAME
9387 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9388#endif
9389 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9390#ifdef FEAT_SEARCHPATH
9391 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9392#endif
9393 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9394#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009395 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009396 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9397#endif
9398#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009399 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009400 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009401 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402#endif
9403 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9404 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9405 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9406 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9407 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9408#ifdef FEAT_KEYMAP
9409 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9410#endif
9411 default: EMSG(_("E356: get_varp ERROR"));
9412 }
9413 /* always return a valid pointer to avoid a crash! */
9414 return (char_u *)&(curbuf->b_p_wm);
9415}
9416
9417/*
9418 * Get the value of 'equalprg', either the buffer-local one or the global one.
9419 */
9420 char_u *
9421get_equalprg()
9422{
9423 if (*curbuf->b_p_ep == NUL)
9424 return p_ep;
9425 return curbuf->b_p_ep;
9426}
9427
9428#if defined(FEAT_WINDOWS) || defined(PROTO)
9429/*
9430 * Copy options from one window to another.
9431 * Used when splitting a window.
9432 */
9433 void
9434win_copy_options(wp_from, wp_to)
9435 win_T *wp_from;
9436 win_T *wp_to;
9437{
9438 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9439 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9440# ifdef FEAT_RIGHTLEFT
9441# ifdef FEAT_FKMAP
9442 /* Is this right? */
9443 wp_to->w_farsi = wp_from->w_farsi;
9444# endif
9445# endif
9446}
9447#endif
9448
9449/*
9450 * Copy the options from one winopt_T to another.
9451 * Doesn't free the old option values in "to", use clear_winopt() for that.
9452 * The 'scroll' option is not copied, because it depends on the window height.
9453 * The 'previewwindow' option is reset, there can be only one preview window.
9454 */
9455 void
9456copy_winopt(from, to)
9457 winopt_T *from;
9458 winopt_T *to;
9459{
9460#ifdef FEAT_ARABIC
9461 to->wo_arab = from->wo_arab;
9462#endif
9463 to->wo_list = from->wo_list;
9464 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009465 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009466#ifdef FEAT_LINEBREAK
9467 to->wo_nuw = from->wo_nuw;
9468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469#ifdef FEAT_RIGHTLEFT
9470 to->wo_rl = from->wo_rl;
9471 to->wo_rlc = vim_strsave(from->wo_rlc);
9472#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009473#ifdef FEAT_STL_OPT
9474 to->wo_stl = vim_strsave(from->wo_stl);
9475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 to->wo_wrap = from->wo_wrap;
9477#ifdef FEAT_LINEBREAK
9478 to->wo_lbr = from->wo_lbr;
9479#endif
9480#ifdef FEAT_SCROLLBIND
9481 to->wo_scb = from->wo_scb;
9482#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009483#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009484 to->wo_spell = from->wo_spell;
9485#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009486#ifdef FEAT_SYN_HL
9487 to->wo_cuc = from->wo_cuc;
9488 to->wo_cul = from->wo_cul;
9489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490#ifdef FEAT_DIFF
9491 to->wo_diff = from->wo_diff;
9492#endif
9493#ifdef FEAT_FOLDING
9494 to->wo_fdc = from->wo_fdc;
9495 to->wo_fen = from->wo_fen;
9496 to->wo_fdi = vim_strsave(from->wo_fdi);
9497 to->wo_fml = from->wo_fml;
9498 to->wo_fdl = from->wo_fdl;
9499 to->wo_fdm = vim_strsave(from->wo_fdm);
9500 to->wo_fdn = from->wo_fdn;
9501# ifdef FEAT_EVAL
9502 to->wo_fde = vim_strsave(from->wo_fde);
9503 to->wo_fdt = vim_strsave(from->wo_fdt);
9504# endif
9505 to->wo_fmr = vim_strsave(from->wo_fmr);
9506#endif
9507 check_winopt(to); /* don't want NULL pointers */
9508}
9509
9510/*
9511 * Check string options in a window for a NULL value.
9512 */
9513 void
9514check_win_options(win)
9515 win_T *win;
9516{
9517 check_winopt(&win->w_onebuf_opt);
9518 check_winopt(&win->w_allbuf_opt);
9519}
9520
9521/*
9522 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9523 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009524 void
9525check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009526 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527{
9528#ifdef FEAT_FOLDING
9529 check_string_option(&wop->wo_fdi);
9530 check_string_option(&wop->wo_fdm);
9531# ifdef FEAT_EVAL
9532 check_string_option(&wop->wo_fde);
9533 check_string_option(&wop->wo_fdt);
9534# endif
9535 check_string_option(&wop->wo_fmr);
9536#endif
9537#ifdef FEAT_RIGHTLEFT
9538 check_string_option(&wop->wo_rlc);
9539#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009540#ifdef FEAT_STL_OPT
9541 check_string_option(&wop->wo_stl);
9542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543}
9544
9545/*
9546 * Free the allocated memory inside a winopt_T.
9547 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009548 void
9549clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009550 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551{
9552#ifdef FEAT_FOLDING
9553 clear_string_option(&wop->wo_fdi);
9554 clear_string_option(&wop->wo_fdm);
9555# ifdef FEAT_EVAL
9556 clear_string_option(&wop->wo_fde);
9557 clear_string_option(&wop->wo_fdt);
9558# endif
9559 clear_string_option(&wop->wo_fmr);
9560#endif
9561#ifdef FEAT_RIGHTLEFT
9562 clear_string_option(&wop->wo_rlc);
9563#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009564#ifdef FEAT_STL_OPT
9565 clear_string_option(&wop->wo_stl);
9566#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567}
9568
9569/*
9570 * Copy global option values to local options for one buffer.
9571 * Used when creating a new buffer and sometimes when entering a buffer.
9572 * flags:
9573 * BCO_ENTER We will enter the buf buffer.
9574 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9575 * appropriate.
9576 * BCO_NOHELP Don't copy the values to a help buffer.
9577 */
9578 void
9579buf_copy_options(buf, flags)
9580 buf_T *buf;
9581 int flags;
9582{
9583 int should_copy = TRUE;
9584 char_u *save_p_isk = NULL; /* init for GCC */
9585 int dont_do_help;
9586 int did_isk = FALSE;
9587
9588 /*
9589 * Don't do anything of the buffer is invalid.
9590 */
9591 if (buf == NULL || !buf_valid(buf))
9592 return;
9593
9594 /*
9595 * Skip this when the option defaults have not been set yet. Happens when
9596 * main() allocates the first buffer.
9597 */
9598 if (p_cpo != NULL)
9599 {
9600 /*
9601 * Always copy when entering and 'cpo' contains 'S'.
9602 * Don't copy when already initialized.
9603 * Don't copy when 'cpo' contains 's' and not entering.
9604 * 'S' BCO_ENTER initialized 's' should_copy
9605 * yes yes X X TRUE
9606 * yes no yes X FALSE
9607 * no X yes X FALSE
9608 * X no no yes FALSE
9609 * X no no no TRUE
9610 * no yes no X TRUE
9611 */
9612 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9613 && (buf->b_p_initialized
9614 || (!(flags & BCO_ENTER)
9615 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9616 should_copy = FALSE;
9617
9618 if (should_copy || (flags & BCO_ALWAYS))
9619 {
9620 /* Don't copy the options specific to a help buffer when
9621 * BCO_NOHELP is given or the options were initialized already
9622 * (jumping back to a help file with CTRL-T or CTRL-O) */
9623 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9624 || buf->b_p_initialized;
9625 if (dont_do_help) /* don't free b_p_isk */
9626 {
9627 save_p_isk = buf->b_p_isk;
9628 buf->b_p_isk = NULL;
9629 }
9630 /*
9631 * Always free the allocated strings.
9632 * If not already initialized, set 'readonly' and copy 'fileformat'.
9633 */
9634 if (!buf->b_p_initialized)
9635 {
9636 free_buf_options(buf, TRUE);
9637 buf->b_p_ro = FALSE; /* don't copy readonly */
9638 buf->b_p_tx = p_tx;
9639#ifdef FEAT_MBYTE
9640 buf->b_p_fenc = vim_strsave(p_fenc);
9641#endif
9642 buf->b_p_ff = vim_strsave(p_ff);
9643#if defined(FEAT_QUICKFIX)
9644 buf->b_p_bh = empty_option;
9645 buf->b_p_bt = empty_option;
9646#endif
9647 }
9648 else
9649 free_buf_options(buf, FALSE);
9650
9651 buf->b_p_ai = p_ai;
9652 buf->b_p_ai_nopaste = p_ai_nopaste;
9653 buf->b_p_sw = p_sw;
9654 buf->b_p_tw = p_tw;
9655 buf->b_p_tw_nopaste = p_tw_nopaste;
9656 buf->b_p_tw_nobin = p_tw_nobin;
9657 buf->b_p_wm = p_wm;
9658 buf->b_p_wm_nopaste = p_wm_nopaste;
9659 buf->b_p_wm_nobin = p_wm_nobin;
9660 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009661#ifdef FEAT_MBYTE
9662 buf->b_p_bomb = p_bomb;
9663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664 buf->b_p_et = p_et;
9665 buf->b_p_et_nobin = p_et_nobin;
9666 buf->b_p_ml = p_ml;
9667 buf->b_p_ml_nobin = p_ml_nobin;
9668 buf->b_p_inf = p_inf;
9669 buf->b_p_swf = p_swf;
9670#ifdef FEAT_INS_EXPAND
9671 buf->b_p_cpt = vim_strsave(p_cpt);
9672#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009673#ifdef FEAT_COMPL_FUNC
9674 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009675 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009677 buf->b_p_sts = p_sts;
9678 buf->b_p_sts_nopaste = p_sts_nopaste;
9679#ifndef SHORT_FNAME
9680 buf->b_p_sn = p_sn;
9681#endif
9682#ifdef FEAT_COMMENTS
9683 buf->b_p_com = vim_strsave(p_com);
9684#endif
9685#ifdef FEAT_FOLDING
9686 buf->b_p_cms = vim_strsave(p_cms);
9687#endif
9688 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009689 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 buf->b_p_nf = vim_strsave(p_nf);
9691 buf->b_p_mps = vim_strsave(p_mps);
9692#ifdef FEAT_SMARTINDENT
9693 buf->b_p_si = p_si;
9694#endif
9695 buf->b_p_ci = p_ci;
9696#ifdef FEAT_CINDENT
9697 buf->b_p_cin = p_cin;
9698 buf->b_p_cink = vim_strsave(p_cink);
9699 buf->b_p_cino = vim_strsave(p_cino);
9700#endif
9701#ifdef FEAT_AUTOCMD
9702 /* Don't copy 'filetype', it must be detected */
9703 buf->b_p_ft = empty_option;
9704#endif
9705#ifdef FEAT_OSFILETYPE
9706 buf->b_p_oft = vim_strsave(p_oft);
9707#endif
9708 buf->b_p_pi = p_pi;
9709#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9710 buf->b_p_cinw = vim_strsave(p_cinw);
9711#endif
9712#ifdef FEAT_LISP
9713 buf->b_p_lisp = p_lisp;
9714#endif
9715#ifdef FEAT_SYN_HL
9716 /* Don't copy 'syntax', it must be set */
9717 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009718 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009719#endif
9720#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009721 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009722 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009723 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009724 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725#endif
9726#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9727 buf->b_p_inde = vim_strsave(p_inde);
9728 buf->b_p_indk = vim_strsave(p_indk);
9729#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009730#if defined(FEAT_EVAL)
9731 buf->b_p_fex = vim_strsave(p_fex);
9732#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733#ifdef FEAT_CRYPT
9734 buf->b_p_key = vim_strsave(p_key);
9735#endif
9736#ifdef FEAT_SEARCHPATH
9737 buf->b_p_sua = vim_strsave(p_sua);
9738#endif
9739#ifdef FEAT_KEYMAP
9740 buf->b_p_keymap = vim_strsave(p_keymap);
9741 buf->b_kmap_state |= KEYMAP_INIT;
9742#endif
9743 /* This isn't really an option, but copying the langmap and IME
9744 * state from the current buffer is better than resetting it. */
9745 buf->b_p_iminsert = p_iminsert;
9746 buf->b_p_imsearch = p_imsearch;
9747
9748 /* options that are normally global but also have a local value
9749 * are not copied, start using the global value */
9750 buf->b_p_ar = -1;
9751#ifdef FEAT_QUICKFIX
9752 buf->b_p_gp = empty_option;
9753 buf->b_p_mp = empty_option;
9754 buf->b_p_efm = empty_option;
9755#endif
9756 buf->b_p_ep = empty_option;
9757 buf->b_p_kp = empty_option;
9758 buf->b_p_path = empty_option;
9759 buf->b_p_tags = empty_option;
9760#ifdef FEAT_FIND_ID
9761 buf->b_p_def = empty_option;
9762 buf->b_p_inc = empty_option;
9763# ifdef FEAT_EVAL
9764 buf->b_p_inex = vim_strsave(p_inex);
9765# endif
9766#endif
9767#ifdef FEAT_INS_EXPAND
9768 buf->b_p_dict = empty_option;
9769 buf->b_p_tsr = empty_option;
9770#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009771#ifdef FEAT_TEXTOBJ
9772 buf->b_p_qe = vim_strsave(p_qe);
9773#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009774#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9775 buf->b_p_bexpr = empty_option;
9776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777
9778 /*
9779 * Don't copy the options set by ex_help(), use the saved values,
9780 * when going from a help buffer to a non-help buffer.
9781 * Don't touch these at all when BCO_NOHELP is used and going from
9782 * or to a help buffer.
9783 */
9784 if (dont_do_help)
9785 buf->b_p_isk = save_p_isk;
9786 else
9787 {
9788 buf->b_p_isk = vim_strsave(p_isk);
9789 did_isk = TRUE;
9790 buf->b_p_ts = p_ts;
9791 buf->b_help = FALSE;
9792#ifdef FEAT_QUICKFIX
9793 if (buf->b_p_bt[0] == 'h')
9794 clear_string_option(&buf->b_p_bt);
9795#endif
9796 buf->b_p_ma = p_ma;
9797 }
9798 }
9799
9800 /*
9801 * When the options should be copied (ignoring BCO_ALWAYS), set the
9802 * flag that indicates that the options have been initialized.
9803 */
9804 if (should_copy)
9805 buf->b_p_initialized = TRUE;
9806 }
9807
9808 check_buf_options(buf); /* make sure we don't have NULLs */
9809 if (did_isk)
9810 (void)buf_init_chartab(buf, FALSE);
9811}
9812
9813/*
9814 * Reset the 'modifiable' option and its default value.
9815 */
9816 void
9817reset_modifiable()
9818{
9819 int opt_idx;
9820
9821 curbuf->b_p_ma = FALSE;
9822 p_ma = FALSE;
9823 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009824 if (opt_idx >= 0)
9825 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826}
9827
9828/*
9829 * Set the global value for 'iminsert' to the local value.
9830 */
9831 void
9832set_iminsert_global()
9833{
9834 p_iminsert = curbuf->b_p_iminsert;
9835}
9836
9837/*
9838 * Set the global value for 'imsearch' to the local value.
9839 */
9840 void
9841set_imsearch_global()
9842{
9843 p_imsearch = curbuf->b_p_imsearch;
9844}
9845
9846#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9847static int expand_option_idx = -1;
9848static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9849static int expand_option_flags = 0;
9850
9851 void
9852set_context_in_set_cmd(xp, arg, opt_flags)
9853 expand_T *xp;
9854 char_u *arg;
9855 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9856{
9857 int nextchar;
9858 long_u flags = 0; /* init for GCC */
9859 int opt_idx = 0; /* init for GCC */
9860 char_u *p;
9861 char_u *s;
9862 int is_term_option = FALSE;
9863 int key;
9864
9865 expand_option_flags = opt_flags;
9866
9867 xp->xp_context = EXPAND_SETTINGS;
9868 if (*arg == NUL)
9869 {
9870 xp->xp_pattern = arg;
9871 return;
9872 }
9873 p = arg + STRLEN(arg) - 1;
9874 if (*p == ' ' && *(p - 1) != '\\')
9875 {
9876 xp->xp_pattern = p + 1;
9877 return;
9878 }
9879 while (p > arg)
9880 {
9881 s = p;
9882 /* count number of backslashes before ' ' or ',' */
9883 if (*p == ' ' || *p == ',')
9884 {
9885 while (s > arg && *(s - 1) == '\\')
9886 --s;
9887 }
9888 /* break at a space with an even number of backslashes */
9889 if (*p == ' ' && ((p - s) & 1) == 0)
9890 {
9891 ++p;
9892 break;
9893 }
9894 --p;
9895 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00009896 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 {
9898 xp->xp_context = EXPAND_BOOL_SETTINGS;
9899 p += 2;
9900 }
9901 if (STRNCMP(p, "inv", 3) == 0)
9902 {
9903 xp->xp_context = EXPAND_BOOL_SETTINGS;
9904 p += 3;
9905 }
9906 xp->xp_pattern = arg = p;
9907 if (*arg == '<')
9908 {
9909 while (*p != '>')
9910 if (*p++ == NUL) /* expand terminal option name */
9911 return;
9912 key = get_special_key_code(arg + 1);
9913 if (key == 0) /* unknown name */
9914 {
9915 xp->xp_context = EXPAND_NOTHING;
9916 return;
9917 }
9918 nextchar = *++p;
9919 is_term_option = TRUE;
9920 expand_option_name[2] = KEY2TERMCAP0(key);
9921 expand_option_name[3] = KEY2TERMCAP1(key);
9922 }
9923 else
9924 {
9925 if (p[0] == 't' && p[1] == '_')
9926 {
9927 p += 2;
9928 if (*p != NUL)
9929 ++p;
9930 if (*p == NUL)
9931 return; /* expand option name */
9932 nextchar = *++p;
9933 is_term_option = TRUE;
9934 expand_option_name[2] = p[-2];
9935 expand_option_name[3] = p[-1];
9936 }
9937 else
9938 {
9939 /* Allow * wildcard */
9940 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9941 p++;
9942 if (*p == NUL)
9943 return;
9944 nextchar = *p;
9945 *p = NUL;
9946 opt_idx = findoption(arg);
9947 *p = nextchar;
9948 if (opt_idx == -1 || options[opt_idx].var == NULL)
9949 {
9950 xp->xp_context = EXPAND_NOTHING;
9951 return;
9952 }
9953 flags = options[opt_idx].flags;
9954 if (flags & P_BOOL)
9955 {
9956 xp->xp_context = EXPAND_NOTHING;
9957 return;
9958 }
9959 }
9960 }
9961 /* handle "-=" and "+=" */
9962 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9963 {
9964 ++p;
9965 nextchar = '=';
9966 }
9967 if ((nextchar != '=' && nextchar != ':')
9968 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9969 {
9970 xp->xp_context = EXPAND_UNSUCCESSFUL;
9971 return;
9972 }
9973 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9974 {
9975 xp->xp_context = EXPAND_OLD_SETTING;
9976 if (is_term_option)
9977 expand_option_idx = -1;
9978 else
9979 expand_option_idx = opt_idx;
9980 xp->xp_pattern = p + 1;
9981 return;
9982 }
9983 xp->xp_context = EXPAND_NOTHING;
9984 if (is_term_option || (flags & P_NUM))
9985 return;
9986
9987 xp->xp_pattern = p + 1;
9988
9989 if (flags & P_EXPAND)
9990 {
9991 p = options[opt_idx].var;
9992 if (p == (char_u *)&p_bdir
9993 || p == (char_u *)&p_dir
9994 || p == (char_u *)&p_path
9995 || p == (char_u *)&p_rtp
9996#ifdef FEAT_SEARCHPATH
9997 || p == (char_u *)&p_cdpath
9998#endif
9999#ifdef FEAT_SESSION
10000 || p == (char_u *)&p_vdir
10001#endif
10002 )
10003 {
10004 xp->xp_context = EXPAND_DIRECTORIES;
10005 if (p == (char_u *)&p_path
10006#ifdef FEAT_SEARCHPATH
10007 || p == (char_u *)&p_cdpath
10008#endif
10009 )
10010 xp->xp_backslash = XP_BS_THREE;
10011 else
10012 xp->xp_backslash = XP_BS_ONE;
10013 }
10014 else
10015 {
10016 xp->xp_context = EXPAND_FILES;
10017 /* for 'tags' need three backslashes for a space */
10018 if (p == (char_u *)&p_tags)
10019 xp->xp_backslash = XP_BS_THREE;
10020 else
10021 xp->xp_backslash = XP_BS_ONE;
10022 }
10023 }
10024
10025 /* For an option that is a list of file names, find the start of the
10026 * last file name. */
10027 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10028 {
10029 /* count number of backslashes before ' ' or ',' */
10030 if (*p == ' ' || *p == ',')
10031 {
10032 s = p;
10033 while (s > xp->xp_pattern && *(s - 1) == '\\')
10034 --s;
10035 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10036 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10037 {
10038 xp->xp_pattern = p + 1;
10039 break;
10040 }
10041 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010042
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010043#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010044 /* for 'spellsuggest' start at "file:" */
10045 if (options[opt_idx].var == (char_u *)&p_sps
10046 && STRNCMP(p, "file:", 5) == 0)
10047 {
10048 xp->xp_pattern = p + 5;
10049 break;
10050 }
10051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 }
10053
10054 return;
10055}
10056
10057 int
10058ExpandSettings(xp, regmatch, num_file, file)
10059 expand_T *xp;
10060 regmatch_T *regmatch;
10061 int *num_file;
10062 char_u ***file;
10063{
10064 int num_normal = 0; /* Nr of matching non-term-code settings */
10065 int num_term = 0; /* Nr of matching terminal code settings */
10066 int opt_idx;
10067 int match;
10068 int count = 0;
10069 char_u *str;
10070 int loop;
10071 int is_term_opt;
10072 char_u name_buf[MAX_KEY_NAME_LEN];
10073 static char *(names[]) = {"all", "termcap"};
10074 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10075
10076 /* do this loop twice:
10077 * loop == 0: count the number of matching options
10078 * loop == 1: copy the matching options into allocated memory
10079 */
10080 for (loop = 0; loop <= 1; ++loop)
10081 {
10082 regmatch->rm_ic = ic;
10083 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10084 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010085 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10086 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10088 {
10089 if (loop == 0)
10090 num_normal++;
10091 else
10092 (*file)[count++] = vim_strsave((char_u *)names[match]);
10093 }
10094 }
10095 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10096 opt_idx++)
10097 {
10098 if (options[opt_idx].var == NULL)
10099 continue;
10100 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10101 && !(options[opt_idx].flags & P_BOOL))
10102 continue;
10103 is_term_opt = istermoption(&options[opt_idx]);
10104 if (is_term_opt && num_normal > 0)
10105 continue;
10106 match = FALSE;
10107 if (vim_regexec(regmatch, str, (colnr_T)0)
10108 || (options[opt_idx].shortname != NULL
10109 && vim_regexec(regmatch,
10110 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10111 match = TRUE;
10112 else if (is_term_opt)
10113 {
10114 name_buf[0] = '<';
10115 name_buf[1] = 't';
10116 name_buf[2] = '_';
10117 name_buf[3] = str[2];
10118 name_buf[4] = str[3];
10119 name_buf[5] = '>';
10120 name_buf[6] = NUL;
10121 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10122 {
10123 match = TRUE;
10124 str = name_buf;
10125 }
10126 }
10127 if (match)
10128 {
10129 if (loop == 0)
10130 {
10131 if (is_term_opt)
10132 num_term++;
10133 else
10134 num_normal++;
10135 }
10136 else
10137 (*file)[count++] = vim_strsave(str);
10138 }
10139 }
10140 /*
10141 * Check terminal key codes, these are not in the option table
10142 */
10143 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10144 {
10145 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10146 {
10147 if (!isprint(str[0]) || !isprint(str[1]))
10148 continue;
10149
10150 name_buf[0] = 't';
10151 name_buf[1] = '_';
10152 name_buf[2] = str[0];
10153 name_buf[3] = str[1];
10154 name_buf[4] = NUL;
10155
10156 match = FALSE;
10157 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10158 match = TRUE;
10159 else
10160 {
10161 name_buf[0] = '<';
10162 name_buf[1] = 't';
10163 name_buf[2] = '_';
10164 name_buf[3] = str[0];
10165 name_buf[4] = str[1];
10166 name_buf[5] = '>';
10167 name_buf[6] = NUL;
10168
10169 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10170 match = TRUE;
10171 }
10172 if (match)
10173 {
10174 if (loop == 0)
10175 num_term++;
10176 else
10177 (*file)[count++] = vim_strsave(name_buf);
10178 }
10179 }
10180
10181 /*
10182 * Check special key names.
10183 */
10184 regmatch->rm_ic = TRUE; /* ignore case here */
10185 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10186 {
10187 name_buf[0] = '<';
10188 STRCPY(name_buf + 1, str);
10189 STRCAT(name_buf, ">");
10190
10191 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10192 {
10193 if (loop == 0)
10194 num_term++;
10195 else
10196 (*file)[count++] = vim_strsave(name_buf);
10197 }
10198 }
10199 }
10200 if (loop == 0)
10201 {
10202 if (num_normal > 0)
10203 *num_file = num_normal;
10204 else if (num_term > 0)
10205 *num_file = num_term;
10206 else
10207 return OK;
10208 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10209 if (*file == NULL)
10210 {
10211 *file = (char_u **)"";
10212 return FAIL;
10213 }
10214 }
10215 }
10216 return OK;
10217}
10218
10219 int
10220ExpandOldSetting(num_file, file)
10221 int *num_file;
10222 char_u ***file;
10223{
10224 char_u *var = NULL; /* init for GCC */
10225 char_u *buf;
10226
10227 *num_file = 0;
10228 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10229 if (*file == NULL)
10230 return FAIL;
10231
10232 /*
10233 * For a terminal key code expand_option_idx is < 0.
10234 */
10235 if (expand_option_idx < 0)
10236 {
10237 var = find_termcode(expand_option_name + 2);
10238 if (var == NULL)
10239 expand_option_idx = findoption(expand_option_name);
10240 }
10241
10242 if (expand_option_idx >= 0)
10243 {
10244 /* put string of option value in NameBuff */
10245 option_value2string(&options[expand_option_idx], expand_option_flags);
10246 var = NameBuff;
10247 }
10248 else if (var == NULL)
10249 var = (char_u *)"";
10250
10251 /* A backslash is required before some characters. This is the reverse of
10252 * what happens in do_set(). */
10253 buf = vim_strsave_escaped(var, escape_chars);
10254
10255 if (buf == NULL)
10256 {
10257 vim_free(*file);
10258 *file = NULL;
10259 return FAIL;
10260 }
10261
10262#ifdef BACKSLASH_IN_FILENAME
10263 /* For MS-Windows et al. we don't double backslashes at the start and
10264 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010265 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 if (var[0] == '\\' && var[1] == '\\'
10267 && expand_option_idx >= 0
10268 && (options[expand_option_idx].flags & P_EXPAND)
10269 && vim_isfilec(var[2])
10270 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010271 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272#endif
10273
10274 *file[0] = buf;
10275 *num_file = 1;
10276 return OK;
10277}
10278#endif
10279
10280/*
10281 * Get the value for the numeric or string option *opp in a nice format into
10282 * NameBuff[]. Must not be called with a hidden option!
10283 */
10284 static void
10285option_value2string(opp, opt_flags)
10286 struct vimoption *opp;
10287 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10288{
10289 char_u *varp;
10290
10291 varp = get_varp_scope(opp, opt_flags);
10292
10293 if (opp->flags & P_NUM)
10294 {
10295 long wc = 0;
10296
10297 if (wc_use_keyname(varp, &wc))
10298 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10299 else if (wc != 0)
10300 STRCPY(NameBuff, transchar((int)wc));
10301 else
10302 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10303 }
10304 else /* P_STRING */
10305 {
10306 varp = *(char_u **)(varp);
10307 if (varp == NULL) /* just in case */
10308 NameBuff[0] = NUL;
10309#ifdef FEAT_CRYPT
10310 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010311 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 STRCPY(NameBuff, "*****");
10313#endif
10314 else if (opp->flags & P_EXPAND)
10315 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10316 /* Translate 'pastetoggle' into special key names */
10317 else if ((char_u **)opp->var == &p_pt)
10318 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10319 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010320 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 }
10322}
10323
10324/*
10325 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10326 * printed as a keyname.
10327 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10328 */
10329 static int
10330wc_use_keyname(varp, wcp)
10331 char_u *varp;
10332 long *wcp;
10333{
10334 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10335 {
10336 *wcp = *(long *)varp;
10337 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10338 return TRUE;
10339 }
10340 return FALSE;
10341}
10342
10343#ifdef FEAT_LANGMAP
10344/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010345 * Any character has an equivalent 'langmap' character. This is used for
10346 * keyboards that have a special language mode that sends characters above
10347 * 128 (although other characters can be translated too). The "to" field is a
10348 * Vim command character. This avoids having to switch the keyboard back to
10349 * ASCII mode when leaving Insert mode.
10350 *
10351 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10352 * commands.
10353 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10354 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10355 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010357# ifdef FEAT_MBYTE
10358/*
10359 * With multi-byte support use growarray for 'langmap' chars >= 256
10360 */
10361typedef struct
10362{
10363 int from;
10364 int to;
10365} langmap_entry_T;
10366
10367static garray_T langmap_mapga;
10368static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369
10370/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010371 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10372 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010374 static void
10375langmap_set_entry(from, to)
10376 int from;
10377 int to;
10378{
10379 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10380 int a = 0;
10381 int b = langmap_mapga.ga_len;
10382
10383 /* Do a binary search for an existing entry. */
10384 while (a != b)
10385 {
10386 int i = (a + b) / 2;
10387 int d = entries[i].from - from;
10388
10389 if (d == 0)
10390 {
10391 entries[i].to = to;
10392 return;
10393 }
10394 if (d < 0)
10395 a = i + 1;
10396 else
10397 b = i;
10398 }
10399
10400 if (ga_grow(&langmap_mapga, 1) != OK)
10401 return; /* out of memory */
10402
10403 /* insert new entry at position "a" */
10404 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10405 mch_memmove(entries + 1, entries,
10406 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10407 ++langmap_mapga.ga_len;
10408 entries[0].from = from;
10409 entries[0].to = to;
10410}
10411
10412/*
10413 * Apply 'langmap' to multi-byte character "c" and return the result.
10414 */
10415 int
10416langmap_adjust_mb(c)
10417 int c;
10418{
10419 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10420 int a = 0;
10421 int b = langmap_mapga.ga_len;
10422
10423 while (a != b)
10424 {
10425 int i = (a + b) / 2;
10426 int d = entries[i].from - c;
10427
10428 if (d == 0)
10429 return entries[i].to; /* found matching entry */
10430 if (d < 0)
10431 a = i + 1;
10432 else
10433 b = i;
10434 }
10435 return c; /* no entry found, return "c" unmodified */
10436}
10437# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438
10439 static void
10440langmap_init()
10441{
10442 int i;
10443
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010444 for (i = 0; i < 256; i++)
10445 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10446# ifdef FEAT_MBYTE
10447 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10448# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449}
10450
10451/*
10452 * Called when langmap option is set; the language map can be
10453 * changed at any time!
10454 */
10455 static void
10456langmap_set()
10457{
10458 char_u *p;
10459 char_u *p2;
10460 int from, to;
10461
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010462#ifdef FEAT_MBYTE
10463 ga_clear(&langmap_mapga); /* clear the previous map first */
10464#endif
10465 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466
10467 for (p = p_langmap; p[0] != NUL; )
10468 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010469 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10470 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471 {
10472 if (p2[0] == '\\' && p2[1] != NUL)
10473 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474 }
10475 if (p2[0] == ';')
10476 ++p2; /* abcd;ABCD form, p2 points to A */
10477 else
10478 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10479 while (p[0])
10480 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010481 if (p[0] == ',')
10482 {
10483 ++p;
10484 break;
10485 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 if (p[0] == '\\' && p[1] != NUL)
10487 ++p;
10488#ifdef FEAT_MBYTE
10489 from = (*mb_ptr2char)(p);
10490#else
10491 from = p[0];
10492#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010493 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 if (p2 == NULL)
10495 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010496 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010497 if (p[0] != ',')
10498 {
10499 if (p[0] == '\\')
10500 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010502 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010504 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 }
10508 else
10509 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010510 if (p2[0] != ',')
10511 {
10512 if (p2[0] == '\\')
10513 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010515 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010517 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010519 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 }
10521 if (to == NUL)
10522 {
10523 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10524 transchar(from));
10525 return;
10526 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010527
10528#ifdef FEAT_MBYTE
10529 if (from >= 256)
10530 langmap_set_entry(from, to);
10531 else
10532#endif
10533 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534
10535 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010536 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010537 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010539 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540 if (*p == ';')
10541 {
10542 p = p2;
10543 if (p[0] != NUL)
10544 {
10545 if (p[0] != ',')
10546 {
10547 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10548 return;
10549 }
10550 ++p;
10551 }
10552 break;
10553 }
10554 }
10555 }
10556 }
10557}
10558#endif
10559
10560/*
10561 * Return TRUE if format option 'x' is in effect.
10562 * Take care of no formatting when 'paste' is set.
10563 */
10564 int
10565has_format_option(x)
10566 int x;
10567{
10568 if (p_paste)
10569 return FALSE;
10570 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10571}
10572
10573/*
10574 * Return TRUE if "x" is present in 'shortmess' option, or
10575 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10576 */
10577 int
10578shortmess(x)
10579 int x;
10580{
10581 return ( vim_strchr(p_shm, x) != NULL
10582 || (vim_strchr(p_shm, 'a') != NULL
10583 && vim_strchr((char_u *)SHM_A, x) != NULL));
10584}
10585
10586/*
10587 * paste_option_changed() - Called after p_paste was set or reset.
10588 */
10589 static void
10590paste_option_changed()
10591{
10592 static int old_p_paste = FALSE;
10593 static int save_sm = 0;
10594#ifdef FEAT_CMDL_INFO
10595 static int save_ru = 0;
10596#endif
10597#ifdef FEAT_RIGHTLEFT
10598 static int save_ri = 0;
10599 static int save_hkmap = 0;
10600#endif
10601 buf_T *buf;
10602
10603 if (p_paste)
10604 {
10605 /*
10606 * Paste switched from off to on.
10607 * Save the current values, so they can be restored later.
10608 */
10609 if (!old_p_paste)
10610 {
10611 /* save options for each buffer */
10612 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10613 {
10614 buf->b_p_tw_nopaste = buf->b_p_tw;
10615 buf->b_p_wm_nopaste = buf->b_p_wm;
10616 buf->b_p_sts_nopaste = buf->b_p_sts;
10617 buf->b_p_ai_nopaste = buf->b_p_ai;
10618 }
10619
10620 /* save global options */
10621 save_sm = p_sm;
10622#ifdef FEAT_CMDL_INFO
10623 save_ru = p_ru;
10624#endif
10625#ifdef FEAT_RIGHTLEFT
10626 save_ri = p_ri;
10627 save_hkmap = p_hkmap;
10628#endif
10629 /* save global values for local buffer options */
10630 p_tw_nopaste = p_tw;
10631 p_wm_nopaste = p_wm;
10632 p_sts_nopaste = p_sts;
10633 p_ai_nopaste = p_ai;
10634 }
10635
10636 /*
10637 * Always set the option values, also when 'paste' is set when it is
10638 * already on.
10639 */
10640 /* set options for each buffer */
10641 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10642 {
10643 buf->b_p_tw = 0; /* textwidth is 0 */
10644 buf->b_p_wm = 0; /* wrapmargin is 0 */
10645 buf->b_p_sts = 0; /* softtabstop is 0 */
10646 buf->b_p_ai = 0; /* no auto-indent */
10647 }
10648
10649 /* set global options */
10650 p_sm = 0; /* no showmatch */
10651#ifdef FEAT_CMDL_INFO
10652# ifdef FEAT_WINDOWS
10653 if (p_ru)
10654 status_redraw_all(); /* redraw to remove the ruler */
10655# endif
10656 p_ru = 0; /* no ruler */
10657#endif
10658#ifdef FEAT_RIGHTLEFT
10659 p_ri = 0; /* no reverse insert */
10660 p_hkmap = 0; /* no Hebrew keyboard */
10661#endif
10662 /* set global values for local buffer options */
10663 p_tw = 0;
10664 p_wm = 0;
10665 p_sts = 0;
10666 p_ai = 0;
10667 }
10668
10669 /*
10670 * Paste switched from on to off: Restore saved values.
10671 */
10672 else if (old_p_paste)
10673 {
10674 /* restore options for each buffer */
10675 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10676 {
10677 buf->b_p_tw = buf->b_p_tw_nopaste;
10678 buf->b_p_wm = buf->b_p_wm_nopaste;
10679 buf->b_p_sts = buf->b_p_sts_nopaste;
10680 buf->b_p_ai = buf->b_p_ai_nopaste;
10681 }
10682
10683 /* restore global options */
10684 p_sm = save_sm;
10685#ifdef FEAT_CMDL_INFO
10686# ifdef FEAT_WINDOWS
10687 if (p_ru != save_ru)
10688 status_redraw_all(); /* redraw to draw the ruler */
10689# endif
10690 p_ru = save_ru;
10691#endif
10692#ifdef FEAT_RIGHTLEFT
10693 p_ri = save_ri;
10694 p_hkmap = save_hkmap;
10695#endif
10696 /* set global values for local buffer options */
10697 p_tw = p_tw_nopaste;
10698 p_wm = p_wm_nopaste;
10699 p_sts = p_sts_nopaste;
10700 p_ai = p_ai_nopaste;
10701 }
10702
10703 old_p_paste = p_paste;
10704}
10705
10706/*
10707 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10708 *
10709 * Reset 'compatible' and set the values for options that didn't get set yet
10710 * to the Vim defaults.
10711 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010712 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 */
10714 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010715vimrc_found(fname, envname)
10716 char_u *fname;
10717 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010719 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010720 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010721 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722
10723 if (!option_was_set((char_u *)"cp"))
10724 {
10725 p_cp = FALSE;
10726 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10727 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10728 set_option_default(opt_idx, OPT_FREE, FALSE);
10729 didset_options();
10730 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010731
10732 if (fname != NULL)
10733 {
10734 p = vim_getenv(envname, &dofree);
10735 if (p == NULL)
10736 {
10737 /* Set $MYVIMRC to the first vimrc file found. */
10738 p = FullName_save(fname, FALSE);
10739 if (p != NULL)
10740 {
10741 vim_setenv(envname, p);
10742 vim_free(p);
10743 }
10744 }
10745 else if (dofree)
10746 vim_free(p);
10747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748}
10749
10750/*
10751 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10752 */
10753 void
10754change_compatible(on)
10755 int on;
10756{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010757 int opt_idx;
10758
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 if (p_cp != on)
10760 {
10761 p_cp = on;
10762 compatible_set();
10763 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010764 opt_idx = findoption((char_u *)"cp");
10765 if (opt_idx >= 0)
10766 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767}
10768
10769/*
10770 * Return TRUE when option "name" has been set.
10771 */
10772 int
10773option_was_set(name)
10774 char_u *name;
10775{
10776 int idx;
10777
10778 idx = findoption(name);
10779 if (idx < 0) /* unknown option */
10780 return FALSE;
10781 if (options[idx].flags & P_WAS_SET)
10782 return TRUE;
10783 return FALSE;
10784}
10785
10786/*
10787 * compatible_set() - Called when 'compatible' has been set or unset.
10788 *
10789 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10790 * flag) to a Vi compatible value.
10791 * When 'compatible' is unset: Set all options that have a different default
10792 * for Vim (without the P_VI_DEF flag) to that default.
10793 */
10794 static void
10795compatible_set()
10796{
10797 int opt_idx;
10798
10799 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10800 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10801 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10802 set_option_default(opt_idx, OPT_FREE, p_cp);
10803 didset_options();
10804}
10805
10806#ifdef FEAT_LINEBREAK
10807
10808# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10809 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010810 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811# endif
10812
10813/*
10814 * fill_breakat_flags() -- called when 'breakat' changes value.
10815 */
10816 static void
10817fill_breakat_flags()
10818{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010819 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820 int i;
10821
10822 for (i = 0; i < 256; i++)
10823 breakat_flags[i] = FALSE;
10824
10825 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010826 for (p = p_breakat; *p; p++)
10827 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828}
10829
10830# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010831 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832# endif
10833
10834#endif
10835
10836/*
10837 * Check an option that can be a range of string values.
10838 *
10839 * Return OK for correct value, FAIL otherwise.
10840 * Empty is always OK.
10841 */
10842 static int
10843check_opt_strings(val, values, list)
10844 char_u *val;
10845 char **values;
10846 int list; /* when TRUE: accept a list of values */
10847{
10848 return opt_strings_flags(val, values, NULL, list);
10849}
10850
10851/*
10852 * Handle an option that can be a range of string values.
10853 * Set a flag in "*flagp" for each string present.
10854 *
10855 * Return OK for correct value, FAIL otherwise.
10856 * Empty is always OK.
10857 */
10858 static int
10859opt_strings_flags(val, values, flagp, list)
10860 char_u *val; /* new value */
10861 char **values; /* array of valid string values */
10862 unsigned *flagp;
10863 int list; /* when TRUE: accept a list of values */
10864{
10865 int i;
10866 int len;
10867 unsigned new_flags = 0;
10868
10869 while (*val)
10870 {
10871 for (i = 0; ; ++i)
10872 {
10873 if (values[i] == NULL) /* val not found in values[] */
10874 return FAIL;
10875
10876 len = (int)STRLEN(values[i]);
10877 if (STRNCMP(values[i], val, len) == 0
10878 && ((list && val[len] == ',') || val[len] == NUL))
10879 {
10880 val += len + (val[len] == ',');
10881 new_flags |= (1 << i);
10882 break; /* check next item in val list */
10883 }
10884 }
10885 }
10886 if (flagp != NULL)
10887 *flagp = new_flags;
10888
10889 return OK;
10890}
10891
10892/*
10893 * Read the 'wildmode' option, fill wim_flags[].
10894 */
10895 static int
10896check_opt_wim()
10897{
10898 char_u new_wim_flags[4];
10899 char_u *p;
10900 int i;
10901 int idx = 0;
10902
10903 for (i = 0; i < 4; ++i)
10904 new_wim_flags[i] = 0;
10905
10906 for (p = p_wim; *p; ++p)
10907 {
10908 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10909 ;
10910 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10911 return FAIL;
10912 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10913 new_wim_flags[idx] |= WIM_LONGEST;
10914 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10915 new_wim_flags[idx] |= WIM_FULL;
10916 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10917 new_wim_flags[idx] |= WIM_LIST;
10918 else
10919 return FAIL;
10920 p += i;
10921 if (*p == NUL)
10922 break;
10923 if (*p == ',')
10924 {
10925 if (idx == 3)
10926 return FAIL;
10927 ++idx;
10928 }
10929 }
10930
10931 /* fill remaining entries with last flag */
10932 while (idx < 3)
10933 {
10934 new_wim_flags[idx + 1] = new_wim_flags[idx];
10935 ++idx;
10936 }
10937
10938 /* only when there are no errors, wim_flags[] is changed */
10939 for (i = 0; i < 4; ++i)
10940 wim_flags[i] = new_wim_flags[i];
10941 return OK;
10942}
10943
10944/*
10945 * Check if backspacing over something is allowed.
10946 */
10947 int
10948can_bs(what)
10949 int what; /* BS_INDENT, BS_EOL or BS_START */
10950{
10951 switch (*p_bs)
10952 {
10953 case '2': return TRUE;
10954 case '1': return (what != BS_START);
10955 case '0': return FALSE;
10956 }
10957 return vim_strchr(p_bs, what) != NULL;
10958}
10959
10960/*
10961 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10962 * the file must be considered changed when the value is different.
10963 */
10964 void
10965save_file_ff(buf)
10966 buf_T *buf;
10967{
10968 buf->b_start_ffc = *buf->b_p_ff;
10969 buf->b_start_eol = buf->b_p_eol;
10970#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010971 buf->b_start_bomb = buf->b_p_bomb;
10972
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973 /* Only use free/alloc when necessary, they take time. */
10974 if (buf->b_start_fenc == NULL
10975 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10976 {
10977 vim_free(buf->b_start_fenc);
10978 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10979 }
10980#endif
10981}
10982
10983/*
10984 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10985 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010986 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
10987 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988 * Don't consider a new, empty buffer to be changed.
10989 */
10990 int
10991file_ff_differs(buf)
10992 buf_T *buf;
10993{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000010994 /* In a buffer that was never loaded the options are not valid. */
10995 if (buf->b_flags & BF_NEVERLOADED)
10996 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010997 if ((buf->b_flags & BF_NEW)
10998 && buf->b_ml.ml_line_count == 1
10999 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11000 return FALSE;
11001 if (buf->b_start_ffc != *buf->b_p_ff)
11002 return TRUE;
11003 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11004 return TRUE;
11005#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011006 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11007 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008 if (buf->b_start_fenc == NULL)
11009 return (*buf->b_p_fenc != NUL);
11010 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11011#else
11012 return FALSE;
11013#endif
11014}
11015
11016/*
11017 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11018 */
11019 int
11020check_ff_value(p)
11021 char_u *p;
11022{
11023 return check_opt_strings(p, p_ff_values, FALSE);
11024}