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