Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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. |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 25 | * - Add documentation! One line in doc/quickref.txt, full description in |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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" |
Bram Moolenaar | 0eddca4 | 2019-09-12 22:26:43 +0200 | [diff] [blame] | 36 | #include "optiondefs.h" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 38 | static void set_options_default(int opt_flags); |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 39 | static void set_string_default_esc(char *name, char_u *val, int escape); |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 40 | static char_u *find_dup_item(char_u *origval, char_u *newval, long_u flags); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 41 | static char_u *option_expand(int opt_idx, char_u *val); |
| 42 | static void didset_options(void); |
| 43 | static void didset_options2(void); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 44 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 45 | static long_u *insecure_flag(int opt_idx, int opt_flags); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 46 | #else |
| 47 | # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags) |
| 48 | #endif |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 49 | static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); |
| 50 | static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags); |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 51 | static int find_key_option(char_u *arg_arg, int has_lt); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 52 | static void showoptions(int all, int opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 53 | static int optval_default(struct vimoption *, char_u *varp, int compatible); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 54 | static void showoneopt(struct vimoption *, int opt_flags); |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 55 | static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 56 | static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); |
| 57 | static int put_setbool(FILE *fd, char *cmd, char *name, int value); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 58 | static int istermoption(struct vimoption *p); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 59 | static char_u *get_varp_scope(struct vimoption *p, int opt_flags); |
| 60 | static char_u *get_varp(struct vimoption *); |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 61 | static void check_win_options(win_T *win); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 62 | static void option_value2string(struct vimoption *, int opt_flags); |
| 63 | static void check_winopt(winopt_T *wop); |
| 64 | static int wc_use_keyname(char_u *varp, long *wcp); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 65 | static void paste_option_changed(void); |
| 66 | static void compatible_set(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Initialize the options, first part. |
| 70 | * |
| 71 | * Called only once from main(), just after creating the first buffer. |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 72 | * If "clean_arg" is TRUE Vim was started with --clean. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 73 | */ |
| 74 | void |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 75 | set_init_1(int clean_arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | { |
| 77 | char_u *p; |
| 78 | int opt_idx; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 79 | long_u n; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef FEAT_LANGMAP |
| 82 | langmap_init(); |
| 83 | #endif |
| 84 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 85 | // Be Vi compatible by default |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 86 | p_cp = TRUE; |
| 87 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 88 | // Use POSIX compatibility when $VIM_POSIX is set. |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 89 | if (mch_getenv((char_u *)"VIM_POSIX") != NULL) |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 90 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 91 | set_string_default("cpo", (char_u *)CPO_ALL); |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 92 | set_string_default("shm", (char_u *)SHM_POSIX); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 93 | } |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * Find default value for 'shell' option. |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 97 | * Don't use it if it is empty. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 98 | */ |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 99 | if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 100 | #if defined(MSWIN) |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 101 | || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) |
Bram Moolenaar | 6aa2cd4 | 2016-02-16 15:06:59 +0100 | [diff] [blame] | 102 | || ((p = (char_u *)default_shell()) != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | #endif |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 104 | ) |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 105 | #if defined(MSWIN) |
| 106 | { |
| 107 | // For MS-Windows put the path in quotes instead of escaping spaces. |
| 108 | char_u *cmd; |
| 109 | size_t len; |
| 110 | |
| 111 | if (vim_strchr(p, ' ') != NULL) |
| 112 | { |
| 113 | len = STRLEN(p) + 3; // two quotes and a trailing NUL |
| 114 | cmd = alloc(len); |
Bram Moolenaar | 1671de3 | 2019-10-05 21:35:16 +0200 | [diff] [blame] | 115 | if (cmd != NULL) |
| 116 | { |
| 117 | vim_snprintf((char *)cmd, len, "\"%s\"", p); |
| 118 | set_string_default("sh", cmd); |
| 119 | vim_free(cmd); |
| 120 | } |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 121 | } |
| 122 | else |
| 123 | set_string_default("sh", p); |
| 124 | } |
| 125 | #else |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 126 | set_string_default_esc("sh", p, TRUE); |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 127 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 128 | |
| 129 | #ifdef FEAT_WILDIGN |
| 130 | /* |
| 131 | * Set the default for 'backupskip' to include environment variables for |
| 132 | * temp files. |
| 133 | */ |
| 134 | { |
| 135 | # ifdef UNIX |
| 136 | static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; |
| 137 | # else |
| 138 | static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; |
| 139 | # endif |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 140 | int len; |
| 141 | garray_T ga; |
| 142 | int mustfree; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 143 | char_u *item; |
| 144 | |
| 145 | opt_idx = findoption((char_u *)"backupskip"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | |
| 147 | ga_init2(&ga, 1, 100); |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 148 | for (n = 0; n < (long)ARRAY_LENGTH(names); ++n) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 149 | { |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 150 | mustfree = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 151 | # ifdef UNIX |
| 152 | if (*names[n] == NUL) |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 153 | # ifdef MACOS_X |
| 154 | p = (char_u *)"/private/tmp"; |
| 155 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 156 | p = (char_u *)"/tmp"; |
Bram Moolenaar | b8e22a0 | 2018-04-12 21:37:34 +0200 | [diff] [blame] | 157 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | else |
| 159 | # endif |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 160 | p = vim_getenv((char_u *)names[n], &mustfree); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 161 | if (p != NULL && *p != NUL) |
| 162 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 163 | // First time count the NUL, otherwise count the ','. |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 164 | len = (int)STRLEN(p) + 3; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 165 | item = alloc(len); |
| 166 | STRCPY(item, p); |
| 167 | add_pathsep(item); |
| 168 | STRCAT(item, "*"); |
| 169 | if (find_dup_item(ga.ga_data, item, options[opt_idx].flags) |
| 170 | == NULL |
| 171 | && ga_grow(&ga, len) == OK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | { |
| 173 | if (ga.ga_len > 0) |
| 174 | STRCAT(ga.ga_data, ","); |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 175 | STRCAT(ga.ga_data, item); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | ga.ga_len += len; |
| 177 | } |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 178 | vim_free(item); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 179 | } |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 180 | if (mustfree) |
| 181 | vim_free(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 182 | } |
| 183 | if (ga.ga_data != NULL) |
| 184 | { |
| 185 | set_string_default("bsk", ga.ga_data); |
| 186 | vim_free(ga.ga_data); |
| 187 | } |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | /* |
| 192 | * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory |
| 193 | */ |
| 194 | opt_idx = findoption((char_u *)"maxmemtot"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 195 | if (opt_idx >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 196 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 197 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
| 198 | if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) |
| 199 | #endif |
| 200 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 201 | #ifdef HAVE_AVAIL_MEM |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 202 | // Use amount of memory available at this moment. |
Bram Moolenaar | 11b73d6 | 2012-06-29 15:51:30 +0200 | [diff] [blame] | 203 | n = (mch_avail_mem(FALSE) >> 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 204 | #else |
| 205 | # ifdef HAVE_TOTAL_MEM |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 206 | // Use amount of memory available to Vim. |
Bram Moolenaar | 914572a | 2007-05-01 11:37:47 +0000 | [diff] [blame] | 207 | n = (mch_total_mem(FALSE) >> 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 208 | # else |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 209 | n = (0x7fffffff >> 11); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 210 | # endif |
| 211 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 212 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 213 | opt_idx = findoption((char_u *)"maxmem"); |
| 214 | if (opt_idx >= 0) |
| 215 | { |
| 216 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
Bram Moolenaar | 35be453 | 2015-12-11 22:38:36 +0100 | [diff] [blame] | 217 | if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n |
| 218 | || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L) |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 219 | #endif |
| 220 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
| 221 | } |
| 222 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 225 | #ifdef FEAT_SEARCHPATH |
| 226 | { |
| 227 | char_u *cdpath; |
| 228 | char_u *buf; |
| 229 | int i; |
| 230 | int j; |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 231 | int mustfree = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 232 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 233 | // Initialize the 'cdpath' option's default value. |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 234 | cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 235 | if (cdpath != NULL) |
| 236 | { |
Bram Moolenaar | 964b374 | 2019-05-24 18:54:09 +0200 | [diff] [blame] | 237 | buf = alloc((STRLEN(cdpath) << 1) + 2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | if (buf != NULL) |
| 239 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 240 | buf[0] = ','; // start with ",", current dir first |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 241 | j = 1; |
| 242 | for (i = 0; cdpath[i] != NUL; ++i) |
| 243 | { |
| 244 | if (vim_ispathlistsep(cdpath[i])) |
| 245 | buf[j++] = ','; |
| 246 | else |
| 247 | { |
| 248 | if (cdpath[i] == ' ' || cdpath[i] == ',') |
| 249 | buf[j++] = '\\'; |
| 250 | buf[j++] = cdpath[i]; |
| 251 | } |
| 252 | } |
| 253 | buf[j] = NUL; |
| 254 | opt_idx = findoption((char_u *)"cdpath"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 255 | if (opt_idx >= 0) |
| 256 | { |
| 257 | options[opt_idx].def_val[VI_DEFAULT] = buf; |
| 258 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 259 | } |
Bram Moolenaar | a9d52e3 | 2010-07-31 16:44:19 +0200 | [diff] [blame] | 260 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 261 | vim_free(buf); // cannot happen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 262 | } |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 263 | if (mustfree) |
| 264 | vim_free(cdpath); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | #endif |
| 268 | |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 269 | #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 270 | // Set print encoding on platforms that don't default to latin1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 271 | set_string_default("penc", |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 272 | # if defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 273 | (char_u *)"cp1252" |
| 274 | # else |
| 275 | # ifdef VMS |
| 276 | (char_u *)"dec-mcs" |
| 277 | # else |
| 278 | # ifdef EBCDIC |
| 279 | (char_u *)"ebcdic-uk" |
| 280 | # else |
| 281 | # ifdef MAC |
| 282 | (char_u *)"mac-roman" |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 283 | # else // HPUX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 284 | (char_u *)"hp-roman8" |
| 285 | # endif |
| 286 | # endif |
| 287 | # endif |
| 288 | # endif |
| 289 | ); |
| 290 | #endif |
| 291 | |
| 292 | #ifdef FEAT_POSTSCRIPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 293 | // 'printexpr' must be allocated to be able to evaluate it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 294 | set_string_default("pexpr", |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 295 | # if defined(MSWIN) |
Bram Moolenaar | ed20346 | 2004-06-16 11:19:22 +0000 | [diff] [blame] | 296 | (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 297 | # else |
| 298 | # ifdef VMS |
| 299 | (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" |
| 300 | |
| 301 | # else |
| 302 | (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error" |
| 303 | # endif |
| 304 | # endif |
| 305 | ); |
| 306 | #endif |
| 307 | |
| 308 | /* |
| 309 | * Set all the options (except the terminal options) to their default |
| 310 | * value. Also set the global value for local options. |
| 311 | */ |
| 312 | set_options_default(0); |
| 313 | |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 314 | #ifdef CLEAN_RUNTIMEPATH |
| 315 | if (clean_arg) |
| 316 | { |
| 317 | opt_idx = findoption((char_u *)"runtimepath"); |
| 318 | if (opt_idx >= 0) |
| 319 | { |
| 320 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 321 | p_rtp = (char_u *)CLEAN_RUNTIMEPATH; |
| 322 | } |
| 323 | opt_idx = findoption((char_u *)"packpath"); |
| 324 | if (opt_idx >= 0) |
| 325 | { |
| 326 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 327 | p_pp = (char_u *)CLEAN_RUNTIMEPATH; |
| 328 | } |
| 329 | } |
| 330 | #endif |
| 331 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 332 | #ifdef FEAT_GUI |
| 333 | if (found_reverse_arg) |
| 334 | set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0); |
| 335 | #endif |
| 336 | |
| 337 | curbuf->b_p_initialized = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 338 | curbuf->b_p_ar = -1; // no local 'autoread' value |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 339 | curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 340 | check_buf_options(curbuf); |
| 341 | check_win_options(curwin); |
| 342 | check_options(); |
| 343 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 344 | // Must be before option_expand(), because that one needs vim_isIDc() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 345 | didset_options(); |
| 346 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 347 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 348 | // Use the current chartab for the generic chartab. This is not in |
| 349 | // didset_options() because it only depends on 'encoding'. |
Bram Moolenaar | 6bb6836 | 2005-03-22 23:03:44 +0000 | [diff] [blame] | 350 | init_spell_chartab(); |
| 351 | #endif |
| 352 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 353 | /* |
| 354 | * Expand environment variables and things like "~" for the defaults. |
| 355 | * If option_expand() returns non-NULL the variable is expanded. This can |
| 356 | * only happen for non-indirect options. |
| 357 | * Also set the default to the expanded value, so ":set" does not list |
| 358 | * them. |
| 359 | * Don't set the P_ALLOCED flag, because we don't want to free the |
| 360 | * default. |
| 361 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 362 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 363 | { |
| 364 | if ((options[opt_idx].flags & P_GETTEXT) |
| 365 | && options[opt_idx].var != NULL) |
| 366 | p = (char_u *)_(*(char **)options[opt_idx].var); |
| 367 | else |
| 368 | p = option_expand(opt_idx, NULL); |
| 369 | if (p != NULL && (p = vim_strsave(p)) != NULL) |
| 370 | { |
| 371 | *(char_u **)options[opt_idx].var = p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 372 | // VIMEXP |
| 373 | // Defaults for all expanded options are currently the same for Vi |
| 374 | // and Vim. When this changes, add some code here! Also need to |
| 375 | // split P_DEF_ALLOCED in two. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 376 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 377 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 378 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 379 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 380 | } |
| 381 | } |
| 382 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 383 | save_file_ff(curbuf); // Buffer is unchanged |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 384 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 385 | #if defined(FEAT_ARABIC) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 386 | // Detect use of mlterm. |
| 387 | // Mlterm is a terminal emulator akin to xterm that has some special |
| 388 | // abilities (bidi namely). |
| 389 | // NOTE: mlterm's author is being asked to 'set' a variable |
| 390 | // instead of an environment variable due to inheritance. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 391 | if (mch_getenv((char_u *)"MLTERM") != NULL) |
| 392 | set_option_value((char_u *)"tbidi", 1L, NULL, 0); |
| 393 | #endif |
| 394 | |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 395 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 396 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 397 | # if defined(MSWIN) && defined(FEAT_GETTEXT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 398 | /* |
| 399 | * If $LANG isn't set, try to get a good value for it. This makes the |
| 400 | * right language be used automatically. Don't do this for English. |
| 401 | */ |
| 402 | if (mch_getenv((char_u *)"LANG") == NULL) |
| 403 | { |
| 404 | char buf[20]; |
| 405 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 406 | // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. |
| 407 | // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use |
| 408 | // only the first two. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 409 | n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, |
| 410 | (LPTSTR)buf, 20); |
| 411 | if (n >= 2 && STRNICMP(buf, "en", 2) != 0) |
| 412 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 413 | // There are a few exceptions (probably more) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 414 | if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) |
| 415 | STRCPY(buf, "zh_TW"); |
| 416 | else if (STRNICMP(buf, "chs", 3) == 0 |
| 417 | || STRNICMP(buf, "zhc", 3) == 0) |
| 418 | STRCPY(buf, "zh_CN"); |
| 419 | else if (STRNICMP(buf, "jp", 2) == 0) |
| 420 | STRCPY(buf, "ja"); |
| 421 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 422 | buf[2] = NUL; // truncate to two-letter code |
Bram Moolenaar | 6aa2cd4 | 2016-02-16 15:06:59 +0100 | [diff] [blame] | 423 | vim_setenv((char_u *)"LANG", (char_u *)buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 426 | # else |
Bram Moolenaar | 9d47f17 | 2006-03-15 23:03:01 +0000 | [diff] [blame] | 427 | # ifdef MACOS_CONVERT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 428 | // Moved to os_mac_conv.c to avoid dependency problems. |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 429 | mac_lang_init(); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 430 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 431 | # endif |
| 432 | |
K.Takata | f883d90 | 2021-05-30 18:04:19 +0200 | [diff] [blame] | 433 | # ifdef MSWIN |
| 434 | // MS-Windows has builtin support for conversion to and from Unicode, using |
| 435 | // "utf-8" for 'encoding' should work best for most users. |
| 436 | p = vim_strsave((char_u *)ENC_DFLT); |
| 437 | # else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 438 | // enc_locale() will try to find the encoding of the current locale. |
K.Takata | f883d90 | 2021-05-30 18:04:19 +0200 | [diff] [blame] | 439 | // This works best for properly configured systems, old and new. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 440 | p = enc_locale(); |
K.Takata | f883d90 | 2021-05-30 18:04:19 +0200 | [diff] [blame] | 441 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 442 | if (p != NULL) |
| 443 | { |
| 444 | char_u *save_enc; |
| 445 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 446 | // Try setting 'encoding' and check if the value is valid. |
K.Takata | f883d90 | 2021-05-30 18:04:19 +0200 | [diff] [blame] | 447 | // If not, go back to the default encoding. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 448 | save_enc = p_enc; |
| 449 | p_enc = p; |
Bram Moolenaar | 733f0a2 | 2007-03-02 18:56:27 +0000 | [diff] [blame] | 450 | if (STRCMP(p_enc, "gb18030") == 0) |
| 451 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 452 | // We don't support "gb18030", but "cp936" is a good substitute |
| 453 | // for practical purposes, thus use that. It's not an alias to |
| 454 | // still support conversion between gb18030 and utf-8. |
Bram Moolenaar | 733f0a2 | 2007-03-02 18:56:27 +0000 | [diff] [blame] | 455 | p_enc = vim_strsave((char_u *)"cp936"); |
| 456 | vim_free(p); |
| 457 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 458 | if (mb_init() == NULL) |
| 459 | { |
| 460 | opt_idx = findoption((char_u *)"encoding"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 461 | if (opt_idx >= 0) |
| 462 | { |
| 463 | options[opt_idx].def_val[VI_DEFAULT] = p_enc; |
| 464 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 465 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 466 | |
Bram Moolenaar | d057301 | 2017-10-28 21:11:06 +0200 | [diff] [blame] | 467 | #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 468 | if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 469 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 470 | // Adjust the default for 'isprint' and 'iskeyword' to match |
| 471 | // latin1. Also set the defaults for when 'nocompatible' is |
| 472 | // set. |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 473 | set_string_option_direct((char_u *)"isp", -1, |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 474 | ISP_LATIN1, OPT_FREE, SID_NONE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 475 | set_string_option_direct((char_u *)"isk", -1, |
| 476 | ISK_LATIN1, OPT_FREE, SID_NONE); |
| 477 | opt_idx = findoption((char_u *)"isp"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 478 | if (opt_idx >= 0) |
| 479 | options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 480 | opt_idx = findoption((char_u *)"isk"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 481 | if (opt_idx >= 0) |
| 482 | options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 483 | (void)init_chartab(); |
| 484 | } |
| 485 | #endif |
| 486 | |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 487 | #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 488 | // Win32 console: When GetACP() returns a different value from |
| 489 | // GetConsoleCP() set 'termencoding'. |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 490 | if ( |
| 491 | # ifdef VIMDLL |
| 492 | (!gui.in_use && !gui.starting) && |
| 493 | # endif |
| 494 | GetACP() != GetConsoleCP()) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 495 | { |
| 496 | char buf[50]; |
| 497 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 498 | // Win32 console: In ConPTY, GetConsoleCP() returns zero. |
| 499 | // Use an alternative value. |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 500 | if (GetConsoleCP() == 0) |
| 501 | sprintf(buf, "cp%ld", (long)GetACP()); |
| 502 | else |
| 503 | sprintf(buf, "cp%ld", (long)GetConsoleCP()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 504 | p_tenc = vim_strsave((char_u *)buf); |
| 505 | if (p_tenc != NULL) |
| 506 | { |
| 507 | opt_idx = findoption((char_u *)"termencoding"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 508 | if (opt_idx >= 0) |
| 509 | { |
| 510 | options[opt_idx].def_val[VI_DEFAULT] = p_tenc; |
| 511 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 512 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 513 | convert_setup(&input_conv, p_tenc, p_enc); |
| 514 | convert_setup(&output_conv, p_enc, p_tenc); |
| 515 | } |
| 516 | else |
| 517 | p_tenc = empty_option; |
| 518 | } |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 519 | #endif |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 520 | #if defined(MSWIN) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 521 | // $HOME may have characters in active code page. |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 522 | init_homedir(); |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 523 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 524 | } |
| 525 | else |
| 526 | { |
| 527 | vim_free(p_enc); |
| 528 | p_enc = save_enc; |
| 529 | } |
| 530 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 531 | |
| 532 | #ifdef FEAT_MULTI_LANG |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 533 | // Set the default for 'helplang'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 534 | set_helplang_default(get_mess_lang()); |
| 535 | #endif |
| 536 | } |
| 537 | |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 538 | static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1"; |
| 539 | |
| 540 | /* |
| 541 | * Set the "fileencodings" option to the default value for when 'encoding' is |
| 542 | * utf-8. |
| 543 | */ |
| 544 | void |
| 545 | set_fencs_unicode() |
| 546 | { |
| 547 | set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, |
| 548 | OPT_FREE, 0); |
| 549 | } |
| 550 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 551 | /* |
| 552 | * Set an option to its default value. |
| 553 | * This does not take care of side effects! |
| 554 | */ |
| 555 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 556 | set_option_default( |
| 557 | int opt_idx, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 558 | int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
| 559 | int compatible) // use Vi default value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 560 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 561 | char_u *varp; // pointer to variable for current option |
| 562 | int dvi; // index in def_val[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 563 | long_u flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 564 | long_u *flagsp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 565 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 566 | |
| 567 | varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); |
| 568 | flags = options[opt_idx].flags; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 569 | if (varp != NULL) // skip hidden option, nothing to do for it |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 570 | { |
| 571 | dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
| 572 | if (flags & P_STRING) |
| 573 | { |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 574 | // 'fencs' default value depends on 'encoding' |
| 575 | if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8) |
| 576 | set_fencs_unicode(); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 577 | // Use set_string_option_direct() for local options to handle |
| 578 | // freeing and allocating the value. |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 579 | else if (options[opt_idx].indir != PV_NONE) |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 580 | set_string_option_direct(NULL, opt_idx, |
| 581 | options[opt_idx].def_val[dvi], opt_flags, 0); |
| 582 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 583 | { |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 584 | if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) |
| 585 | free_string_option(*(char_u **)(varp)); |
| 586 | *(char_u **)varp = options[opt_idx].def_val[dvi]; |
| 587 | options[opt_idx].flags &= ~P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | else if (flags & P_NUM) |
| 591 | { |
Bram Moolenaar | 5fc1a8b | 2006-10-17 16:34:24 +0000 | [diff] [blame] | 592 | if (options[opt_idx].indir == PV_SCROLL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 593 | win_comp_scroll(curwin); |
| 594 | else |
| 595 | { |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 596 | long def_val = (long)(long_i)options[opt_idx].def_val[dvi]; |
| 597 | |
| 598 | if ((long *)varp == &curwin->w_p_so |
| 599 | || (long *)varp == &curwin->w_p_siso) |
| 600 | // 'scrolloff' and 'sidescrolloff' local values have a |
| 601 | // different default value than the global default. |
| 602 | *(long *)varp = -1; |
| 603 | else |
| 604 | *(long *)varp = def_val; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 605 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 606 | if (both) |
| 607 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 608 | def_val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 611 | else // P_BOOL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 612 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 613 | // the cast to long is required for Manx C, long_i is needed for |
| 614 | // MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 615 | *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 616 | #ifdef UNIX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 617 | // 'modeline' defaults to off for root |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 618 | if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) |
| 619 | *(int *)varp = FALSE; |
| 620 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 621 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 622 | if (both) |
| 623 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
| 624 | *(int *)varp; |
| 625 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 626 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 627 | // The default value is not insecure. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 628 | flagsp = insecure_flag(opt_idx, opt_flags); |
| 629 | *flagsp = *flagsp & ~P_INSECURE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | #ifdef FEAT_EVAL |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 633 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 634 | #endif |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * Set all options (except terminal options) to their default value. |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 639 | * When "opt_flags" is non-zero skip 'encoding'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 640 | */ |
| 641 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 642 | set_options_default( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 643 | int opt_flags) // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 644 | { |
| 645 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 646 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 647 | tabpage_T *tp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 648 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 649 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 650 | if (!(options[i].flags & P_NODEFAULT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 651 | && (opt_flags == 0 |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 652 | || (options[i].var != (char_u *)&p_enc |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 653 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 654 | && options[i].var != (char_u *)&p_cm |
Bram Moolenaar | 8060687 | 2015-08-25 21:27:35 +0200 | [diff] [blame] | 655 | && options[i].var != (char_u *)&p_key |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 656 | # endif |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 657 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 658 | set_option_default(i, opt_flags, p_cp); |
| 659 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 660 | // The 'scroll' option must be computed for all windows. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 661 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 662 | win_comp_scroll(wp); |
Bram Moolenaar | 5a4eceb | 2014-09-09 17:33:07 +0200 | [diff] [blame] | 663 | #ifdef FEAT_CINDENT |
| 664 | parse_cino(curbuf); |
| 665 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Set the Vi-default value of a string option. |
| 670 | * Used for 'sh', 'backupskip' and 'term'. |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 671 | * When "escape" is TRUE escape spaces with a backslash. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 672 | */ |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 673 | static void |
| 674 | set_string_default_esc(char *name, char_u *val, int escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 675 | { |
| 676 | char_u *p; |
| 677 | int opt_idx; |
| 678 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 679 | if (escape && vim_strchr(val, ' ') != NULL) |
| 680 | p = vim_strsave_escaped(val, (char_u *)" "); |
| 681 | else |
| 682 | p = vim_strsave(val); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 683 | if (p != NULL) // we don't want a NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 684 | { |
| 685 | opt_idx = findoption((char_u *)name); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 686 | if (opt_idx >= 0) |
| 687 | { |
| 688 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 689 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 690 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 691 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 692 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 696 | void |
| 697 | set_string_default(char *name, char_u *val) |
| 698 | { |
| 699 | set_string_default_esc(name, val, FALSE); |
| 700 | } |
| 701 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 702 | /* |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 703 | * For an option value that contains comma separated items, find "newval" in |
| 704 | * "origval". Return NULL if not found. |
| 705 | */ |
| 706 | static char_u * |
| 707 | find_dup_item(char_u *origval, char_u *newval, long_u flags) |
| 708 | { |
Bram Moolenaar | 8f13d82 | 2020-09-12 21:04:23 +0200 | [diff] [blame] | 709 | int bs = 0; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 710 | size_t newlen; |
| 711 | char_u *s; |
| 712 | |
| 713 | if (origval == NULL) |
| 714 | return NULL; |
| 715 | |
| 716 | newlen = STRLEN(newval); |
| 717 | for (s = origval; *s != NUL; ++s) |
| 718 | { |
| 719 | if ((!(flags & P_COMMA) |
| 720 | || s == origval |
| 721 | || (s[-1] == ',' && !(bs & 1))) |
| 722 | && STRNCMP(s, newval, newlen) == 0 |
| 723 | && (!(flags & P_COMMA) |
| 724 | || s[newlen] == ',' |
| 725 | || s[newlen] == NUL)) |
| 726 | return s; |
| 727 | // Count backslashes. Only a comma with an even number of backslashes |
| 728 | // or a single backslash preceded by a comma before it is recognized as |
| 729 | // a separator. |
| 730 | if ((s > origval + 1 |
| 731 | && s[-1] == '\\' |
| 732 | && s[-2] != ',') |
| 733 | || (s == origval + 1 |
| 734 | && s[-1] == '\\')) |
| 735 | ++bs; |
| 736 | else |
| 737 | bs = 0; |
| 738 | } |
| 739 | return NULL; |
| 740 | } |
| 741 | |
| 742 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 743 | * Set the Vi-default value of a number option. |
| 744 | * Used for 'lines' and 'columns'. |
| 745 | */ |
| 746 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 747 | set_number_default(char *name, long val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 748 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 749 | int opt_idx; |
| 750 | |
| 751 | opt_idx = findoption((char_u *)name); |
| 752 | if (opt_idx >= 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 753 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 756 | /* |
| 757 | * Set all window-local and buffer-local options to the Vim default. |
| 758 | * local-global options will use the global value. |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 759 | * When "do_buffer" is FALSE don't set buffer-local options. |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 760 | */ |
| 761 | void |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 762 | set_local_options_default(win_T *wp, int do_buffer) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 763 | { |
| 764 | win_T *save_curwin = curwin; |
| 765 | int i; |
| 766 | |
| 767 | curwin = wp; |
| 768 | curbuf = curwin->w_buffer; |
| 769 | block_autocmds(); |
| 770 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 771 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 772 | { |
| 773 | struct vimoption *p = &(options[i]); |
| 774 | char_u *varp = get_varp_scope(p, OPT_LOCAL); |
| 775 | |
| 776 | if (p->indir != PV_NONE |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 777 | && (do_buffer || (p->indir & PV_BUF) == 0) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 778 | && !(options[i].flags & P_NODEFAULT) |
| 779 | && !optval_default(p, varp, FALSE)) |
Bram Moolenaar | 8617348 | 2019-10-01 17:02:16 +0200 | [diff] [blame] | 780 | set_option_default(i, OPT_FREE|OPT_LOCAL, FALSE); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | unblock_autocmds(); |
| 784 | curwin = save_curwin; |
| 785 | curbuf = curwin->w_buffer; |
| 786 | } |
| 787 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 788 | #if defined(EXITFREE) || defined(PROTO) |
| 789 | /* |
| 790 | * Free all options. |
| 791 | */ |
| 792 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 793 | free_all_options(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 794 | { |
| 795 | int i; |
| 796 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 797 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 798 | { |
| 799 | if (options[i].indir == PV_NONE) |
| 800 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 801 | // global option: free value and default value. |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 802 | if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 803 | free_string_option(*(char_u **)options[i].var); |
| 804 | if (options[i].flags & P_DEF_ALLOCED) |
| 805 | free_string_option(options[i].def_val[VI_DEFAULT]); |
| 806 | } |
| 807 | else if (options[i].var != VAR_WIN |
| 808 | && (options[i].flags & P_STRING)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 809 | // buffer-local option: free global value |
Bram Moolenaar | 77111e2 | 2021-07-29 21:11:30 +0200 | [diff] [blame] | 810 | clear_string_option((char_u **)options[i].var); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | #endif |
| 814 | |
| 815 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 816 | /* |
| 817 | * Initialize the options, part two: After getting Rows and Columns and |
| 818 | * setting 'term'. |
| 819 | */ |
| 820 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 821 | set_init_2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 822 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 823 | int idx; |
| 824 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 825 | /* |
Bram Moolenaar | af2d20c | 2017-10-29 15:26:57 +0100 | [diff] [blame] | 826 | * 'scroll' defaults to half the window height. The stored default is zero, |
| 827 | * which results in the actual value computed from the window height. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 828 | */ |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 829 | idx = findoption((char_u *)"scroll"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 830 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 831 | set_option_default(idx, OPT_LOCAL, p_cp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 832 | comp_col(); |
| 833 | |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 834 | /* |
| 835 | * 'window' is only for backwards compatibility with Vi. |
| 836 | * Default is Rows - 1. |
| 837 | */ |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 838 | if (!option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 839 | p_window = Rows - 1; |
| 840 | set_number_default("window", Rows - 1); |
| 841 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 842 | // For DOS console the default is always black. |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 843 | #if !((defined(MSWIN)) && !defined(FEAT_GUI)) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 844 | /* |
| 845 | * If 'background' wasn't set by the user, try guessing the value, |
| 846 | * depending on the terminal name. Only need to check for terminals |
| 847 | * with a dark background, that can handle color. |
| 848 | */ |
| 849 | idx = findoption((char_u *)"bg"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 850 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET) |
| 851 | && *term_bg_default() == 'd') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 852 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 853 | set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 854 | // don't mark it as set, when starting the GUI it may be |
| 855 | // changed again |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 856 | options[idx].flags &= ~P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 857 | } |
| 858 | #endif |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 859 | |
| 860 | #ifdef CURSOR_SHAPE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 861 | parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 862 | #endif |
| 863 | #ifdef FEAT_MOUSESHAPE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 864 | parse_shape_opt(SHAPE_MOUSE); // set mouse shapes from 'mouseshape' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 865 | #endif |
| 866 | #ifdef FEAT_PRINTER |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 867 | (void)parse_printoptions(); // parse 'printoptions' default value |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 868 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* |
| 872 | * Initialize the options, part three: After reading the .vimrc |
| 873 | */ |
| 874 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 875 | set_init_3(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 876 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 877 | #if defined(UNIX) || defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 878 | /* |
| 879 | * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. |
| 880 | * This is done after other initializations, where 'shell' might have been |
| 881 | * set, but only if they have not been set before. |
| 882 | */ |
| 883 | char_u *p; |
| 884 | int idx_srr; |
| 885 | int do_srr; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 886 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 887 | int idx_sp; |
| 888 | int do_sp; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 889 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 890 | |
| 891 | idx_srr = findoption((char_u *)"srr"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 892 | if (idx_srr < 0) |
| 893 | do_srr = FALSE; |
| 894 | else |
| 895 | do_srr = !(options[idx_srr].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 896 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 897 | idx_sp = findoption((char_u *)"sp"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 898 | if (idx_sp < 0) |
| 899 | do_sp = FALSE; |
| 900 | else |
| 901 | do_sp = !(options[idx_sp].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 902 | # endif |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 903 | p = get_isolated_shell_name(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 904 | if (p != NULL) |
| 905 | { |
| 906 | /* |
| 907 | * Default for p_sp is "| tee", for p_srr is ">". |
| 908 | * For known shells it is changed here to include stderr. |
| 909 | */ |
| 910 | if ( fnamecmp(p, "csh") == 0 |
| 911 | || fnamecmp(p, "tcsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 912 | # if defined(MSWIN) // also check with .exe extension |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 913 | || fnamecmp(p, "csh.exe") == 0 |
| 914 | || fnamecmp(p, "tcsh.exe") == 0 |
| 915 | # endif |
| 916 | ) |
| 917 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 918 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 919 | if (do_sp) |
| 920 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 921 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 922 | p_sp = (char_u *)">&"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 923 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 924 | p_sp = (char_u *)"|& tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 925 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 926 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 927 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 928 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 929 | if (do_srr) |
| 930 | { |
| 931 | p_srr = (char_u *)">&"; |
| 932 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 933 | } |
| 934 | } |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 935 | # ifdef MSWIN |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 936 | // Windows PowerShell output is UTF-16 with BOM so re-encode to the |
| 937 | // current codepage. |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 938 | else if ( fnamecmp(p, "powershell") == 0 |
| 939 | || fnamecmp(p, "powershell.exe") == 0 |
| 940 | ) |
| 941 | { |
| 942 | # if defined(FEAT_QUICKFIX) |
| 943 | if (do_sp) |
| 944 | { |
| 945 | p_sp = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 946 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 947 | } |
| 948 | # endif |
| 949 | if (do_srr) |
| 950 | { |
| 951 | p_srr = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 952 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 953 | } |
| 954 | } |
| 955 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 956 | else |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 957 | // Always use POSIX shell style redirection if we reach this |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 958 | if ( fnamecmp(p, "sh") == 0 |
| 959 | || fnamecmp(p, "ksh") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 960 | || fnamecmp(p, "mksh") == 0 |
| 961 | || fnamecmp(p, "pdksh") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 962 | || fnamecmp(p, "zsh") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 963 | || fnamecmp(p, "zsh-beta") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 964 | || fnamecmp(p, "bash") == 0 |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 965 | || fnamecmp(p, "fish") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 966 | || fnamecmp(p, "ash") == 0 |
| 967 | || fnamecmp(p, "dash") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 968 | || fnamecmp(p, "pwsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 969 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 970 | || fnamecmp(p, "cmd") == 0 |
| 971 | || fnamecmp(p, "sh.exe") == 0 |
| 972 | || fnamecmp(p, "ksh.exe") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 973 | || fnamecmp(p, "mksh.exe") == 0 |
| 974 | || fnamecmp(p, "pdksh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 975 | || fnamecmp(p, "zsh.exe") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 976 | || fnamecmp(p, "zsh-beta.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 977 | || fnamecmp(p, "bash.exe") == 0 |
| 978 | || fnamecmp(p, "cmd.exe") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 979 | || fnamecmp(p, "dash.exe") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 980 | || fnamecmp(p, "pwsh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 981 | # endif |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 982 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 983 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 984 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 985 | if (do_sp) |
| 986 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 987 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 988 | p_sp = (char_u *)">%s 2>&1"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 989 | # else |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 990 | if (fnamecmp(p, "pwsh") == 0) |
| 991 | p_sp = (char_u *)">%s 2>&1"; |
| 992 | else |
| 993 | p_sp = (char_u *)"2>&1| tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 994 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 995 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 996 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 997 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 998 | if (do_srr) |
| 999 | { |
| 1000 | p_srr = (char_u *)">%s 2>&1"; |
| 1001 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1002 | } |
| 1003 | } |
| 1004 | vim_free(p); |
| 1005 | } |
| 1006 | #endif |
| 1007 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1008 | #if defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1009 | /* |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1010 | * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the |
| 1011 | * 'shell' option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1012 | * This is done after other initializations, where 'shell' might have been |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1013 | * set, but only if they have not been set before. |
| 1014 | * Default values depend on shell (cmd.exe is default shell): |
| 1015 | * |
| 1016 | * p_shcf p_sxq |
| 1017 | * cmd.exe - "/c" "(" |
| 1018 | * powershell.exe - "-Command" "\"" |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1019 | * pwsh.exe - "-c" "\"" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1020 | * "sh" like shells - "-c" "\"" |
| 1021 | * |
| 1022 | * For Win32 p_sxq is set instead of p_shq to include shell redirection. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1023 | */ |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1024 | if (strstr((char *)gettail(p_sh), "powershell") != NULL) |
| 1025 | { |
| 1026 | int idx_opt; |
| 1027 | |
| 1028 | idx_opt = findoption((char_u *)"shcf"); |
| 1029 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1030 | { |
| 1031 | p_shcf = (char_u*)"-Command"; |
| 1032 | options[idx_opt].def_val[VI_DEFAULT] = p_shcf; |
| 1033 | } |
| 1034 | |
| 1035 | idx_opt = findoption((char_u *)"sxq"); |
| 1036 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1037 | { |
| 1038 | p_sxq = (char_u*)"\""; |
| 1039 | options[idx_opt].def_val[VI_DEFAULT] = p_sxq; |
| 1040 | } |
| 1041 | } |
| 1042 | else if (strstr((char *)gettail(p_sh), "sh") != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1043 | { |
| 1044 | int idx3; |
| 1045 | |
| 1046 | idx3 = findoption((char_u *)"shcf"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1047 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1048 | { |
| 1049 | p_shcf = (char_u *)"-c"; |
| 1050 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1051 | } |
| 1052 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1053 | // Somehow Win32 requires the quotes around the redirection too |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1054 | idx3 = findoption((char_u *)"sxq"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1055 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1056 | { |
| 1057 | p_sxq = (char_u *)"\""; |
| 1058 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1059 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1060 | } |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1061 | else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL) |
| 1062 | { |
| 1063 | int idx3; |
| 1064 | |
| 1065 | /* |
| 1066 | * cmd.exe on Windows will strip the first and last double quote given |
| 1067 | * on the command line, e.g. most of the time things like: |
| 1068 | * cmd /c "my path/to/echo" "my args to echo" |
| 1069 | * become: |
| 1070 | * my path/to/echo" "my args to echo |
| 1071 | * when executed. |
| 1072 | * |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1073 | * To avoid this, set shellxquote to surround the command in |
| 1074 | * parenthesis. This appears to make most commands work, without |
| 1075 | * breaking commands that worked previously, such as |
| 1076 | * '"path with spaces/cmd" "a&b"'. |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1077 | */ |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1078 | idx3 = findoption((char_u *)"sxq"); |
| 1079 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1080 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1081 | p_sxq = (char_u *)"("; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1082 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1083 | } |
| 1084 | |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1085 | idx3 = findoption((char_u *)"shcf"); |
| 1086 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1087 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1088 | p_shcf = (char_u *)"/c"; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1089 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1090 | } |
| 1091 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1092 | #endif |
| 1093 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1094 | if (BUFEMPTY()) |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1095 | { |
| 1096 | int idx_ffs = findoption((char_u *)"ffs"); |
| 1097 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1098 | // Apply the first entry of 'fileformats' to the initial buffer. |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1099 | if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) |
| 1100 | set_fileformat(default_fileformat(), OPT_LOCAL); |
| 1101 | } |
| 1102 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1103 | #ifdef FEAT_TITLE |
| 1104 | set_title_defaults(); |
| 1105 | #endif |
| 1106 | } |
| 1107 | |
| 1108 | #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
| 1109 | /* |
| 1110 | * When 'helplang' is still at its default value, set it to "lang". |
| 1111 | * Only the first two characters of "lang" are used. |
| 1112 | */ |
| 1113 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1114 | set_helplang_default(char_u *lang) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1115 | { |
| 1116 | int idx; |
| 1117 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1118 | if (lang == NULL || STRLEN(lang) < 2) // safety check |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1119 | return; |
| 1120 | idx = findoption((char_u *)"hlg"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1121 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1122 | { |
| 1123 | if (options[idx].flags & P_ALLOCED) |
| 1124 | free_string_option(p_hlg); |
| 1125 | p_hlg = vim_strsave(lang); |
| 1126 | if (p_hlg == NULL) |
| 1127 | p_hlg = empty_option; |
| 1128 | else |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1129 | { |
Bram Moolenaar | dcd71cb | 2018-11-04 14:40:47 +0100 | [diff] [blame] | 1130 | // zh_CN becomes "cn", zh_TW becomes "tw" |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1131 | if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) |
| 1132 | { |
| 1133 | p_hlg[0] = TOLOWER_ASC(p_hlg[3]); |
| 1134 | p_hlg[1] = TOLOWER_ASC(p_hlg[4]); |
| 1135 | } |
Bram Moolenaar | dcd71cb | 2018-11-04 14:40:47 +0100 | [diff] [blame] | 1136 | // any C like setting, such as C.UTF-8, becomes "en" |
| 1137 | else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') |
| 1138 | { |
| 1139 | p_hlg[0] = 'e'; |
| 1140 | p_hlg[1] = 'n'; |
| 1141 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1142 | p_hlg[2] = NUL; |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1143 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1144 | options[idx].flags |= P_ALLOCED; |
| 1145 | } |
| 1146 | } |
| 1147 | #endif |
| 1148 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1149 | #ifdef FEAT_TITLE |
| 1150 | /* |
| 1151 | * 'title' and 'icon' only default to true if they have not been set or reset |
| 1152 | * in .vimrc and we can read the old value. |
| 1153 | * When 'title' and 'icon' have been reset in .vimrc, we won't even check if |
| 1154 | * they can be reset. This reduces startup time when using X on a remote |
| 1155 | * machine. |
| 1156 | */ |
| 1157 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1158 | set_title_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1159 | { |
| 1160 | int idx1; |
| 1161 | long val; |
| 1162 | |
| 1163 | /* |
| 1164 | * If GUI is (going to be) used, we can always set the window title and |
| 1165 | * icon name. Saves a bit of time, because the X11 display server does |
| 1166 | * not need to be contacted. |
| 1167 | */ |
| 1168 | idx1 = findoption((char_u *)"title"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1169 | if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1170 | { |
| 1171 | #ifdef FEAT_GUI |
| 1172 | if (gui.starting || gui.in_use) |
| 1173 | val = TRUE; |
| 1174 | else |
| 1175 | #endif |
| 1176 | val = mch_can_restore_title(); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1177 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1178 | p_title = val; |
| 1179 | } |
| 1180 | idx1 = findoption((char_u *)"icon"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1181 | if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1182 | { |
| 1183 | #ifdef FEAT_GUI |
| 1184 | if (gui.starting || gui.in_use) |
| 1185 | val = TRUE; |
| 1186 | else |
| 1187 | #endif |
| 1188 | val = mch_can_restore_icon(); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1189 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1190 | p_icon = val; |
| 1191 | } |
| 1192 | } |
| 1193 | #endif |
| 1194 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1195 | void |
| 1196 | ex_set(exarg_T *eap) |
| 1197 | { |
| 1198 | int flags = 0; |
| 1199 | |
| 1200 | if (eap->cmdidx == CMD_setlocal) |
| 1201 | flags = OPT_LOCAL; |
| 1202 | else if (eap->cmdidx == CMD_setglobal) |
| 1203 | flags = OPT_GLOBAL; |
| 1204 | #if defined(FEAT_EVAL) && defined(FEAT_BROWSE) |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 1205 | if ((cmdmod.cmod_flags & CMOD_BROWSE) && flags == 0) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1206 | ex_options(eap); |
| 1207 | else |
| 1208 | #endif |
| 1209 | { |
| 1210 | if (eap->forceit) |
| 1211 | flags |= OPT_ONECOLUMN; |
| 1212 | (void)do_set(eap->arg, flags); |
| 1213 | } |
| 1214 | } |
| 1215 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1216 | /* |
| 1217 | * Parse 'arg' for option settings. |
| 1218 | * |
| 1219 | * 'arg' may be IObuff, but only when no errors can be present and option |
| 1220 | * does not need to be expanded with option_expand(). |
| 1221 | * "opt_flags": |
| 1222 | * 0 for ":set" |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 1223 | * OPT_GLOBAL for ":setglobal" |
| 1224 | * OPT_LOCAL for ":setlocal" and a modeline |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1225 | * OPT_MODELINE for a modeline |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 1226 | * OPT_WINONLY to only set window-local options |
| 1227 | * OPT_NOWIN to skip setting window-local options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1228 | * |
| 1229 | * returns FAIL if an error is detected, OK otherwise |
| 1230 | */ |
| 1231 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1232 | do_set( |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 1233 | char_u *arg_start, // option string (may be written to!) |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1234 | int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1235 | { |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 1236 | char_u *arg = arg_start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1237 | int opt_idx; |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1238 | char *errmsg; |
| 1239 | char errbuf[80]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1240 | char_u *startarg; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1241 | int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name |
| 1242 | int nextchar; // next non-white char after option name |
| 1243 | int afterchar; // character just after option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1244 | int len; |
| 1245 | int i; |
Bram Moolenaar | 22fcfad | 2016-07-01 18:17:26 +0200 | [diff] [blame] | 1246 | varnumber_T value; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1247 | int key; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1248 | long_u flags; // flags for current option |
| 1249 | char_u *varp = NULL; // pointer to variable for current option |
| 1250 | int did_show = FALSE; // already showed one value |
| 1251 | int adding; // "opt+=arg" |
| 1252 | int prepending; // "opt^=arg" |
| 1253 | int removing; // "opt-=arg" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1254 | int cp_val = 0; |
| 1255 | char_u key_name[2]; |
| 1256 | |
| 1257 | if (*arg == NUL) |
| 1258 | { |
| 1259 | showoptions(0, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 1260 | did_show = TRUE; |
| 1261 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1264 | while (*arg != NUL) // loop to process all options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1265 | { |
| 1266 | errmsg = NULL; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1267 | startarg = arg; // remember for error message |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1268 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1269 | if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) |
| 1270 | && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1271 | { |
| 1272 | /* |
| 1273 | * ":set all" show all options. |
| 1274 | * ":set all&" set all options to their default value. |
| 1275 | */ |
| 1276 | arg += 3; |
| 1277 | if (*arg == '&') |
| 1278 | { |
| 1279 | ++arg; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1280 | // Only for :set command set global value of local options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1281 | set_options_default(OPT_FREE | opt_flags); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 1282 | didset_options(); |
| 1283 | didset_options2(); |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 1284 | redraw_all_later(CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1285 | } |
| 1286 | else |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 1287 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1288 | showoptions(1, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 1289 | did_show = TRUE; |
| 1290 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1291 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1292 | else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1293 | { |
| 1294 | showoptions(2, opt_flags); |
| 1295 | show_termcodes(); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 1296 | did_show = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1297 | arg += 7; |
| 1298 | } |
| 1299 | else |
| 1300 | { |
| 1301 | prefix = 1; |
Bram Moolenaar | 2a7b9ee | 2009-06-16 15:50:33 +0000 | [diff] [blame] | 1302 | if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1303 | { |
| 1304 | prefix = 0; |
| 1305 | arg += 2; |
| 1306 | } |
| 1307 | else if (STRNCMP(arg, "inv", 3) == 0) |
| 1308 | { |
| 1309 | prefix = 2; |
| 1310 | arg += 3; |
| 1311 | } |
| 1312 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1313 | // find end of name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1314 | key = 0; |
| 1315 | if (*arg == '<') |
| 1316 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1317 | opt_idx = -1; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1318 | // look out for <t_>;> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1319 | if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) |
| 1320 | len = 5; |
| 1321 | else |
| 1322 | { |
| 1323 | len = 1; |
| 1324 | while (arg[len] != NUL && arg[len] != '>') |
| 1325 | ++len; |
| 1326 | } |
| 1327 | if (arg[len] != '>') |
| 1328 | { |
| 1329 | errmsg = e_invarg; |
| 1330 | goto skip; |
| 1331 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1332 | arg[len] = NUL; // put NUL after name |
| 1333 | if (arg[1] == 't' && arg[2] == '_') // could be term code |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1334 | opt_idx = findoption(arg + 1); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1335 | arg[len++] = '>'; // restore '>' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1336 | if (opt_idx == -1) |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 1337 | key = find_key_option(arg + 1, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1338 | } |
| 1339 | else |
| 1340 | { |
| 1341 | len = 0; |
| 1342 | /* |
| 1343 | * The two characters after "t_" may not be alphanumeric. |
| 1344 | */ |
| 1345 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 1346 | len = 4; |
| 1347 | else |
| 1348 | while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') |
| 1349 | ++len; |
| 1350 | nextchar = arg[len]; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1351 | arg[len] = NUL; // put NUL after name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1352 | opt_idx = findoption(arg); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1353 | arg[len] = nextchar; // restore nextchar |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1354 | if (opt_idx == -1) |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 1355 | key = find_key_option(arg, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1358 | // remember character after option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1359 | afterchar = arg[len]; |
| 1360 | |
Bram Moolenaar | deb108b | 2021-07-08 17:35:36 +0200 | [diff] [blame] | 1361 | if (in_vim9script()) |
| 1362 | { |
| 1363 | char_u *p = skipwhite(arg + len); |
| 1364 | |
| 1365 | // disallow white space before =val, +=val, -=val, ^=val |
| 1366 | if (p > arg + len && (p[0] == '=' |
| 1367 | || (vim_strchr((char_u *)"+-^", p[0]) != NULL |
| 1368 | && p[1] == '='))) |
| 1369 | { |
| 1370 | errmsg = e_no_white_space_allowed_between_option_and; |
| 1371 | arg = p; |
| 1372 | startarg = p; |
| 1373 | goto skip; |
| 1374 | } |
| 1375 | } |
| 1376 | else |
Bram Moolenaar | 208f0b4 | 2021-06-20 12:40:08 +0200 | [diff] [blame] | 1377 | // skip white space, allow ":set ai ?", ":set hlsearch !" |
| 1378 | while (VIM_ISWHITE(arg[len])) |
| 1379 | ++len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1380 | |
| 1381 | adding = FALSE; |
| 1382 | prepending = FALSE; |
| 1383 | removing = FALSE; |
| 1384 | if (arg[len] != NUL && arg[len + 1] == '=') |
| 1385 | { |
| 1386 | if (arg[len] == '+') |
| 1387 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1388 | adding = TRUE; // "+=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1389 | ++len; |
| 1390 | } |
| 1391 | else if (arg[len] == '^') |
| 1392 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1393 | prepending = TRUE; // "^=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1394 | ++len; |
| 1395 | } |
| 1396 | else if (arg[len] == '-') |
| 1397 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1398 | removing = TRUE; // "-=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1399 | ++len; |
| 1400 | } |
| 1401 | } |
| 1402 | nextchar = arg[len]; |
| 1403 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1404 | if (opt_idx == -1 && key == 0) // found a mismatch: skip |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1405 | { |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 1406 | if (in_vim9script() && arg > arg_start |
| 1407 | && vim_strchr((char_u *)"!&<", *arg) != NULL) |
| 1408 | errmsg = e_no_white_space_allowed_between_option_and; |
| 1409 | else |
| 1410 | errmsg = N_("E518: Unknown option"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1411 | goto skip; |
| 1412 | } |
| 1413 | |
| 1414 | if (opt_idx >= 0) |
| 1415 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1416 | if (options[opt_idx].var == NULL) // hidden option: skip |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1417 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1418 | // Only give an error message when requesting the value of |
| 1419 | // a hidden option, ignore setting it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1420 | if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL |
| 1421 | && (!(options[opt_idx].flags & P_BOOL) |
| 1422 | || nextchar == '?')) |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1423 | errmsg = N_("E519: Option not supported"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1424 | goto skip; |
| 1425 | } |
| 1426 | |
| 1427 | flags = options[opt_idx].flags; |
| 1428 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 1429 | } |
| 1430 | else |
| 1431 | { |
| 1432 | flags = P_STRING; |
| 1433 | if (key < 0) |
| 1434 | { |
| 1435 | key_name[0] = KEY2TERMCAP0(key); |
| 1436 | key_name[1] = KEY2TERMCAP1(key); |
| 1437 | } |
| 1438 | else |
| 1439 | { |
| 1440 | key_name[0] = KS_KEY; |
| 1441 | key_name[1] = (key & 0xff); |
| 1442 | } |
| 1443 | } |
| 1444 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1445 | // Skip all options that are not window-local (used when showing |
| 1446 | // an already loaded buffer in a window). |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 1447 | if ((opt_flags & OPT_WINONLY) |
| 1448 | && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) |
| 1449 | goto skip; |
| 1450 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1451 | // Skip all options that are window-local (used for :vimgrep). |
Bram Moolenaar | a3227e2 | 2006-03-08 21:32:40 +0000 | [diff] [blame] | 1452 | if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 |
| 1453 | && options[opt_idx].var == VAR_WIN) |
| 1454 | goto skip; |
| 1455 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1456 | // Disallow changing some options from modelines. |
Bram Moolenaar | 1bf0ddc | 2009-02-11 15:47:05 +0000 | [diff] [blame] | 1457 | if (opt_flags & OPT_MODELINE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1458 | { |
Bram Moolenaar | 865242e | 2010-07-14 21:12:05 +0200 | [diff] [blame] | 1459 | if (flags & (P_SECURE | P_NO_ML)) |
Bram Moolenaar | 1bf0ddc | 2009-02-11 15:47:05 +0000 | [diff] [blame] | 1460 | { |
Bram Moolenaar | 994b89d | 2020-08-07 19:12:41 +0200 | [diff] [blame] | 1461 | errmsg = N_("E520: Not allowed in a modeline"); |
Bram Moolenaar | 1bf0ddc | 2009-02-11 15:47:05 +0000 | [diff] [blame] | 1462 | goto skip; |
| 1463 | } |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 1464 | if ((flags & P_MLE) && !p_mle) |
| 1465 | { |
Bram Moolenaar | 994b89d | 2020-08-07 19:12:41 +0200 | [diff] [blame] | 1466 | errmsg = N_("E992: Not allowed in a modeline when 'modelineexpr' is off"); |
Bram Moolenaar | 110289e | 2019-05-23 15:38:06 +0200 | [diff] [blame] | 1467 | goto skip; |
| 1468 | } |
Bram Moolenaar | f69d9a3 | 2009-02-11 21:48:40 +0000 | [diff] [blame] | 1469 | #ifdef FEAT_DIFF |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1470 | // In diff mode some options are overruled. This avoids that |
| 1471 | // 'foldmethod' becomes "marker" instead of "diff" and that |
| 1472 | // "wrap" gets set. |
Bram Moolenaar | 1bf0ddc | 2009-02-11 15:47:05 +0000 | [diff] [blame] | 1473 | if (curwin->w_p_diff |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1474 | && opt_idx >= 0 // shut up coverity warning |
Bram Moolenaar | a6c0760 | 2017-03-05 21:18:27 +0100 | [diff] [blame] | 1475 | && ( |
| 1476 | #ifdef FEAT_FOLDING |
| 1477 | options[opt_idx].indir == PV_FDM || |
| 1478 | #endif |
| 1479 | options[opt_idx].indir == PV_WRAP)) |
Bram Moolenaar | 1bf0ddc | 2009-02-11 15:47:05 +0000 | [diff] [blame] | 1480 | goto skip; |
Bram Moolenaar | f69d9a3 | 2009-02-11 21:48:40 +0000 | [diff] [blame] | 1481 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1485 | // Disallow changing some options in the sandbox |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 1486 | if (sandbox != 0 && (flags & P_SECURE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1487 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 1488 | errmsg = e_not_allowed_in_sandbox; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1489 | goto skip; |
| 1490 | } |
| 1491 | #endif |
| 1492 | |
| 1493 | if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) |
| 1494 | { |
| 1495 | arg += len; |
| 1496 | cp_val = p_cp; |
| 1497 | if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') |
| 1498 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1499 | if (arg[3] == 'm') // "opt&vim": set to Vim default |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1500 | { |
| 1501 | cp_val = FALSE; |
| 1502 | arg += 3; |
| 1503 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1504 | else // "opt&vi": set to Vi default |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1505 | { |
| 1506 | cp_val = TRUE; |
| 1507 | arg += 2; |
| 1508 | } |
| 1509 | } |
| 1510 | if (vim_strchr((char_u *)"?!&<", nextchar) != NULL |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 1511 | && arg[1] != NUL && !VIM_ISWHITE(arg[1])) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1512 | { |
| 1513 | errmsg = e_trailing; |
| 1514 | goto skip; |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /* |
Bram Moolenaar | a80faa8 | 2020-04-12 19:37:17 +0200 | [diff] [blame] | 1519 | * allow '=' and ':' for historical reasons (MSDOS command.com |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 1520 | * allows only one '=' character per "set" command line. grrr. (jw) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1521 | */ |
| 1522 | if (nextchar == '?' |
| 1523 | || (prefix == 1 |
| 1524 | && vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 1525 | && !(flags & P_BOOL))) |
| 1526 | { |
| 1527 | /* |
| 1528 | * print value |
| 1529 | */ |
| 1530 | if (did_show) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1531 | msg_putchar('\n'); // cursor below last one |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1532 | else |
| 1533 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1534 | gotocmdline(TRUE); // cursor at status line |
| 1535 | did_show = TRUE; // remember that we did a line |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1536 | } |
| 1537 | if (opt_idx >= 0) |
| 1538 | { |
| 1539 | showoneopt(&options[opt_idx], opt_flags); |
| 1540 | #ifdef FEAT_EVAL |
| 1541 | if (p_verbose > 0) |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 1542 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1543 | // Mention where the option was last set. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 1544 | if (varp == options[opt_idx].var) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1545 | last_set_msg(options[opt_idx].script_ctx); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 1546 | else if ((int)options[opt_idx].indir & PV_WIN) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1547 | last_set_msg(curwin->w_p_script_ctx[ |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 1548 | (int)options[opt_idx].indir & PV_MASK]); |
| 1549 | else if ((int)options[opt_idx].indir & PV_BUF) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1550 | last_set_msg(curbuf->b_p_script_ctx[ |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 1551 | (int)options[opt_idx].indir & PV_MASK]); |
| 1552 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1553 | #endif |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | char_u *p; |
| 1558 | |
| 1559 | p = find_termcode(key_name); |
| 1560 | if (p == NULL) |
| 1561 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1562 | errmsg = N_("E846: Key code not set"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1563 | goto skip; |
| 1564 | } |
| 1565 | else |
| 1566 | (void)show_one_termcode(key_name, p, TRUE); |
| 1567 | } |
| 1568 | if (nextchar != '?' |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 1569 | && nextchar != NUL && !VIM_ISWHITE(afterchar)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1570 | errmsg = e_trailing; |
| 1571 | } |
| 1572 | else |
| 1573 | { |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 1574 | int value_is_replaced = !prepending && !adding && !removing; |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 1575 | int value_checked = FALSE; |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 1576 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1577 | if (flags & P_BOOL) // boolean |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1578 | { |
| 1579 | if (nextchar == '=' || nextchar == ':') |
| 1580 | { |
| 1581 | errmsg = e_invarg; |
| 1582 | goto skip; |
| 1583 | } |
| 1584 | |
| 1585 | /* |
| 1586 | * ":set opt!": invert |
| 1587 | * ":set opt&": reset to default value |
| 1588 | * ":set opt<": reset to global value |
| 1589 | */ |
| 1590 | if (nextchar == '!') |
| 1591 | value = *(int *)(varp) ^ 1; |
| 1592 | else if (nextchar == '&') |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1593 | value = (int)(long)(long_i)options[opt_idx].def_val[ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1594 | ((flags & P_VI_DEF) || cp_val) |
| 1595 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1596 | else if (nextchar == '<') |
| 1597 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1598 | // For 'autoread' -1 means to use global value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1599 | if ((int *)varp == &curbuf->b_p_ar |
| 1600 | && opt_flags == OPT_LOCAL) |
| 1601 | value = -1; |
| 1602 | else |
| 1603 | value = *(int *)get_varp_scope(&(options[opt_idx]), |
| 1604 | OPT_GLOBAL); |
| 1605 | } |
| 1606 | else |
| 1607 | { |
| 1608 | /* |
| 1609 | * ":set invopt": invert |
| 1610 | * ":set opt" or ":set noopt": set or reset |
| 1611 | */ |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 1612 | if (nextchar != NUL && !VIM_ISWHITE(afterchar)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1613 | { |
| 1614 | errmsg = e_trailing; |
| 1615 | goto skip; |
| 1616 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1617 | if (prefix == 2) // inv |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1618 | value = *(int *)(varp) ^ 1; |
| 1619 | else |
| 1620 | value = prefix; |
| 1621 | } |
| 1622 | |
| 1623 | errmsg = set_bool_option(opt_idx, varp, (int)value, |
| 1624 | opt_flags); |
| 1625 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1626 | else // numeric or string |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1627 | { |
| 1628 | if (vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 1629 | || prefix != 1) |
| 1630 | { |
| 1631 | errmsg = e_invarg; |
| 1632 | goto skip; |
| 1633 | } |
| 1634 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1635 | if (flags & P_NUM) // numeric |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1636 | { |
| 1637 | /* |
| 1638 | * Different ways to set a number option: |
| 1639 | * & set to default value |
| 1640 | * < set to global value |
| 1641 | * <xx> accept special key codes for 'wildchar' |
| 1642 | * c accept any non-digit for 'wildchar' |
| 1643 | * [-]0-9 set number |
| 1644 | * other error |
| 1645 | */ |
| 1646 | ++arg; |
| 1647 | if (nextchar == '&') |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1648 | value = (long)(long_i)options[opt_idx].def_val[ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1649 | ((flags & P_VI_DEF) || cp_val) |
| 1650 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1651 | else if (nextchar == '<') |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 1652 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1653 | // For 'undolevels' NO_LOCAL_UNDOLEVEL means to |
| 1654 | // use the global value. |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 1655 | if ((long *)varp == &curbuf->b_p_ul |
| 1656 | && opt_flags == OPT_LOCAL) |
| 1657 | value = NO_LOCAL_UNDOLEVEL; |
| 1658 | else |
| 1659 | value = *(long *)get_varp_scope( |
| 1660 | &(options[opt_idx]), OPT_GLOBAL); |
| 1661 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1662 | else if (((long *)varp == &p_wc |
| 1663 | || (long *)varp == &p_wcm) |
| 1664 | && (*arg == '<' |
| 1665 | || *arg == '^' |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 1666 | || (*arg != NUL |
| 1667 | && (!arg[1] || VIM_ISWHITE(arg[1])) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1668 | && !VIM_ISDIGIT(*arg)))) |
| 1669 | { |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 1670 | value = string_to_key(arg, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1671 | if (value == 0 && (long *)varp != &p_wcm) |
| 1672 | { |
| 1673 | errmsg = e_invarg; |
| 1674 | goto skip; |
| 1675 | } |
| 1676 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1677 | else if (*arg == '-' || VIM_ISDIGIT(*arg)) |
| 1678 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1679 | // Allow negative (for 'undolevels'), octal and |
| 1680 | // hex numbers. |
Bram Moolenaar | 887c1fe | 2016-01-02 17:56:35 +0100 | [diff] [blame] | 1681 | vim_str2nr(arg, NULL, &i, STR2NR_ALL, |
Bram Moolenaar | 16e9b85 | 2019-05-19 19:59:35 +0200 | [diff] [blame] | 1682 | &value, NULL, 0, TRUE); |
Bram Moolenaar | 06e2c81 | 2019-06-12 19:05:48 +0200 | [diff] [blame] | 1683 | if (i == 0 || (arg[i] != NUL |
| 1684 | && !VIM_ISWHITE(arg[i]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1685 | { |
Bram Moolenaar | 16e9b85 | 2019-05-19 19:59:35 +0200 | [diff] [blame] | 1686 | errmsg = N_("E521: Number required after ="); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1687 | goto skip; |
| 1688 | } |
| 1689 | } |
| 1690 | else |
| 1691 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1692 | errmsg = N_("E521: Number required after ="); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1693 | goto skip; |
| 1694 | } |
| 1695 | |
| 1696 | if (adding) |
| 1697 | value = *(long *)varp + value; |
| 1698 | if (prepending) |
| 1699 | value = *(long *)varp * value; |
| 1700 | if (removing) |
| 1701 | value = *(long *)varp - value; |
| 1702 | errmsg = set_num_option(opt_idx, varp, value, |
Bram Moolenaar | 555b280 | 2005-05-19 21:08:39 +0000 | [diff] [blame] | 1703 | errbuf, sizeof(errbuf), opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1704 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1705 | else if (opt_idx >= 0) // string |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1706 | { |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1707 | char_u *save_arg = NULL; |
| 1708 | char_u *s = NULL; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1709 | char_u *oldval = NULL; // previous value if *varp |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1710 | char_u *newval; |
| 1711 | char_u *origval = NULL; |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1712 | char_u *origval_l = NULL; |
| 1713 | char_u *origval_g = NULL; |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 1714 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1715 | char_u *saved_origval = NULL; |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1716 | char_u *saved_origval_l = NULL; |
| 1717 | char_u *saved_origval_g = NULL; |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1718 | char_u *saved_newval = NULL; |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 1719 | #endif |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1720 | unsigned newlen; |
| 1721 | int comma; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1722 | int new_value_alloced; // new string option |
| 1723 | // was allocated |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1724 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1725 | // When using ":set opt=val" for a global option |
| 1726 | // with a local value the local value will be |
| 1727 | // reset, use the global value here. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1728 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 1729 | && ((int)options[opt_idx].indir & PV_BOTH)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1730 | varp = options[opt_idx].var; |
| 1731 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1732 | // The old value is kept until we are sure that the |
| 1733 | // new value is valid. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1734 | oldval = *(char_u **)varp; |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1735 | |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1736 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 1737 | { |
| 1738 | origval_l = *(char_u **)get_varp_scope( |
| 1739 | &(options[opt_idx]), OPT_LOCAL); |
| 1740 | origval_g = *(char_u **)get_varp_scope( |
| 1741 | &(options[opt_idx]), OPT_GLOBAL); |
| 1742 | |
| 1743 | // A global-local string option might have an empty |
| 1744 | // option as value to indicate that the global |
| 1745 | // value should be used. |
| 1746 | if (((int)options[opt_idx].indir & PV_BOTH) |
| 1747 | && origval_l == empty_option) |
| 1748 | origval_l = origval_g; |
| 1749 | } |
| 1750 | |
| 1751 | // When setting the local value of a global |
| 1752 | // option, the old value may be the global value. |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 1753 | if (((int)options[opt_idx].indir & PV_BOTH) |
| 1754 | && (opt_flags & OPT_LOCAL)) |
| 1755 | origval = *(char_u **)get_varp( |
| 1756 | &options[opt_idx]); |
| 1757 | else |
| 1758 | origval = oldval; |
| 1759 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1760 | if (nextchar == '&') // set to default val |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1761 | { |
| 1762 | newval = options[opt_idx].def_val[ |
| 1763 | ((flags & P_VI_DEF) || cp_val) |
| 1764 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1765 | if ((char_u **)varp == &p_bg) |
| 1766 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1767 | // guess the value of 'background' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1768 | #ifdef FEAT_GUI |
| 1769 | if (gui.in_use) |
| 1770 | newval = gui_bg_default(); |
| 1771 | else |
| 1772 | #endif |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 1773 | newval = term_bg_default(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1774 | } |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 1775 | else if ((char_u **)varp == &p_fencs && enc_utf8) |
| 1776 | newval = fencs_utf8_default; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1777 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1778 | // expand environment variables and ~ (since the |
| 1779 | // default value was already expanded, only |
| 1780 | // required when an environment variable was set |
| 1781 | // later |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1782 | if (newval == NULL) |
| 1783 | newval = empty_option; |
| 1784 | else |
| 1785 | { |
| 1786 | s = option_expand(opt_idx, newval); |
| 1787 | if (s == NULL) |
| 1788 | s = newval; |
| 1789 | newval = vim_strsave(s); |
| 1790 | } |
| 1791 | new_value_alloced = TRUE; |
| 1792 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1793 | else if (nextchar == '<') // set to global val |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1794 | { |
| 1795 | newval = vim_strsave(*(char_u **)get_varp_scope( |
| 1796 | &(options[opt_idx]), OPT_GLOBAL)); |
| 1797 | new_value_alloced = TRUE; |
| 1798 | } |
| 1799 | else |
| 1800 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1801 | ++arg; // jump to after the '=' or ':' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1802 | |
| 1803 | /* |
| 1804 | * Set 'keywordprg' to ":help" if an empty |
| 1805 | * value was passed to :set by the user. |
| 1806 | * Misuse errbuf[] for the resulting string. |
| 1807 | */ |
| 1808 | if (varp == (char_u *)&p_kp |
| 1809 | && (*arg == NUL || *arg == ' ')) |
| 1810 | { |
| 1811 | STRCPY(errbuf, ":help"); |
| 1812 | save_arg = arg; |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1813 | arg = (char_u *)errbuf; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1814 | } |
| 1815 | /* |
Bram Moolenaar | 4e5ccfa | 2011-11-30 11:15:47 +0100 | [diff] [blame] | 1816 | * Convert 'backspace' number to string, for |
| 1817 | * adding, prepending and removing string. |
| 1818 | */ |
| 1819 | else if (varp == (char_u *)&p_bs |
| 1820 | && VIM_ISDIGIT(**(char_u **)varp)) |
| 1821 | { |
| 1822 | i = getdigits((char_u **)varp); |
| 1823 | switch (i) |
| 1824 | { |
| 1825 | case 0: |
| 1826 | *(char_u **)varp = empty_option; |
| 1827 | break; |
| 1828 | case 1: |
| 1829 | *(char_u **)varp = vim_strsave( |
| 1830 | (char_u *)"indent,eol"); |
| 1831 | break; |
| 1832 | case 2: |
| 1833 | *(char_u **)varp = vim_strsave( |
| 1834 | (char_u *)"indent,eol,start"); |
| 1835 | break; |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 1836 | case 3: |
| 1837 | *(char_u **)varp = vim_strsave( |
| 1838 | (char_u *)"indent,eol,nostop"); |
| 1839 | break; |
Bram Moolenaar | 4e5ccfa | 2011-11-30 11:15:47 +0100 | [diff] [blame] | 1840 | } |
| 1841 | vim_free(oldval); |
Bram Moolenaar | edbc0d4 | 2017-08-20 16:11:51 +0200 | [diff] [blame] | 1842 | if (origval == oldval) |
| 1843 | origval = *(char_u **)varp; |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 1844 | if (origval_l == oldval) |
| 1845 | origval_l = *(char_u **)varp; |
| 1846 | if (origval_g == oldval) |
| 1847 | origval_g = *(char_u **)varp; |
Bram Moolenaar | 4e5ccfa | 2011-11-30 11:15:47 +0100 | [diff] [blame] | 1848 | oldval = *(char_u **)varp; |
| 1849 | } |
| 1850 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1851 | * Convert 'whichwrap' number to string, for |
| 1852 | * backwards compatibility with Vim 3.0. |
| 1853 | * Misuse errbuf[] for the resulting string. |
| 1854 | */ |
| 1855 | else if (varp == (char_u *)&p_ww |
| 1856 | && VIM_ISDIGIT(*arg)) |
| 1857 | { |
| 1858 | *errbuf = NUL; |
| 1859 | i = getdigits(&arg); |
| 1860 | if (i & 1) |
| 1861 | STRCAT(errbuf, "b,"); |
| 1862 | if (i & 2) |
| 1863 | STRCAT(errbuf, "s,"); |
| 1864 | if (i & 4) |
| 1865 | STRCAT(errbuf, "h,l,"); |
| 1866 | if (i & 8) |
| 1867 | STRCAT(errbuf, "<,>,"); |
| 1868 | if (i & 16) |
| 1869 | STRCAT(errbuf, "[,],"); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1870 | if (*errbuf != NUL) // remove trailing , |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1871 | errbuf[STRLEN(errbuf) - 1] = NUL; |
| 1872 | save_arg = arg; |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1873 | arg = (char_u *)errbuf; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1874 | } |
| 1875 | /* |
| 1876 | * Remove '>' before 'dir' and 'bdir', for |
| 1877 | * backwards compatibility with version 3.0 |
| 1878 | */ |
| 1879 | else if ( *arg == '>' |
| 1880 | && (varp == (char_u *)&p_dir |
| 1881 | || varp == (char_u *)&p_bdir)) |
| 1882 | { |
| 1883 | ++arg; |
| 1884 | } |
| 1885 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1886 | /* |
| 1887 | * Copy the new string into allocated memory. |
| 1888 | * Can't use set_string_option_direct(), because |
| 1889 | * we need to remove the backslashes. |
| 1890 | */ |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1891 | // get a bit too much |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1892 | newlen = (unsigned)STRLEN(arg) + 1; |
| 1893 | if (adding || prepending || removing) |
| 1894 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1895 | newval = alloc(newlen); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1896 | if (newval == NULL) // out of mem, don't change |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1897 | break; |
| 1898 | s = newval; |
| 1899 | |
| 1900 | /* |
| 1901 | * Copy the string, skip over escaped chars. |
| 1902 | * For MS-DOS and WIN32 backslashes before normal |
| 1903 | * file name characters are not removed, and keep |
| 1904 | * backslash at start, for "\\machine\path", but |
| 1905 | * do remove it for "\\\\machine\\path". |
| 1906 | * The reverse is found in ExpandOldSetting(). |
| 1907 | */ |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 1908 | while (*arg && !VIM_ISWHITE(*arg)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1909 | { |
| 1910 | if (*arg == '\\' && arg[1] != NUL |
| 1911 | #ifdef BACKSLASH_IN_FILENAME |
| 1912 | && !((flags & P_EXPAND) |
| 1913 | && vim_isfilec(arg[1]) |
Bram Moolenaar | 994b89d | 2020-08-07 19:12:41 +0200 | [diff] [blame] | 1914 | && !VIM_ISWHITE(arg[1]) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1915 | && (arg[1] != '\\' |
| 1916 | || (s == newval |
| 1917 | && arg[2] != '\\'))) |
| 1918 | #endif |
| 1919 | ) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1920 | ++arg; // remove backslash |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1921 | if (has_mbyte |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 1922 | && (i = (*mb_ptr2len)(arg)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1923 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1924 | // copy multibyte char |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1925 | mch_memmove(s, arg, (size_t)i); |
| 1926 | arg += i; |
| 1927 | s += i; |
| 1928 | } |
| 1929 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1930 | *s++ = *arg++; |
| 1931 | } |
| 1932 | *s = NUL; |
| 1933 | |
| 1934 | /* |
| 1935 | * Expand environment variables and ~. |
| 1936 | * Don't do it when adding without inserting a |
| 1937 | * comma. |
| 1938 | */ |
| 1939 | if (!(adding || prepending || removing) |
| 1940 | || (flags & P_COMMA)) |
| 1941 | { |
| 1942 | s = option_expand(opt_idx, newval); |
| 1943 | if (s != NULL) |
| 1944 | { |
| 1945 | vim_free(newval); |
| 1946 | newlen = (unsigned)STRLEN(s) + 1; |
| 1947 | if (adding || prepending || removing) |
| 1948 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1949 | newval = alloc(newlen); |
| 1950 | if (newval == NULL) |
| 1951 | break; |
| 1952 | STRCPY(newval, s); |
| 1953 | } |
| 1954 | } |
| 1955 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1956 | // locate newval[] in origval[] when removing it |
| 1957 | // and when adding to avoid duplicates |
| 1958 | i = 0; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1959 | if (removing || (flags & P_NODUP)) |
| 1960 | { |
| 1961 | i = (int)STRLEN(newval); |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1962 | s = find_dup_item(origval, newval, flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1963 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1964 | // do not add if already there |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1965 | if ((adding || prepending) && s != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1966 | { |
| 1967 | prepending = FALSE; |
| 1968 | adding = FALSE; |
| 1969 | STRCPY(newval, origval); |
| 1970 | } |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 1971 | |
| 1972 | // if no duplicate, move pointer to end of |
| 1973 | // original value |
| 1974 | if (s == NULL) |
| 1975 | s = origval + (int)STRLEN(origval); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1978 | // concatenate the two strings; add a ',' if |
| 1979 | // needed |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1980 | if (adding || prepending) |
| 1981 | { |
| 1982 | comma = ((flags & P_COMMA) && *origval != NUL |
| 1983 | && *newval != NUL); |
| 1984 | if (adding) |
| 1985 | { |
| 1986 | i = (int)STRLEN(origval); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1987 | // strip a trailing comma, would get 2 |
Bram Moolenaar | 1746747 | 2015-11-10 17:50:24 +0100 | [diff] [blame] | 1988 | if (comma && i > 1 |
| 1989 | && (flags & P_ONECOMMA) == P_ONECOMMA |
| 1990 | && origval[i - 1] == ',' |
| 1991 | && origval[i - 2] != '\\') |
Bram Moolenaar | a7b7b1c | 2015-06-19 14:06:43 +0200 | [diff] [blame] | 1992 | i--; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1993 | mch_memmove(newval + i + comma, newval, |
| 1994 | STRLEN(newval) + 1); |
| 1995 | mch_memmove(newval, origval, (size_t)i); |
| 1996 | } |
| 1997 | else |
| 1998 | { |
| 1999 | i = (int)STRLEN(newval); |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 2000 | STRMOVE(newval + i + comma, origval); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2001 | } |
| 2002 | if (comma) |
| 2003 | newval[i] = ','; |
| 2004 | } |
| 2005 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2006 | // Remove newval[] from origval[]. (Note: "i" has |
| 2007 | // been set above and is used here). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2008 | if (removing) |
| 2009 | { |
| 2010 | STRCPY(newval, origval); |
| 2011 | if (*s) |
| 2012 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2013 | // may need to remove a comma |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2014 | if (flags & P_COMMA) |
| 2015 | { |
| 2016 | if (s == origval) |
| 2017 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2018 | // include comma after string |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2019 | if (s[i] == ',') |
| 2020 | ++i; |
| 2021 | } |
| 2022 | else |
| 2023 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2024 | // include comma before string |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2025 | --s; |
| 2026 | ++i; |
| 2027 | } |
| 2028 | } |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 2029 | STRMOVE(newval + (s - origval), s + i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | if (flags & P_FLAGLIST) |
| 2034 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2035 | // Remove flags that appear twice. |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 2036 | for (s = newval; *s;) |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2037 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2038 | // if options have P_FLAGLIST and |
| 2039 | // P_ONECOMMA such as 'whichwrap' |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2040 | if (flags & P_ONECOMMA) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2041 | { |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2042 | if (*s != ',' && *(s + 1) == ',' |
| 2043 | && vim_strchr(s + 2, *s) != NULL) |
| 2044 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2045 | // Remove the duplicated value and |
| 2046 | // the next comma. |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2047 | STRMOVE(s, s + 2); |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 2048 | continue; |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2049 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2050 | } |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2051 | else |
| 2052 | { |
| 2053 | if ((!(flags & P_COMMA) || *s != ',') |
| 2054 | && vim_strchr(s + 1, *s) != NULL) |
| 2055 | { |
| 2056 | STRMOVE(s, s + 1); |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 2057 | continue; |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2058 | } |
| 2059 | } |
Bram Moolenaar | aaaf57d | 2017-02-05 14:13:20 +0100 | [diff] [blame] | 2060 | ++s; |
Bram Moolenaar | c8ce615 | 2016-08-07 13:48:20 +0200 | [diff] [blame] | 2061 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2064 | if (save_arg != NULL) // number for 'whichwrap' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2065 | arg = save_arg; |
| 2066 | new_value_alloced = TRUE; |
| 2067 | } |
| 2068 | |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 2069 | /* |
| 2070 | * Set the new value. |
| 2071 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2072 | *(char_u **)(varp) = newval; |
| 2073 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 2074 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 5cbb8db | 2015-07-17 23:08:29 +0200 | [diff] [blame] | 2075 | if (!starting |
| 2076 | # ifdef FEAT_CRYPT |
| 2077 | && options[opt_idx].indir != PV_KEY |
| 2078 | # endif |
Bram Moolenaar | 182a17b | 2017-06-25 20:57:18 +0200 | [diff] [blame] | 2079 | && origval != NULL && newval != NULL) |
| 2080 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2081 | // origval may be freed by |
| 2082 | // did_set_string_option(), make a copy. |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 2083 | saved_origval = vim_strsave(origval); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2084 | // newval (and varp) may become invalid if the |
| 2085 | // buffer is closed by autocommands. |
Bram Moolenaar | 182a17b | 2017-06-25 20:57:18 +0200 | [diff] [blame] | 2086 | saved_newval = vim_strsave(newval); |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2087 | if (origval_l != NULL) |
| 2088 | saved_origval_l = vim_strsave(origval_l); |
| 2089 | if (origval_g != NULL) |
| 2090 | saved_origval_g = vim_strsave(origval_g); |
Bram Moolenaar | 182a17b | 2017-06-25 20:57:18 +0200 | [diff] [blame] | 2091 | } |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 2092 | #endif |
| 2093 | |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2094 | { |
| 2095 | long_u *p = insecure_flag(opt_idx, opt_flags); |
Bram Moolenaar | 48f377a | 2018-12-21 13:03:28 +0100 | [diff] [blame] | 2096 | int secure_saved = secure; |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2097 | |
| 2098 | // When an option is set in the sandbox, from a |
| 2099 | // modeline or in secure mode, then deal with side |
| 2100 | // effects in secure mode. Also when the value was |
| 2101 | // set with the P_INSECURE flag and is not |
| 2102 | // completely replaced. |
Bram Moolenaar | 82b033e | 2019-03-24 14:02:04 +0100 | [diff] [blame] | 2103 | if ((opt_flags & OPT_MODELINE) |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2104 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 82b033e | 2019-03-24 14:02:04 +0100 | [diff] [blame] | 2105 | || sandbox != 0 |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2106 | #endif |
Bram Moolenaar | 82b033e | 2019-03-24 14:02:04 +0100 | [diff] [blame] | 2107 | || (!value_is_replaced && (*p & P_INSECURE))) |
| 2108 | secure = 1; |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2109 | |
Bram Moolenaar | 48f377a | 2018-12-21 13:03:28 +0100 | [diff] [blame] | 2110 | // Handle side effects, and set the global value |
| 2111 | // for ":set" on local options. Note: when setting |
| 2112 | // 'syntax' or 'filetype' autocommands may be |
| 2113 | // triggered that can cause havoc. |
| 2114 | errmsg = did_set_string_option( |
| 2115 | opt_idx, (char_u **)varp, |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2116 | new_value_alloced, oldval, errbuf, |
| 2117 | opt_flags, &value_checked); |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2118 | |
Bram Moolenaar | 48f377a | 2018-12-21 13:03:28 +0100 | [diff] [blame] | 2119 | secure = secure_saved; |
Bram Moolenaar | 247bb7e | 2018-11-20 14:27:07 +0100 | [diff] [blame] | 2120 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2121 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 2122 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 2123 | if (errmsg == NULL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2124 | trigger_optionsset_string( |
| 2125 | opt_idx, opt_flags, saved_origval, |
| 2126 | saved_origval_l, saved_origval_g, |
| 2127 | saved_newval); |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 2128 | vim_free(saved_origval); |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2129 | vim_free(saved_origval_l); |
| 2130 | vim_free(saved_origval_g); |
Bram Moolenaar | 8efa026 | 2017-08-20 15:47:20 +0200 | [diff] [blame] | 2131 | vim_free(saved_newval); |
| 2132 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2133 | // If error detected, print the error message. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2134 | if (errmsg != NULL) |
| 2135 | goto skip; |
| 2136 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2137 | else // key code option |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2138 | { |
| 2139 | char_u *p; |
| 2140 | |
| 2141 | if (nextchar == '&') |
| 2142 | { |
| 2143 | if (add_termcap_entry(key_name, TRUE) == FAIL) |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 2144 | errmsg = N_("E522: Not found in termcap"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2145 | } |
| 2146 | else |
| 2147 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2148 | ++arg; // jump to after the '=' or ':' |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 2149 | for (p = arg; *p && !VIM_ISWHITE(*p); ++p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2150 | if (*p == '\\' && p[1] != NUL) |
| 2151 | ++p; |
| 2152 | nextchar = *p; |
| 2153 | *p = NUL; |
| 2154 | add_termcode(key_name, arg, FALSE); |
| 2155 | *p = nextchar; |
| 2156 | } |
| 2157 | if (full_screen) |
| 2158 | ttest(FALSE); |
| 2159 | redraw_all_later(CLEAR); |
| 2160 | } |
| 2161 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2162 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2163 | if (opt_idx >= 0) |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2164 | did_set_option( |
| 2165 | opt_idx, opt_flags, value_is_replaced, value_checked); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | skip: |
| 2169 | /* |
| 2170 | * Advance to next argument. |
| 2171 | * - skip until a blank found, taking care of backslashes |
| 2172 | * - skip blanks |
| 2173 | * - skip one "=val" argument (for hidden options ":set gfn =xx") |
| 2174 | */ |
| 2175 | for (i = 0; i < 2 ; ++i) |
| 2176 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 2177 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2178 | if (*arg++ == '\\' && *arg != NUL) |
| 2179 | ++arg; |
| 2180 | arg = skipwhite(arg); |
| 2181 | if (*arg != '=') |
| 2182 | break; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | if (errmsg != NULL) |
| 2187 | { |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 2188 | vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2189 | i = (int)STRLEN(IObuff) + 2; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2190 | if (i + (arg - startarg) < IOSIZE) |
| 2191 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2192 | // append the argument with the error |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2193 | STRCAT(IObuff, ": "); |
| 2194 | mch_memmove(IObuff + i, startarg, (arg - startarg)); |
| 2195 | IObuff[i + (arg - startarg)] = NUL; |
| 2196 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2197 | // make sure all characters are printable |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2198 | trans_characters(IObuff, IOSIZE); |
| 2199 | |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 2200 | ++no_wait_return; // wait_return done later |
| 2201 | emsg((char *)IObuff); // show error highlighted |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2202 | --no_wait_return; |
| 2203 | |
| 2204 | return FAIL; |
| 2205 | } |
| 2206 | |
| 2207 | arg = skipwhite(arg); |
| 2208 | } |
| 2209 | |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2210 | theend: |
| 2211 | if (silent_mode && did_show) |
| 2212 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2213 | // After displaying option values in silent mode. |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2214 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2215 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2216 | msg_putchar('\n'); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2217 | cursor_on(); // msg_start() switches it off |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2218 | out_flush(); |
| 2219 | silent_mode = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2220 | info_message = FALSE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2223 | return OK; |
| 2224 | } |
| 2225 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2226 | /* |
| 2227 | * Call this when an option has been given a new value through a user command. |
| 2228 | * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. |
| 2229 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2230 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2231 | did_set_option( |
| 2232 | int opt_idx, |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2233 | int opt_flags, // possibly with OPT_MODELINE |
| 2234 | int new_value, // value was replaced completely |
| 2235 | int value_checked) // value was checked to be safe, no need to set the |
| 2236 | // P_INSECURE flag. |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2237 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2238 | long_u *p; |
| 2239 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2240 | options[opt_idx].flags |= P_WAS_SET; |
| 2241 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2242 | // When an option is set in the sandbox, from a modeline or in secure mode |
| 2243 | // set the P_INSECURE flag. Otherwise, if a new value is stored reset the |
| 2244 | // flag. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2245 | p = insecure_flag(opt_idx, opt_flags); |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2246 | if (!value_checked && (secure |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2247 | #ifdef HAVE_SANDBOX |
| 2248 | || sandbox != 0 |
| 2249 | #endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2250 | || (opt_flags & OPT_MODELINE))) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2251 | *p = *p | P_INSECURE; |
| 2252 | else if (new_value) |
| 2253 | *p = *p & ~P_INSECURE; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2256 | /* |
| 2257 | * Convert a key name or string into a key value. |
| 2258 | * Used for 'wildchar' and 'cedit' options. |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2259 | * When "multi_byte" is TRUE allow for multi-byte characters. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2260 | */ |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2261 | int |
| 2262 | string_to_key(char_u *arg, int multi_byte) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2263 | { |
| 2264 | if (*arg == '<') |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 2265 | return find_key_option(arg + 1, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2266 | if (*arg == '^') |
| 2267 | return Ctrl_chr(arg[1]); |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2268 | if (multi_byte) |
| 2269 | return PTR2CHAR(arg); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2270 | return *arg; |
| 2271 | } |
| 2272 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2273 | #ifdef FEAT_TITLE |
| 2274 | /* |
| 2275 | * When changing 'title', 'titlestring', 'icon' or 'iconstring', call |
| 2276 | * maketitle() to create and display it. |
| 2277 | * When switching the title or icon off, call mch_restore_title() to get |
| 2278 | * the old value back. |
| 2279 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2280 | void |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 2281 | did_set_title(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2282 | { |
| 2283 | if (starting != NO_SCREEN |
| 2284 | #ifdef FEAT_GUI |
| 2285 | && !gui.starting |
| 2286 | #endif |
| 2287 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2288 | maketitle(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2289 | } |
| 2290 | #endif |
| 2291 | |
| 2292 | /* |
| 2293 | * set_options_bin - called when 'bin' changes value. |
| 2294 | */ |
| 2295 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2296 | set_options_bin( |
| 2297 | int oldval, |
| 2298 | int newval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2299 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2300 | { |
| 2301 | /* |
| 2302 | * The option values that are changed when 'bin' changes are |
| 2303 | * copied when 'bin is set and restored when 'bin' is reset. |
| 2304 | */ |
| 2305 | if (newval) |
| 2306 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2307 | if (!oldval) // switched on |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2308 | { |
| 2309 | if (!(opt_flags & OPT_GLOBAL)) |
| 2310 | { |
| 2311 | curbuf->b_p_tw_nobin = curbuf->b_p_tw; |
| 2312 | curbuf->b_p_wm_nobin = curbuf->b_p_wm; |
| 2313 | curbuf->b_p_ml_nobin = curbuf->b_p_ml; |
| 2314 | curbuf->b_p_et_nobin = curbuf->b_p_et; |
| 2315 | } |
| 2316 | if (!(opt_flags & OPT_LOCAL)) |
| 2317 | { |
| 2318 | p_tw_nobin = p_tw; |
| 2319 | p_wm_nobin = p_wm; |
| 2320 | p_ml_nobin = p_ml; |
| 2321 | p_et_nobin = p_et; |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | if (!(opt_flags & OPT_GLOBAL)) |
| 2326 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2327 | curbuf->b_p_tw = 0; // no automatic line wrap |
| 2328 | curbuf->b_p_wm = 0; // no automatic line wrap |
| 2329 | curbuf->b_p_ml = 0; // no modelines |
| 2330 | curbuf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2331 | } |
| 2332 | if (!(opt_flags & OPT_LOCAL)) |
| 2333 | { |
| 2334 | p_tw = 0; |
| 2335 | p_wm = 0; |
| 2336 | p_ml = FALSE; |
| 2337 | p_et = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2338 | p_bin = TRUE; // needed when called for the "-b" argument |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2339 | } |
| 2340 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2341 | else if (oldval) // switched off |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2342 | { |
| 2343 | if (!(opt_flags & OPT_GLOBAL)) |
| 2344 | { |
| 2345 | curbuf->b_p_tw = curbuf->b_p_tw_nobin; |
| 2346 | curbuf->b_p_wm = curbuf->b_p_wm_nobin; |
| 2347 | curbuf->b_p_ml = curbuf->b_p_ml_nobin; |
| 2348 | curbuf->b_p_et = curbuf->b_p_et_nobin; |
| 2349 | } |
| 2350 | if (!(opt_flags & OPT_LOCAL)) |
| 2351 | { |
| 2352 | p_tw = p_tw_nobin; |
| 2353 | p_wm = p_wm_nobin; |
| 2354 | p_ml = p_ml_nobin; |
| 2355 | p_et = p_et_nobin; |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2360 | /* |
| 2361 | * Expand environment variables for some string options. |
| 2362 | * These string options cannot be indirect! |
| 2363 | * If "val" is NULL expand the current value of the option. |
| 2364 | * Return pointer to NameBuff, or NULL when not expanded. |
| 2365 | */ |
| 2366 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2367 | option_expand(int opt_idx, char_u *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2368 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2369 | // if option doesn't need expansion nothing to do |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2370 | if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) |
| 2371 | return NULL; |
| 2372 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2373 | // If val is longer than MAXPATHL no meaningful expansion can be done, |
| 2374 | // expand_env() would truncate the string. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2375 | if (val != NULL && STRLEN(val) > MAXPATHL) |
| 2376 | return NULL; |
| 2377 | |
| 2378 | if (val == NULL) |
| 2379 | val = *(char_u **)options[opt_idx].var; |
| 2380 | |
| 2381 | /* |
| 2382 | * Expanding this with NameBuff, expand_env() must not be passed IObuff. |
| 2383 | * Escape spaces when expanding 'tags', they are used to separate file |
| 2384 | * names. |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2385 | * For 'spellsuggest' expand after "file:". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2386 | */ |
| 2387 | expand_env_esc(val, NameBuff, MAXPATHL, |
Bram Moolenaar | 9f0545d | 2007-09-26 20:36:32 +0000 | [diff] [blame] | 2388 | (char_u **)options[opt_idx].var == &p_tags, FALSE, |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2389 | #ifdef FEAT_SPELL |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2390 | (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : |
| 2391 | #endif |
| 2392 | NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2393 | if (STRCMP(NameBuff, val) == 0) // they are the same |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2394 | return NULL; |
| 2395 | |
| 2396 | return NameBuff; |
| 2397 | } |
| 2398 | |
| 2399 | /* |
| 2400 | * After setting various option values: recompute variables that depend on |
| 2401 | * option values. |
| 2402 | */ |
| 2403 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2404 | didset_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2405 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2406 | // initialize the table for 'iskeyword' et.al. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2407 | (void)init_chartab(); |
| 2408 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2409 | didset_string_options(); |
| 2410 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2411 | #ifdef FEAT_SPELL |
Bram Moolenaar | 8aff23a | 2005-08-19 20:40:30 +0000 | [diff] [blame] | 2412 | (void)spell_check_msm(); |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2413 | (void)spell_check_sps(); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2414 | (void)compile_cap_prog(curwin->w_s); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2415 | (void)did_set_spell_option(TRUE); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 2416 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2417 | #ifdef FEAT_CMDWIN |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2418 | // set cedit_key |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2419 | (void)check_cedit(); |
| 2420 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 2421 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2422 | // initialize the table for 'breakat'. |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2423 | fill_breakat_flags(); |
| 2424 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2425 | after_copy_winopt(curwin); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | /* |
| 2429 | * More side effects of setting options. |
| 2430 | */ |
| 2431 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2432 | didset_options2(void) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2433 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2434 | // Initialize the highlight_attr[] table. |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2435 | (void)highlight_changed(); |
| 2436 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2437 | // Parse default for 'wildmode' |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2438 | check_opt_wim(); |
| 2439 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2440 | // Parse default for 'listchars'. |
| 2441 | (void)set_chars_option(curwin, &curwin->w_p_lcs); |
| 2442 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2443 | // Parse default for 'fillchars'. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2444 | (void)set_chars_option(curwin, &p_fcs); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2445 | |
| 2446 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2447 | // Parse default for 'clipboard' |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2448 | (void)check_clipboard_option(); |
| 2449 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2450 | #ifdef FEAT_VARTABS |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2451 | vim_free(curbuf->b_p_vsts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2452 | (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2453 | vim_free(curbuf->b_p_vts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2454 | (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2455 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | /* |
| 2459 | * Check for string options that are NULL (normally only termcap options). |
| 2460 | */ |
| 2461 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2462 | check_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2463 | { |
| 2464 | int opt_idx; |
| 2465 | |
| 2466 | for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) |
| 2467 | if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) |
| 2468 | check_string_option((char_u **)get_varp(&(options[opt_idx]))); |
| 2469 | } |
| 2470 | |
| 2471 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2472 | * Return the option index found by a pointer into term_strings[]. |
| 2473 | * Return -1 if not found. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2474 | */ |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2475 | int |
| 2476 | get_term_opt_idx(char_u **p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2477 | { |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2478 | int opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2479 | |
| 2480 | for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) |
| 2481 | if (options[opt_idx].var == (char_u *)p) |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2482 | return opt_idx; |
| 2483 | return -1; // cannot happen: didn't find it! |
| 2484 | } |
| 2485 | |
| 2486 | /* |
| 2487 | * Mark a terminal option as allocated, found by a pointer into term_strings[]. |
| 2488 | * Return the option index or -1 if not found. |
| 2489 | */ |
| 2490 | int |
| 2491 | set_term_option_alloced(char_u **p) |
| 2492 | { |
| 2493 | int opt_idx = get_term_opt_idx(p); |
| 2494 | |
| 2495 | if (opt_idx >= 0) |
| 2496 | options[opt_idx].flags |= P_ALLOCED; |
| 2497 | return opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2500 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2501 | /* |
| 2502 | * Return TRUE when option "opt" was set from a modeline or in secure mode. |
| 2503 | * Return FALSE when it wasn't. |
| 2504 | * Return -1 for an unknown option. |
| 2505 | */ |
| 2506 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2507 | was_set_insecurely(char_u *opt, int opt_flags) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2508 | { |
| 2509 | int idx = findoption(opt); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2510 | long_u *flagp; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2511 | |
| 2512 | if (idx >= 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2513 | { |
| 2514 | flagp = insecure_flag(idx, opt_flags); |
| 2515 | return (*flagp & P_INSECURE) != 0; |
| 2516 | } |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 2517 | internal_error("was_set_insecurely()"); |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2518 | return -1; |
| 2519 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2520 | |
| 2521 | /* |
| 2522 | * Get a pointer to the flags used for the P_INSECURE flag of option |
| 2523 | * "opt_idx". For some local options a local flags field is used. |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 2524 | * NOTE: Caller must make sure that "curwin" is set to the window from which |
| 2525 | * the option is used. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2526 | */ |
| 2527 | static long_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2528 | insecure_flag(int opt_idx, int opt_flags) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2529 | { |
| 2530 | if (opt_flags & OPT_LOCAL) |
| 2531 | switch ((int)options[opt_idx].indir) |
| 2532 | { |
| 2533 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2534 | case PV_STL: return &curwin->w_p_stl_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2535 | #endif |
| 2536 | #ifdef FEAT_EVAL |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2537 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2538 | case PV_FDE: return &curwin->w_p_fde_flags; |
| 2539 | case PV_FDT: return &curwin->w_p_fdt_flags; |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2540 | # endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 2541 | # ifdef FEAT_BEVAL |
| 2542 | case PV_BEXPR: return &curbuf->b_p_bexpr_flags; |
| 2543 | # endif |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2544 | # if defined(FEAT_CINDENT) |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2545 | case PV_INDE: return &curbuf->b_p_inde_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2546 | # endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2547 | case PV_FEX: return &curbuf->b_p_fex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2548 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2549 | case PV_INEX: return &curbuf->b_p_inex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2550 | # endif |
| 2551 | #endif |
| 2552 | } |
| 2553 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2554 | // Nothing special, return global flags field. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2555 | return &options[opt_idx].flags; |
| 2556 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2557 | #endif |
| 2558 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2559 | #if defined(FEAT_TITLE) || defined(PROTO) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2560 | /* |
| 2561 | * Redraw the window title and/or tab page text later. |
| 2562 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2563 | void redraw_titles(void) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2564 | { |
| 2565 | need_maketitle = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2566 | redraw_tabline = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2567 | } |
| 2568 | #endif |
| 2569 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2570 | /* |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2571 | * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII |
| 2572 | * characters or characters in "allowed". |
| 2573 | */ |
Bram Moolenaar | e677df8 | 2019-09-02 22:31:11 +0200 | [diff] [blame] | 2574 | int |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2575 | valid_name(char_u *val, char *allowed) |
| 2576 | { |
| 2577 | char_u *s; |
| 2578 | |
| 2579 | for (s = val; *s != NUL; ++s) |
| 2580 | if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL) |
| 2581 | return FALSE; |
| 2582 | return TRUE; |
| 2583 | } |
| 2584 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2585 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2586 | /* |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2587 | * Set the script_ctx for an option, taking care of setting the buffer- or |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2588 | * window-local value. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2589 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2590 | void |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2591 | set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2592 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2593 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 2594 | int indir = (int)options[opt_idx].indir; |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2595 | sctx_T new_script_ctx = script_ctx; |
| 2596 | |
Bram Moolenaar | 5125874 | 2020-05-03 17:19:33 +0200 | [diff] [blame] | 2597 | // Modeline already has the line number set. |
| 2598 | if (!(opt_flags & OPT_MODELINE)) |
| 2599 | new_script_ctx.sc_lnum += SOURCING_LNUM; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2600 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2601 | // Remember where the option was set. For local options need to do that |
| 2602 | // in the buffer or window structure. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2603 | if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2604 | options[opt_idx].script_ctx = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2605 | if (both || (opt_flags & OPT_LOCAL)) |
| 2606 | { |
| 2607 | if (indir & PV_BUF) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2608 | curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2609 | else if (indir & PV_WIN) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2610 | curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2611 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2612 | } |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2613 | |
| 2614 | /* |
| 2615 | * Set the script_ctx for a termcap option. |
| 2616 | * "name" must be the two character code, e.g. "RV". |
| 2617 | * When "name" is NULL use "opt_idx". |
| 2618 | */ |
| 2619 | void |
| 2620 | set_term_option_sctx_idx(char *name, int opt_idx) |
| 2621 | { |
| 2622 | char_u buf[5]; |
| 2623 | int idx; |
| 2624 | |
| 2625 | if (name == NULL) |
| 2626 | idx = opt_idx; |
| 2627 | else |
| 2628 | { |
| 2629 | buf[0] = 't'; |
| 2630 | buf[1] = '_'; |
| 2631 | buf[2] = name[0]; |
| 2632 | buf[3] = name[1]; |
| 2633 | buf[4] = 0; |
| 2634 | idx = findoption(buf); |
| 2635 | } |
| 2636 | if (idx >= 0) |
| 2637 | set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx); |
| 2638 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2639 | #endif |
| 2640 | |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 2641 | #if defined(FEAT_EVAL) |
| 2642 | /* |
| 2643 | * Apply the OptionSet autocommand. |
| 2644 | */ |
| 2645 | static void |
| 2646 | apply_optionset_autocmd( |
| 2647 | int opt_idx, |
| 2648 | long opt_flags, |
| 2649 | long oldval, |
| 2650 | long oldval_g, |
| 2651 | long newval, |
| 2652 | char *errmsg) |
| 2653 | { |
| 2654 | char_u buf_old[12], buf_old_global[12], buf_new[12], buf_type[12]; |
| 2655 | |
| 2656 | // Don't do this while starting up, failure or recursively. |
| 2657 | if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL) |
| 2658 | return; |
| 2659 | |
| 2660 | vim_snprintf((char *)buf_old, sizeof(buf_old), "%ld", oldval); |
| 2661 | vim_snprintf((char *)buf_old_global, sizeof(buf_old_global), "%ld", |
| 2662 | oldval_g); |
| 2663 | vim_snprintf((char *)buf_new, sizeof(buf_new), "%ld", newval); |
| 2664 | vim_snprintf((char *)buf_type, sizeof(buf_type), "%s", |
| 2665 | (opt_flags & OPT_LOCAL) ? "local" : "global"); |
| 2666 | set_vim_var_string(VV_OPTION_NEW, buf_new, -1); |
| 2667 | set_vim_var_string(VV_OPTION_OLD, buf_old, -1); |
| 2668 | set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
| 2669 | if (opt_flags & OPT_LOCAL) |
| 2670 | { |
| 2671 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
| 2672 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 2673 | } |
| 2674 | if (opt_flags & OPT_GLOBAL) |
| 2675 | { |
| 2676 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
| 2677 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); |
| 2678 | } |
| 2679 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 2680 | { |
| 2681 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
| 2682 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 2683 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); |
| 2684 | } |
| 2685 | if (opt_flags & OPT_MODELINE) |
| 2686 | { |
| 2687 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
| 2688 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 2689 | } |
| 2690 | apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, |
| 2691 | NULL, FALSE, NULL); |
| 2692 | reset_v_option_vars(); |
| 2693 | } |
| 2694 | #endif |
| 2695 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2696 | /* |
| 2697 | * Set the value of a boolean option, and take care of side effects. |
| 2698 | * Returns NULL for success, or an error message for an error. |
| 2699 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 2700 | static char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2701 | set_bool_option( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2702 | int opt_idx, // index in options[] table |
| 2703 | char_u *varp, // pointer to the option variable |
| 2704 | int value, // new value |
| 2705 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2706 | { |
| 2707 | int old_value = *(int *)varp; |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 2708 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2709 | int old_global_value = 0; |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 2710 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2711 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2712 | // Disallow changing some options from secure mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2713 | if ((secure |
| 2714 | #ifdef HAVE_SANDBOX |
| 2715 | || sandbox != 0 |
| 2716 | #endif |
| 2717 | ) && (options[opt_idx].flags & P_SECURE)) |
| 2718 | return e_secure; |
| 2719 | |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 2720 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2721 | // Save the global value before changing anything. This is needed as for |
| 2722 | // a global-only option setting the "local value" in fact sets the global |
| 2723 | // value (since there is only one value). |
| 2724 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 2725 | old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), |
| 2726 | OPT_GLOBAL); |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 2727 | #endif |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 2728 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2729 | *(int *)varp = value; // set the new value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2730 | #ifdef FEAT_EVAL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2731 | // Remember where the option was set. |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2732 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2733 | #endif |
| 2734 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2735 | #ifdef FEAT_GUI |
| 2736 | need_mouse_correct = TRUE; |
| 2737 | #endif |
| 2738 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2739 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2740 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 2741 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; |
| 2742 | |
| 2743 | /* |
| 2744 | * Handle side effects of changing a bool option. |
| 2745 | */ |
| 2746 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2747 | // 'compatible' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2748 | if ((int *)varp == &p_cp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2749 | compatible_set(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2750 | |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 2751 | #ifdef FEAT_LANGMAP |
| 2752 | if ((int *)varp == &p_lrm) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2753 | // 'langremap' -> !'langnoremap' |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 2754 | p_lnr = !p_lrm; |
| 2755 | else if ((int *)varp == &p_lnr) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2756 | // 'langnoremap' -> !'langremap' |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 2757 | p_lrm = !p_lnr; |
| 2758 | #endif |
| 2759 | |
Bram Moolenaar | 8c63e0e | 2018-09-25 22:17:54 +0200 | [diff] [blame] | 2760 | #ifdef FEAT_SYN_HL |
| 2761 | else if ((int *)varp == &curwin->w_p_cul && !value && old_value) |
| 2762 | reset_cursorline(); |
| 2763 | #endif |
| 2764 | |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2765 | #ifdef FEAT_PERSISTENT_UNDO |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2766 | // 'undofile' |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2767 | else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) |
| 2768 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2769 | // Only take action when the option was set. When reset we do not |
| 2770 | // delete the undo file, the option may be set again without making |
| 2771 | // any changes in between. |
Bram Moolenaar | e8d8fd2 | 2012-10-21 03:46:05 +0200 | [diff] [blame] | 2772 | if (curbuf->b_p_udf || p_udf) |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2773 | { |
Bram Moolenaar | e8d8fd2 | 2012-10-21 03:46:05 +0200 | [diff] [blame] | 2774 | char_u hash[UNDO_HASH_SIZE]; |
| 2775 | buf_T *save_curbuf = curbuf; |
| 2776 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 2777 | FOR_ALL_BUFFERS(curbuf) |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2778 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2779 | // When 'undofile' is set globally: for every buffer, otherwise |
| 2780 | // only for the current buffer: Try to read in the undofile, |
| 2781 | // if one exists, the buffer wasn't changed and the buffer was |
| 2782 | // loaded |
Bram Moolenaar | e8d8fd2 | 2012-10-21 03:46:05 +0200 | [diff] [blame] | 2783 | if ((curbuf == save_curbuf |
| 2784 | || (opt_flags & OPT_GLOBAL) || opt_flags == 0) |
| 2785 | && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) |
| 2786 | { |
Christian Brabandt | f573c6e | 2021-06-20 14:02:16 +0200 | [diff] [blame] | 2787 | #ifdef FEAT_CRYPT |
| 2788 | if (crypt_get_method_nr(curbuf) == CRYPT_M_SOD) |
| 2789 | continue; |
| 2790 | #endif |
Bram Moolenaar | e8d8fd2 | 2012-10-21 03:46:05 +0200 | [diff] [blame] | 2791 | u_compute_hash(hash); |
| 2792 | u_read_undo(NULL, hash, curbuf->b_fname); |
| 2793 | } |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2794 | } |
Bram Moolenaar | e8d8fd2 | 2012-10-21 03:46:05 +0200 | [diff] [blame] | 2795 | curbuf = save_curbuf; |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2796 | } |
Bram Moolenaar | 374d32d | 2012-01-04 19:34:37 +0100 | [diff] [blame] | 2797 | } |
| 2798 | #endif |
| 2799 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2800 | else if ((int *)varp == &curbuf->b_p_ro) |
| 2801 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2802 | // when 'readonly' is reset globally, also reset readonlymode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2803 | if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) |
| 2804 | readonlymode = FALSE; |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2805 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2806 | // when 'readonly' is set may give W10 again |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2807 | if (curbuf->b_p_ro) |
| 2808 | curbuf->b_did_warn = FALSE; |
| 2809 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2810 | #ifdef FEAT_TITLE |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2811 | redraw_titles(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2812 | #endif |
| 2813 | } |
| 2814 | |
Bram Moolenaar | 9c44972 | 2010-07-20 18:44:27 +0200 | [diff] [blame] | 2815 | #ifdef FEAT_GUI |
| 2816 | else if ((int *)varp == &p_mh) |
| 2817 | { |
| 2818 | if (!p_mh) |
| 2819 | gui_mch_mousehide(FALSE); |
| 2820 | } |
| 2821 | #endif |
| 2822 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2823 | // when 'modifiable' is changed, redraw the window title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2824 | else if ((int *)varp == &curbuf->b_p_ma) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2825 | { |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 2826 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2827 | // Cannot set 'modifiable' when in Terminal mode. |
Bram Moolenaar | d7db27b | 2018-03-07 23:02:33 +0100 | [diff] [blame] | 2828 | if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) |
| 2829 | && curbuf->b_term != NULL && !term_is_finished(curbuf)))) |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 2830 | { |
| 2831 | curbuf->b_p_ma = FALSE; |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 2832 | return N_("E946: Cannot make a terminal with running job modifiable"); |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 2833 | } |
| 2834 | # endif |
| 2835 | # ifdef FEAT_TITLE |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2836 | redraw_titles(); |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 2837 | # endif |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2838 | } |
Bram Moolenaar | 423802d | 2017-07-30 16:52:24 +0200 | [diff] [blame] | 2839 | #ifdef FEAT_TITLE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2840 | // when 'endofline' is changed, redraw the window title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2841 | else if ((int *)varp == &curbuf->b_p_eol) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2842 | { |
| 2843 | redraw_titles(); |
| 2844 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2845 | // when 'fixeol' is changed, redraw the window title |
Bram Moolenaar | 34d72d4 | 2015-07-17 14:18:08 +0200 | [diff] [blame] | 2846 | else if ((int *)varp == &curbuf->b_p_fixeol) |
| 2847 | { |
| 2848 | redraw_titles(); |
| 2849 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2850 | // when 'bomb' is changed, redraw the window title and tab page text |
Bram Moolenaar | 83eb885 | 2007-08-12 13:51:26 +0000 | [diff] [blame] | 2851 | else if ((int *)varp == &curbuf->b_p_bomb) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2852 | { |
| 2853 | redraw_titles(); |
| 2854 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2855 | #endif |
| 2856 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2857 | // when 'bin' is set also set some other options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2858 | else if ((int *)varp == &curbuf->b_p_bin) |
| 2859 | { |
| 2860 | set_options_bin(old_value, curbuf->b_p_bin, opt_flags); |
| 2861 | #ifdef FEAT_TITLE |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2862 | redraw_titles(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2863 | #endif |
| 2864 | } |
| 2865 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2866 | // when 'buflisted' changes, trigger autocommands |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2867 | else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) |
| 2868 | { |
| 2869 | apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, |
| 2870 | NULL, NULL, TRUE, curbuf); |
| 2871 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2872 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2873 | // when 'swf' is set, create swapfile, when reset remove swapfile |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2874 | else if ((int *)varp == &curbuf->b_p_swf) |
| 2875 | { |
| 2876 | if (curbuf->b_p_swf && p_uc) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2877 | ml_open_file(curbuf); // create the swap file |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2878 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2879 | // no need to reset curbuf->b_may_swap, ml_open_file() will check |
| 2880 | // buf->b_p_swf |
| 2881 | mf_close_file(curbuf, TRUE); // remove the swap file |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2884 | // when 'terse' is set change 'shortmess' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2885 | else if ((int *)varp == &p_terse) |
| 2886 | { |
| 2887 | char_u *p; |
| 2888 | |
| 2889 | p = vim_strchr(p_shm, SHM_SEARCH); |
| 2890 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2891 | // insert 's' in p_shm |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2892 | if (p_terse && p == NULL) |
| 2893 | { |
| 2894 | STRCPY(IObuff, p_shm); |
| 2895 | STRCAT(IObuff, "s"); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2896 | set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2897 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2898 | // remove 's' from p_shm |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2899 | else if (!p_terse && p != NULL) |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 2900 | STRMOVE(p, p + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2903 | // when 'paste' is set or reset also change other options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2904 | else if ((int *)varp == &p_paste) |
| 2905 | { |
| 2906 | paste_option_changed(); |
| 2907 | } |
| 2908 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2909 | // when 'insertmode' is set from an autocommand need to do work here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2910 | else if ((int *)varp == &p_im) |
| 2911 | { |
| 2912 | if (p_im) |
| 2913 | { |
| 2914 | if ((State & INSERT) == 0) |
| 2915 | need_start_insertmode = TRUE; |
| 2916 | stop_insert_mode = FALSE; |
| 2917 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2918 | // only reset if it was set previously |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 2919 | else if (old_value) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2920 | { |
| 2921 | need_start_insertmode = FALSE; |
| 2922 | stop_insert_mode = TRUE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 2923 | if (restart_edit != 0 && mode_displayed) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2924 | clear_cmdline = TRUE; // remove "(insert)" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2925 | restart_edit = 0; |
| 2926 | } |
| 2927 | } |
| 2928 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2929 | // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2930 | else if ((int *)varp == &p_ic && p_hls) |
| 2931 | { |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2932 | redraw_all_later(SOME_VALID); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2936 | // when 'hlsearch' is set or reset: reset no_hlsearch |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2937 | else if ((int *)varp == &p_hls) |
| 2938 | { |
Bram Moolenaar | 451fc7b | 2018-04-27 22:53:07 +0200 | [diff] [blame] | 2939 | set_no_hlsearch(FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2940 | } |
| 2941 | #endif |
| 2942 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2943 | // when 'scrollbind' is set: snapshot the current position to avoid a jump |
| 2944 | // at the end of normal_cmd() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2945 | else if ((int *)varp == &curwin->w_p_scb) |
| 2946 | { |
| 2947 | if (curwin->w_p_scb) |
Bram Moolenaar | 04c5c9e | 2013-07-09 13:44:59 +0200 | [diff] [blame] | 2948 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2949 | do_check_scrollbind(FALSE); |
Bram Moolenaar | 04c5c9e | 2013-07-09 13:44:59 +0200 | [diff] [blame] | 2950 | curwin->w_scbind_pos = curwin->w_topline; |
| 2951 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2952 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2953 | |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 2954 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2955 | // There can be only one window with 'previewwindow' set. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2956 | else if ((int *)varp == &curwin->w_p_pvw) |
| 2957 | { |
| 2958 | if (curwin->w_p_pvw) |
| 2959 | { |
| 2960 | win_T *win; |
| 2961 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 2962 | FOR_ALL_WINDOWS(win) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2963 | if (win->w_p_pvw && win != curwin) |
| 2964 | { |
| 2965 | curwin->w_p_pvw = FALSE; |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 2966 | return N_("E590: A preview window already exists"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | #endif |
| 2971 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2972 | // when 'textmode' is set or reset also change 'fileformat' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2973 | else if ((int *)varp == &curbuf->b_p_tx) |
| 2974 | { |
| 2975 | set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags); |
| 2976 | } |
| 2977 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2978 | // when 'textauto' is set or reset also change 'fileformats' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2979 | else if ((int *)varp == &p_ta) |
Bram Moolenaar | abab0b0 | 2019-03-30 18:47:01 +0100 | [diff] [blame] | 2980 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2981 | set_string_option_direct((char_u *)"ffs", -1, |
| 2982 | p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2983 | OPT_FREE | opt_flags, 0); |
Bram Moolenaar | abab0b0 | 2019-03-30 18:47:01 +0100 | [diff] [blame] | 2984 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2985 | |
| 2986 | /* |
| 2987 | * When 'lisp' option changes include/exclude '-' in |
| 2988 | * keyword characters. |
| 2989 | */ |
| 2990 | #ifdef FEAT_LISP |
| 2991 | else if (varp == (char_u *)&(curbuf->b_p_lisp)) |
| 2992 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2993 | (void)buf_init_chartab(curbuf, FALSE); // ignore errors |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2994 | } |
| 2995 | #endif |
| 2996 | |
| 2997 | #ifdef FEAT_TITLE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2998 | // when 'title' changed, may need to change the title; same for 'icon' |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 2999 | else if ((int *)varp == &p_title || (int *)varp == &p_icon) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3000 | { |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 3001 | did_set_title(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3002 | } |
| 3003 | #endif |
| 3004 | |
| 3005 | else if ((int *)varp == &curbuf->b_changed) |
| 3006 | { |
| 3007 | if (!value) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3008 | save_file_ff(curbuf); // Buffer is unchanged |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3009 | #ifdef FEAT_TITLE |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 3010 | redraw_titles(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3011 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3012 | modified_was_set = value; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | #ifdef BACKSLASH_IN_FILENAME |
| 3016 | else if ((int *)varp == &p_ssl) |
| 3017 | { |
| 3018 | if (p_ssl) |
| 3019 | { |
| 3020 | psepc = '/'; |
| 3021 | psepcN = '\\'; |
| 3022 | pseps[0] = '/'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3023 | } |
| 3024 | else |
| 3025 | { |
| 3026 | psepc = '\\'; |
| 3027 | psepcN = '/'; |
| 3028 | pseps[0] = '\\'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3031 | // need to adjust the file name arguments and buffer names. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3032 | buflist_slash_adjust(); |
| 3033 | alist_slash_adjust(); |
| 3034 | # ifdef FEAT_EVAL |
| 3035 | scriptnames_slash_adjust(); |
| 3036 | # endif |
| 3037 | } |
| 3038 | #endif |
| 3039 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3040 | // If 'wrap' is set, set w_leftcol to zero. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3041 | else if ((int *)varp == &curwin->w_p_wrap) |
| 3042 | { |
| 3043 | if (curwin->w_p_wrap) |
| 3044 | curwin->w_leftcol = 0; |
| 3045 | } |
| 3046 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3047 | else if ((int *)varp == &p_ea) |
| 3048 | { |
| 3049 | if (p_ea && !old_value) |
| 3050 | win_equal(curwin, FALSE, 0); |
| 3051 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3052 | |
| 3053 | else if ((int *)varp == &p_wiv) |
| 3054 | { |
| 3055 | /* |
| 3056 | * When 'weirdinvert' changed, set/reset 't_xs'. |
| 3057 | * Then set 'weirdinvert' according to value of 't_xs'. |
| 3058 | */ |
| 3059 | if (p_wiv && !old_value) |
| 3060 | T_XS = (char_u *)"y"; |
| 3061 | else if (!p_wiv && old_value) |
| 3062 | T_XS = empty_option; |
| 3063 | p_wiv = (*T_XS != NUL); |
| 3064 | } |
| 3065 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 3066 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3067 | else if ((int *)varp == &p_beval) |
| 3068 | { |
Bram Moolenaar | 51b0f37 | 2017-11-18 18:52:04 +0100 | [diff] [blame] | 3069 | if (!balloonEvalForTerm) |
| 3070 | { |
| 3071 | if (p_beval && !old_value) |
| 3072 | gui_mch_enable_beval_area(balloonEval); |
| 3073 | else if (!p_beval && old_value) |
| 3074 | gui_mch_disable_beval_area(balloonEval); |
| 3075 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3076 | } |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 3077 | #endif |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 3078 | #ifdef FEAT_BEVAL_TERM |
Bram Moolenaar | 51b0f37 | 2017-11-18 18:52:04 +0100 | [diff] [blame] | 3079 | else if ((int *)varp == &p_bevalterm) |
| 3080 | { |
| 3081 | mch_bevalterm_changed(); |
| 3082 | } |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 3083 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3084 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 3085 | #ifdef FEAT_AUTOCHDIR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3086 | else if ((int *)varp == &p_acd) |
| 3087 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3088 | // Change directories when the 'acd' option is set now. |
Bram Moolenaar | 6f47002 | 2018-04-10 18:47:20 +0200 | [diff] [blame] | 3089 | DO_AUTOCHDIR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3090 | } |
| 3091 | #endif |
| 3092 | |
| 3093 | #ifdef FEAT_DIFF |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3094 | // 'diff' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3095 | else if ((int *)varp == &curwin->w_p_diff) |
| 3096 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3097 | // May add or remove the buffer from the list of diff buffers. |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 3098 | diff_buf_adjust(curwin); |
| 3099 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3100 | if (foldmethodIsDiff(curwin)) |
| 3101 | foldUpdateAll(curwin); |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 3102 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3103 | } |
| 3104 | #endif |
| 3105 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 3106 | #ifdef HAVE_INPUT_METHOD |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3107 | // 'imdisable' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3108 | else if ((int *)varp == &p_imdisable) |
| 3109 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3110 | // Only de-activate it here, it will be enabled when changing mode. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3111 | if (p_imdisable) |
| 3112 | im_set_active(FALSE); |
Bram Moolenaar | 725a962 | 2011-10-12 16:57:13 +0200 | [diff] [blame] | 3113 | else if (State & INSERT) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3114 | // When the option is set from an autocommand, it may need to take |
| 3115 | // effect right away. |
Bram Moolenaar | 725a962 | 2011-10-12 16:57:13 +0200 | [diff] [blame] | 3116 | im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3117 | } |
| 3118 | #endif |
| 3119 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 3120 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3121 | // 'spell' |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3122 | else if ((int *)varp == &curwin->w_p_spell) |
| 3123 | { |
| 3124 | if (curwin->w_p_spell) |
| 3125 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 3126 | char *errmsg = did_set_spelllang(curwin); |
| 3127 | |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3128 | if (errmsg != NULL) |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 3129 | emsg(_(errmsg)); |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | #endif |
| 3133 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3134 | #ifdef FEAT_ARABIC |
| 3135 | if ((int *)varp == &curwin->w_p_arab) |
| 3136 | { |
| 3137 | if (curwin->w_p_arab) |
| 3138 | { |
| 3139 | /* |
| 3140 | * 'arabic' is set, handle various sub-settings. |
| 3141 | */ |
| 3142 | if (!p_tbidi) |
| 3143 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3144 | // set rightleft mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3145 | if (!curwin->w_p_rl) |
| 3146 | { |
| 3147 | curwin->w_p_rl = TRUE; |
| 3148 | changed_window_setting(); |
| 3149 | } |
| 3150 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3151 | // Enable Arabic shaping (major part of what Arabic requires) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3152 | if (!p_arshape) |
| 3153 | { |
| 3154 | p_arshape = TRUE; |
| 3155 | redraw_later_clear(); |
| 3156 | } |
| 3157 | } |
| 3158 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3159 | // Arabic requires a utf-8 encoding, inform the user if its not |
| 3160 | // set. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3161 | if (STRCMP(p_enc, "utf-8") != 0) |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 3162 | { |
Bram Moolenaar | 496c526 | 2009-03-18 14:42:00 +0000 | [diff] [blame] | 3163 | static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); |
| 3164 | |
Bram Moolenaar | 8820b48 | 2017-03-16 17:23:31 +0100 | [diff] [blame] | 3165 | msg_source(HL_ATTR(HLF_W)); |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 3166 | msg_attr(_(w_arabic), HL_ATTR(HLF_W)); |
Bram Moolenaar | 496c526 | 2009-03-18 14:42:00 +0000 | [diff] [blame] | 3167 | #ifdef FEAT_EVAL |
| 3168 | set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); |
| 3169 | #endif |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 3170 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3171 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3172 | // set 'delcombine' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3173 | p_deco = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3174 | |
| 3175 | # ifdef FEAT_KEYMAP |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3176 | // Force-set the necessary keymap for arabic |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3177 | set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", |
| 3178 | OPT_LOCAL); |
| 3179 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3180 | } |
| 3181 | else |
| 3182 | { |
| 3183 | /* |
| 3184 | * 'arabic' is reset, handle various sub-settings. |
| 3185 | */ |
| 3186 | if (!p_tbidi) |
| 3187 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3188 | // reset rightleft mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3189 | if (curwin->w_p_rl) |
| 3190 | { |
| 3191 | curwin->w_p_rl = FALSE; |
| 3192 | changed_window_setting(); |
| 3193 | } |
| 3194 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3195 | // 'arabicshape' isn't reset, it is a global option and |
| 3196 | // another window may still need it "on". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3199 | // 'delcombine' isn't reset, it is a global option and another |
| 3200 | // window may still want it "on". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3201 | |
| 3202 | # ifdef FEAT_KEYMAP |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3203 | // Revert to the default keymap |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3204 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3205 | curbuf->b_p_imsearch = B_IMODE_USE_INSERT; |
| 3206 | # endif |
| 3207 | } |
Bram Moolenaar | 801f8b8 | 2009-07-29 13:42:05 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Bram Moolenaar | 319bdbd | 2009-09-11 13:20:33 +0000 | [diff] [blame] | 3210 | #endif |
| 3211 | |
Bram Moolenaar | 4482621 | 2019-08-22 21:23:20 +0200 | [diff] [blame] | 3212 | #if defined(FEAT_SIGNS) && defined(FEAT_GUI) |
| 3213 | else if (((int *)varp == &curwin->w_p_nu |
| 3214 | || (int *)varp == &curwin->w_p_rnu) |
| 3215 | && gui.in_use |
| 3216 | && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u') |
| 3217 | && curbuf->b_signlist != NULL) |
| 3218 | { |
| 3219 | // If the 'number' or 'relativenumber' options are modified and |
| 3220 | // 'signcolumn' is set to 'number', then clear the screen for a full |
| 3221 | // refresh. Otherwise the sign icons are not displayed properly in the |
| 3222 | // number column. If the 'number' option is set and only the |
| 3223 | // 'relativenumber' option is toggled, then don't refresh the screen |
| 3224 | // (optimization). |
| 3225 | if (!(curwin->w_p_nu && ((int *)varp == &curwin->w_p_rnu))) |
| 3226 | redraw_all_later(CLEAR); |
| 3227 | } |
| 3228 | #endif |
| 3229 | |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 3230 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3231 | // 'termguicolors' |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 3232 | else if ((int *)varp == &p_tgc) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 3233 | { |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3234 | # ifdef FEAT_VTP |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3235 | // Do not turn on 'tgc' when 24-bit colors are not supported. |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 3236 | if ( |
| 3237 | # ifdef VIMDLL |
| 3238 | !gui.in_use && !gui.starting && |
| 3239 | # endif |
| 3240 | !has_vtp_working()) |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3241 | { |
| 3242 | p_tgc = 0; |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 3243 | return N_("E954: 24-bit colors are not supported on this environment"); |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3244 | } |
Bram Moolenaar | c5cd885 | 2018-05-01 15:47:38 +0200 | [diff] [blame] | 3245 | if (is_term_win32()) |
| 3246 | swap_tcap(); |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3247 | # endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 3248 | # ifdef FEAT_GUI |
| 3249 | if (!gui.in_use && !gui.starting) |
| 3250 | # endif |
| 3251 | highlight_gui_started(); |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3252 | # ifdef FEAT_VTP |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3253 | // reset t_Co |
Bram Moolenaar | c5cd885 | 2018-05-01 15:47:38 +0200 | [diff] [blame] | 3254 | if (is_term_win32()) |
Bram Moolenaar | b0eb14f | 2018-06-28 15:29:52 +0200 | [diff] [blame] | 3255 | { |
| 3256 | control_console_color_rgb(); |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3257 | set_termname(T_NAME); |
Bram Moolenaar | b0eb14f | 2018-06-28 15:29:52 +0200 | [diff] [blame] | 3258 | init_highlight(TRUE, FALSE); |
| 3259 | } |
Bram Moolenaar | cafafb3 | 2018-02-22 21:07:09 +0100 | [diff] [blame] | 3260 | # endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 3261 | } |
| 3262 | #endif |
| 3263 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3264 | /* |
| 3265 | * End of handling side effects for bool options. |
| 3266 | */ |
| 3267 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3268 | // after handling side effects, call autocommand |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 3269 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3270 | options[opt_idx].flags |= P_WAS_SET; |
| 3271 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 3272 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3273 | apply_optionset_autocmd(opt_idx, opt_flags, |
| 3274 | (long)(old_value ? TRUE : FALSE), |
| 3275 | (long)(old_global_value ? TRUE : FALSE), |
| 3276 | (long)(value ? TRUE : FALSE), NULL); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 3277 | #endif |
| 3278 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3279 | comp_col(); // in case 'ruler' or 'showcmd' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3280 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 3281 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3282 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 3283 | |
| 3284 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 3285 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3286 | |
| 3287 | return NULL; |
| 3288 | } |
| 3289 | |
| 3290 | /* |
| 3291 | * Set the value of a number option, and take care of side effects. |
| 3292 | * Returns NULL for success, or an error message for an error. |
| 3293 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 3294 | static char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3295 | set_num_option( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3296 | int opt_idx, // index in options[] table |
| 3297 | char_u *varp, // pointer to the option variable |
| 3298 | long value, // new value |
| 3299 | char *errbuf, // buffer for error messages |
| 3300 | size_t errbuflen, // length of "errbuf" |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 3301 | int opt_flags) // OPT_LOCAL, OPT_GLOBAL, |
| 3302 | // OPT_MODELINE, etc. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3303 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 3304 | char *errmsg = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3305 | long old_value = *(long *)varp; |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3306 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3307 | long old_global_value = 0; // only used when setting a local and |
| 3308 | // global option |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3309 | #endif |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3310 | long old_Rows = Rows; // remember old Rows |
| 3311 | long old_Columns = Columns; // remember old Columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3312 | long *pp = (long *)varp; |
| 3313 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3314 | // Disallow changing some options from secure mode. |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 3315 | if ((secure |
| 3316 | #ifdef HAVE_SANDBOX |
| 3317 | || sandbox != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3318 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 3319 | ) && (options[opt_idx].flags & P_SECURE)) |
| 3320 | return e_secure; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3321 | |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3322 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3323 | // Save the global value before changing anything. This is needed as for |
Bram Moolenaar | 4b96df5 | 2020-01-26 22:00:26 +0100 | [diff] [blame] | 3324 | // a global-only option setting the "local value" in fact sets the global |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3325 | // value (since there is only one value). |
| 3326 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3327 | old_global_value = *(long *)get_varp_scope(&(options[opt_idx]), |
| 3328 | OPT_GLOBAL); |
| 3329 | #endif |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3330 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3331 | *pp = value; |
| 3332 | #ifdef FEAT_EVAL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3333 | // Remember where the option was set. |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3334 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3335 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 3336 | #ifdef FEAT_GUI |
| 3337 | need_mouse_correct = TRUE; |
| 3338 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3339 | |
Bram Moolenaar | 14f2474 | 2012-08-08 18:01:05 +0200 | [diff] [blame] | 3340 | if (curbuf->b_p_sw < 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3341 | { |
| 3342 | errmsg = e_positive; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 3343 | #ifdef FEAT_VARTABS |
| 3344 | // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. |
| 3345 | curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0 |
| 3346 | ? tabstop_first(curbuf->b_p_vts_array) |
| 3347 | : curbuf->b_p_ts; |
| 3348 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3349 | curbuf->b_p_sw = curbuf->b_p_ts; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 3350 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | /* |
| 3354 | * Number options that need some action when changed |
| 3355 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3356 | if (pp == &p_wh || pp == &p_hh) |
| 3357 | { |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 3358 | // 'winheight' and 'helpheight' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3359 | if (p_wh < 1) |
| 3360 | { |
| 3361 | errmsg = e_positive; |
| 3362 | p_wh = 1; |
| 3363 | } |
| 3364 | if (p_wmh > p_wh) |
| 3365 | { |
| 3366 | errmsg = e_winheight; |
| 3367 | p_wh = p_wmh; |
| 3368 | } |
| 3369 | if (p_hh < 0) |
| 3370 | { |
| 3371 | errmsg = e_positive; |
| 3372 | p_hh = 0; |
| 3373 | } |
| 3374 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3375 | // Change window height NOW |
Bram Moolenaar | 459ca56 | 2016-11-10 18:16:33 +0100 | [diff] [blame] | 3376 | if (!ONE_WINDOW) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3377 | { |
| 3378 | if (pp == &p_wh && curwin->w_height < p_wh) |
| 3379 | win_setheight((int)p_wh); |
| 3380 | if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) |
| 3381 | win_setheight((int)p_hh); |
| 3382 | } |
| 3383 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3384 | else if (pp == &p_wmh) |
| 3385 | { |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 3386 | // 'winminheight' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3387 | if (p_wmh < 0) |
| 3388 | { |
| 3389 | errmsg = e_positive; |
| 3390 | p_wmh = 0; |
| 3391 | } |
| 3392 | if (p_wmh > p_wh) |
| 3393 | { |
| 3394 | errmsg = e_winheight; |
| 3395 | p_wmh = p_wh; |
| 3396 | } |
| 3397 | win_setminheight(); |
| 3398 | } |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3399 | else if (pp == &p_wiw) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3400 | { |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 3401 | // 'winwidth' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3402 | if (p_wiw < 1) |
| 3403 | { |
| 3404 | errmsg = e_positive; |
| 3405 | p_wiw = 1; |
| 3406 | } |
| 3407 | if (p_wmw > p_wiw) |
| 3408 | { |
| 3409 | errmsg = e_winwidth; |
| 3410 | p_wiw = p_wmw; |
| 3411 | } |
| 3412 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3413 | // Change window width NOW |
Bram Moolenaar | 459ca56 | 2016-11-10 18:16:33 +0100 | [diff] [blame] | 3414 | if (!ONE_WINDOW && curwin->w_width < p_wiw) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3415 | win_setwidth((int)p_wiw); |
| 3416 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3417 | else if (pp == &p_wmw) |
| 3418 | { |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 3419 | // 'winminwidth' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3420 | if (p_wmw < 0) |
| 3421 | { |
| 3422 | errmsg = e_positive; |
| 3423 | p_wmw = 0; |
| 3424 | } |
| 3425 | if (p_wmw > p_wiw) |
| 3426 | { |
| 3427 | errmsg = e_winwidth; |
| 3428 | p_wmw = p_wiw; |
| 3429 | } |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 3430 | win_setminwidth(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3431 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3432 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3433 | // (re)set last window status line |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3434 | else if (pp == &p_ls) |
| 3435 | { |
| 3436 | last_status(FALSE); |
| 3437 | } |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 3438 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3439 | // (re)set tab page line |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 3440 | else if (pp == &p_stal) |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 3441 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3442 | shell_new_rows(); // recompute window positions and heights |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 3443 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3444 | |
| 3445 | #ifdef FEAT_GUI |
| 3446 | else if (pp == &p_linespace) |
| 3447 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3448 | // Recompute gui.char_height and resize the Vim window to keep the |
| 3449 | // same number of lines. |
Bram Moolenaar | 0274363 | 2005-07-25 20:42:36 +0000 | [diff] [blame] | 3450 | if (gui.in_use && gui_mch_adjust_charheight() == OK) |
Bram Moolenaar | 3964b7e | 2006-03-27 20:59:33 +0000 | [diff] [blame] | 3451 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3452 | } |
| 3453 | #endif |
| 3454 | |
| 3455 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3456 | // 'foldlevel' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3457 | else if (pp == &curwin->w_p_fdl) |
| 3458 | { |
| 3459 | if (curwin->w_p_fdl < 0) |
| 3460 | curwin->w_p_fdl = 0; |
| 3461 | newFoldLevel(); |
| 3462 | } |
| 3463 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3464 | // 'foldminlines' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3465 | else if (pp == &curwin->w_p_fml) |
| 3466 | { |
| 3467 | foldUpdateAll(curwin); |
| 3468 | } |
| 3469 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3470 | // 'foldnestmax' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3471 | else if (pp == &curwin->w_p_fdn) |
| 3472 | { |
| 3473 | if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) |
| 3474 | foldUpdateAll(curwin); |
| 3475 | } |
| 3476 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3477 | // 'foldcolumn' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3478 | else if (pp == &curwin->w_p_fdc) |
| 3479 | { |
| 3480 | if (curwin->w_p_fdc < 0) |
| 3481 | { |
| 3482 | errmsg = e_positive; |
| 3483 | curwin->w_p_fdc = 0; |
| 3484 | } |
| 3485 | else if (curwin->w_p_fdc > 12) |
| 3486 | { |
| 3487 | errmsg = e_invarg; |
| 3488 | curwin->w_p_fdc = 12; |
| 3489 | } |
| 3490 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3491 | #endif // FEAT_FOLDING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3492 | |
Bram Moolenaar | 6bcbcc5 | 2013-11-05 07:13:41 +0100 | [diff] [blame] | 3493 | #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3494 | // 'shiftwidth' or 'tabstop' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3495 | else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) |
| 3496 | { |
Bram Moolenaar | 6bcbcc5 | 2013-11-05 07:13:41 +0100 | [diff] [blame] | 3497 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3498 | if (foldmethodIsIndent(curwin)) |
| 3499 | foldUpdateAll(curwin); |
Bram Moolenaar | 6bcbcc5 | 2013-11-05 07:13:41 +0100 | [diff] [blame] | 3500 | # endif |
| 3501 | # ifdef FEAT_CINDENT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3502 | // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: |
| 3503 | // parse 'cinoptions'. |
Bram Moolenaar | 6bcbcc5 | 2013-11-05 07:13:41 +0100 | [diff] [blame] | 3504 | if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) |
| 3505 | parse_cino(curbuf); |
| 3506 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3507 | } |
Bram Moolenaar | 6bcbcc5 | 2013-11-05 07:13:41 +0100 | [diff] [blame] | 3508 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3509 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3510 | // 'maxcombine' |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3511 | else if (pp == &p_mco) |
| 3512 | { |
| 3513 | if (p_mco > MAX_MCO) |
| 3514 | p_mco = MAX_MCO; |
| 3515 | else if (p_mco < 0) |
| 3516 | p_mco = 0; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3517 | screenclear(); // will re-allocate the screen |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3518 | } |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3519 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3520 | else if (pp == &curbuf->b_p_iminsert) |
| 3521 | { |
| 3522 | if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) |
| 3523 | { |
| 3524 | errmsg = e_invarg; |
| 3525 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3526 | } |
| 3527 | p_iminsert = curbuf->b_p_iminsert; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3528 | if (termcap_active) // don't do this in the alternate screen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3529 | showmode(); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3530 | #if defined(FEAT_KEYMAP) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3531 | // Show/unshow value of 'keymap' in status lines. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3532 | status_redraw_curbuf(); |
| 3533 | #endif |
| 3534 | } |
| 3535 | |
Bram Moolenaar | 5c6dbcb | 2017-08-30 22:00:20 +0200 | [diff] [blame] | 3536 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3537 | // 'imstyle' |
Bram Moolenaar | 5c6dbcb | 2017-08-30 22:00:20 +0200 | [diff] [blame] | 3538 | else if (pp == &p_imst) |
| 3539 | { |
| 3540 | if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) |
| 3541 | errmsg = e_invarg; |
| 3542 | } |
| 3543 | #endif |
| 3544 | |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 3545 | else if (pp == &p_window) |
| 3546 | { |
| 3547 | if (p_window < 1) |
| 3548 | p_window = 1; |
| 3549 | else if (p_window >= Rows) |
| 3550 | p_window = Rows - 1; |
| 3551 | } |
| 3552 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3553 | else if (pp == &curbuf->b_p_imsearch) |
| 3554 | { |
| 3555 | if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) |
| 3556 | { |
| 3557 | errmsg = e_invarg; |
| 3558 | curbuf->b_p_imsearch = B_IMODE_NONE; |
| 3559 | } |
| 3560 | p_imsearch = curbuf->b_p_imsearch; |
| 3561 | } |
| 3562 | |
| 3563 | #ifdef FEAT_TITLE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3564 | // if 'titlelen' has changed, redraw the title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3565 | else if (pp == &p_titlelen) |
| 3566 | { |
| 3567 | if (p_titlelen < 0) |
| 3568 | { |
| 3569 | errmsg = e_positive; |
| 3570 | p_titlelen = 85; |
| 3571 | } |
| 3572 | if (starting != NO_SCREEN && old_value != p_titlelen) |
| 3573 | need_maketitle = TRUE; |
| 3574 | } |
| 3575 | #endif |
| 3576 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3577 | // if p_ch changed value, change the command line height |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3578 | else if (pp == &p_ch) |
| 3579 | { |
| 3580 | if (p_ch < 1) |
| 3581 | { |
| 3582 | errmsg = e_positive; |
| 3583 | p_ch = 1; |
| 3584 | } |
Bram Moolenaar | 719939c | 2007-09-25 12:51:28 +0000 | [diff] [blame] | 3585 | if (p_ch > Rows - min_rows() + 1) |
| 3586 | p_ch = Rows - min_rows() + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3587 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3588 | // Only compute the new window layout when startup has been |
| 3589 | // completed. Otherwise the frame sizes may be wrong. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3590 | if (p_ch != old_value && full_screen |
| 3591 | #ifdef FEAT_GUI |
| 3592 | && !gui.starting |
| 3593 | #endif |
| 3594 | ) |
Bram Moolenaar | c6fe919 | 2006-04-09 21:54:49 +0000 | [diff] [blame] | 3595 | command_height(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3596 | } |
| 3597 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3598 | // when 'updatecount' changes from zero to non-zero, open swap files |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3599 | else if (pp == &p_uc) |
| 3600 | { |
| 3601 | if (p_uc < 0) |
| 3602 | { |
| 3603 | errmsg = e_positive; |
| 3604 | p_uc = 100; |
| 3605 | } |
| 3606 | if (p_uc && !old_value) |
| 3607 | ml_open_files(); |
| 3608 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3609 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3610 | else if (pp == &curwin->w_p_cole) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3611 | { |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3612 | if (curwin->w_p_cole < 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3613 | { |
| 3614 | errmsg = e_positive; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3615 | curwin->w_p_cole = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3616 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3617 | else if (curwin->w_p_cole > 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3618 | { |
| 3619 | errmsg = e_invarg; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3620 | curwin->w_p_cole = 3; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | #endif |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 3624 | #ifdef MZSCHEME_GUI_THREADS |
Bram Moolenaar | 325b7a2 | 2004-07-05 15:58:32 +0000 | [diff] [blame] | 3625 | else if (pp == &p_mzq) |
| 3626 | mzvim_reset_timer(); |
| 3627 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3628 | |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 3629 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3630 | // 'pyxversion' |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 3631 | else if (pp == &p_pyx) |
| 3632 | { |
| 3633 | if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) |
| 3634 | errmsg = e_invarg; |
| 3635 | } |
| 3636 | #endif |
| 3637 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3638 | // sync undo before 'undolevels' changes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3639 | else if (pp == &p_ul) |
| 3640 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3641 | // use the old value, otherwise u_sync() may not work properly |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3642 | p_ul = old_value; |
Bram Moolenaar | 779b74b | 2006-04-10 14:55:34 +0000 | [diff] [blame] | 3643 | u_sync(TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3644 | p_ul = value; |
| 3645 | } |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 3646 | else if (pp == &curbuf->b_p_ul) |
| 3647 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3648 | // use the old value, otherwise u_sync() may not work properly |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 3649 | curbuf->b_p_ul = old_value; |
| 3650 | u_sync(TRUE); |
| 3651 | curbuf->b_p_ul = value; |
| 3652 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3653 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3654 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3655 | // 'numberwidth' must be positive |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3656 | else if (pp == &curwin->w_p_nuw) |
| 3657 | { |
| 3658 | if (curwin->w_p_nuw < 1) |
| 3659 | { |
| 3660 | errmsg = e_positive; |
| 3661 | curwin->w_p_nuw = 1; |
| 3662 | } |
Bram Moolenaar | f8a0712 | 2019-07-01 22:06:07 +0200 | [diff] [blame] | 3663 | if (curwin->w_p_nuw > 20) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3664 | { |
| 3665 | errmsg = e_invarg; |
Bram Moolenaar | f8a0712 | 2019-07-01 22:06:07 +0200 | [diff] [blame] | 3666 | curwin->w_p_nuw = 20; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3667 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3668 | curwin->w_nrwidth_line_count = 0; // trigger a redraw |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3669 | } |
| 3670 | #endif |
| 3671 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3672 | else if (pp == &curbuf->b_p_tw) |
| 3673 | { |
| 3674 | if (curbuf->b_p_tw < 0) |
| 3675 | { |
| 3676 | errmsg = e_positive; |
| 3677 | curbuf->b_p_tw = 0; |
| 3678 | } |
| 3679 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3680 | { |
| 3681 | win_T *wp; |
| 3682 | tabpage_T *tp; |
| 3683 | |
| 3684 | FOR_ALL_TAB_WINDOWS(tp, wp) |
| 3685 | check_colorcolumn(wp); |
| 3686 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3687 | #endif |
| 3688 | } |
| 3689 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3690 | /* |
| 3691 | * Check the bounds for numeric options here |
| 3692 | */ |
| 3693 | if (Rows < min_rows() && full_screen) |
| 3694 | { |
| 3695 | if (errbuf != NULL) |
| 3696 | { |
Bram Moolenaar | 555b280 | 2005-05-19 21:08:39 +0000 | [diff] [blame] | 3697 | vim_snprintf((char *)errbuf, errbuflen, |
| 3698 | _("E593: Need at least %d lines"), min_rows()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3699 | errmsg = errbuf; |
| 3700 | } |
| 3701 | Rows = min_rows(); |
| 3702 | } |
| 3703 | if (Columns < MIN_COLUMNS && full_screen) |
| 3704 | { |
| 3705 | if (errbuf != NULL) |
| 3706 | { |
Bram Moolenaar | 555b280 | 2005-05-19 21:08:39 +0000 | [diff] [blame] | 3707 | vim_snprintf((char *)errbuf, errbuflen, |
| 3708 | _("E594: Need at least %d columns"), MIN_COLUMNS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3709 | errmsg = errbuf; |
| 3710 | } |
| 3711 | Columns = MIN_COLUMNS; |
| 3712 | } |
Bram Moolenaar | e057d40 | 2013-06-30 17:51:51 +0200 | [diff] [blame] | 3713 | limit_screen_size(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3714 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3715 | /* |
| 3716 | * If the screen (shell) height has been changed, assume it is the |
| 3717 | * physical screenheight. |
| 3718 | */ |
| 3719 | if (old_Rows != Rows || old_Columns != Columns) |
| 3720 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3721 | // Changing the screen size is not allowed while updating the screen. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3722 | if (updating_screen) |
| 3723 | *pp = old_value; |
| 3724 | else if (full_screen |
| 3725 | #ifdef FEAT_GUI |
| 3726 | && !gui.starting |
| 3727 | #endif |
| 3728 | ) |
| 3729 | set_shellsize((int)Columns, (int)Rows, TRUE); |
| 3730 | else |
| 3731 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3732 | // Postpone the resizing; check the size and cmdline position for |
| 3733 | // messages. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3734 | check_shellsize(); |
| 3735 | if (cmdline_row > Rows - p_ch && Rows > p_ch) |
| 3736 | cmdline_row = Rows - p_ch; |
| 3737 | } |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 3738 | if (p_window >= Rows || !option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 3739 | p_window = Rows - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3742 | if (curbuf->b_p_ts <= 0) |
| 3743 | { |
| 3744 | errmsg = e_positive; |
| 3745 | curbuf->b_p_ts = 8; |
| 3746 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3747 | if (p_tm < 0) |
| 3748 | { |
| 3749 | errmsg = e_positive; |
| 3750 | p_tm = 0; |
| 3751 | } |
| 3752 | if ((curwin->w_p_scr <= 0 |
| 3753 | || (curwin->w_p_scr > curwin->w_height |
| 3754 | && curwin->w_height > 0)) |
| 3755 | && full_screen) |
| 3756 | { |
| 3757 | if (pp == &(curwin->w_p_scr)) |
| 3758 | { |
| 3759 | if (curwin->w_p_scr != 0) |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 3760 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3761 | win_comp_scroll(curwin); |
| 3762 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3763 | // If 'scroll' became invalid because of a side effect silently adjust |
| 3764 | // it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3765 | else if (curwin->w_p_scr <= 0) |
| 3766 | curwin->w_p_scr = 1; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3767 | else // curwin->w_p_scr > curwin->w_height |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3768 | curwin->w_p_scr = curwin->w_height; |
| 3769 | } |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 3770 | if (p_hi < 0) |
| 3771 | { |
| 3772 | errmsg = e_positive; |
| 3773 | p_hi = 0; |
| 3774 | } |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 3775 | else if (p_hi > 10000) |
| 3776 | { |
| 3777 | errmsg = e_invarg; |
| 3778 | p_hi = 10000; |
| 3779 | } |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 3780 | if (p_re < 0 || p_re > 2) |
| 3781 | { |
| 3782 | errmsg = e_invarg; |
| 3783 | p_re = 0; |
| 3784 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3785 | if (p_report < 0) |
| 3786 | { |
| 3787 | errmsg = e_positive; |
| 3788 | p_report = 1; |
| 3789 | } |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 3790 | if ((p_sj < -100 || p_sj >= Rows) && full_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3791 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3792 | if (Rows != old_Rows) // Rows changed, just adjust p_sj |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3793 | p_sj = Rows / 2; |
| 3794 | else |
| 3795 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 3796 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3797 | p_sj = 1; |
| 3798 | } |
| 3799 | } |
| 3800 | if (p_so < 0 && full_screen) |
| 3801 | { |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 3802 | errmsg = e_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3803 | p_so = 0; |
| 3804 | } |
| 3805 | if (p_siso < 0 && full_screen) |
| 3806 | { |
| 3807 | errmsg = e_positive; |
| 3808 | p_siso = 0; |
| 3809 | } |
| 3810 | #ifdef FEAT_CMDWIN |
| 3811 | if (p_cwh < 1) |
| 3812 | { |
| 3813 | errmsg = e_positive; |
| 3814 | p_cwh = 1; |
| 3815 | } |
| 3816 | #endif |
| 3817 | if (p_ut < 0) |
| 3818 | { |
| 3819 | errmsg = e_positive; |
| 3820 | p_ut = 2000; |
| 3821 | } |
| 3822 | if (p_ss < 0) |
| 3823 | { |
| 3824 | errmsg = e_positive; |
| 3825 | p_ss = 0; |
| 3826 | } |
| 3827 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3828 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3829 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3830 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; |
| 3831 | |
| 3832 | options[opt_idx].flags |= P_WAS_SET; |
| 3833 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 3834 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3835 | apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value, |
| 3836 | value, errmsg); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 3837 | #endif |
| 3838 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3839 | comp_col(); // in case 'columns' or 'ls' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3840 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 3841 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3842 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 3843 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 3844 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3845 | |
| 3846 | return errmsg; |
| 3847 | } |
| 3848 | |
| 3849 | /* |
| 3850 | * Called after an option changed: check if something needs to be redrawn. |
| 3851 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 3852 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3853 | check_redraw(long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3854 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3855 | // Careful: P_RCLR and P_RALL are a combination of other P_ flags |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 3856 | int doclear = (flags & P_RCLR) == P_RCLR; |
| 3857 | int all = ((flags & P_RALL) == P_RALL || doclear); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3858 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3859 | if ((flags & P_RSTAT) || all) // mark all status lines dirty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3860 | status_redraw_all(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3861 | |
| 3862 | if ((flags & P_RBUF) || (flags & P_RWIN) || all) |
| 3863 | changed_window_setting(); |
| 3864 | if (flags & P_RBUF) |
| 3865 | redraw_curbuf_later(NOT_VALID); |
Bram Moolenaar | a2477fd | 2016-12-03 15:13:20 +0100 | [diff] [blame] | 3866 | if (flags & P_RWINONLY) |
| 3867 | redraw_later(NOT_VALID); |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 3868 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3869 | redraw_all_later(CLEAR); |
| 3870 | else if (all) |
| 3871 | redraw_all_later(NOT_VALID); |
| 3872 | } |
| 3873 | |
| 3874 | /* |
| 3875 | * Find index for option 'arg'. |
| 3876 | * Return -1 if not found. |
| 3877 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 3878 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3879 | findoption(char_u *arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3880 | { |
| 3881 | int opt_idx; |
| 3882 | char *s, *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3883 | static short quick_tab[27] = {0, 0}; // quick access table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3884 | int is_term_opt; |
| 3885 | |
| 3886 | /* |
| 3887 | * For first call: Initialize the quick-access table. |
| 3888 | * It contains the index for the first option that starts with a certain |
| 3889 | * letter. There are 26 letters, plus the first "t_" option. |
| 3890 | */ |
| 3891 | if (quick_tab[1] == 0) |
| 3892 | { |
| 3893 | p = options[0].fullname; |
| 3894 | for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 3895 | { |
| 3896 | if (s[0] != p[0]) |
| 3897 | { |
| 3898 | if (s[0] == 't' && s[1] == '_') |
| 3899 | quick_tab[26] = opt_idx; |
| 3900 | else |
| 3901 | quick_tab[CharOrdLow(s[0])] = opt_idx; |
| 3902 | } |
| 3903 | p = s; |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | /* |
| 3908 | * Check for name starting with an illegal character. |
| 3909 | */ |
| 3910 | #ifdef EBCDIC |
| 3911 | if (!islower(arg[0])) |
| 3912 | #else |
| 3913 | if (arg[0] < 'a' || arg[0] > 'z') |
| 3914 | #endif |
| 3915 | return -1; |
| 3916 | |
| 3917 | is_term_opt = (arg[0] == 't' && arg[1] == '_'); |
| 3918 | if (is_term_opt) |
| 3919 | opt_idx = quick_tab[26]; |
| 3920 | else |
| 3921 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 3922 | for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 3923 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3924 | if (STRCMP(arg, s) == 0) // match full name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3925 | break; |
| 3926 | } |
| 3927 | if (s == NULL && !is_term_opt) |
| 3928 | { |
| 3929 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 3930 | for ( ; options[opt_idx].fullname != NULL; opt_idx++) |
| 3931 | { |
| 3932 | s = options[opt_idx].shortname; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3933 | if (s != NULL && STRCMP(arg, s) == 0) // match short name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3934 | break; |
| 3935 | s = NULL; |
| 3936 | } |
| 3937 | } |
| 3938 | if (s == NULL) |
| 3939 | opt_idx = -1; |
| 3940 | return opt_idx; |
| 3941 | } |
| 3942 | |
Bram Moolenaar | 325b7a2 | 2004-07-05 15:58:32 +0000 | [diff] [blame] | 3943 | #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3944 | /* |
| 3945 | * Get the value for an option. |
| 3946 | * |
| 3947 | * Returns: |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3948 | * Number option: gov_number, *numval gets value. |
Bram Moolenaar | a725149 | 2021-01-02 16:53:13 +0100 | [diff] [blame] | 3949 | * Toggle option: gov_bool, *numval gets value. |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3950 | * String option: gov_string, *stringval gets allocated string. |
| 3951 | * Hidden Number option: gov_hidden_number. |
| 3952 | * Hidden Toggle option: gov_hidden_bool. |
| 3953 | * Hidden String option: gov_hidden_string. |
| 3954 | * Unknown option: gov_unknown. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3955 | */ |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3956 | getoption_T |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3957 | get_option_value( |
| 3958 | char_u *name, |
| 3959 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3960 | char_u **stringval, // NULL when only checking existence |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3961 | int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3962 | { |
| 3963 | int opt_idx; |
| 3964 | char_u *varp; |
| 3965 | |
| 3966 | opt_idx = findoption(name); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3967 | if (opt_idx < 0) // option not in the table |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 3968 | { |
| 3969 | int key; |
| 3970 | |
| 3971 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3972 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 3973 | { |
| 3974 | char_u key_name[2]; |
| 3975 | char_u *p; |
| 3976 | |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3977 | // check for a terminal option |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 3978 | if (key < 0) |
| 3979 | { |
| 3980 | key_name[0] = KEY2TERMCAP0(key); |
| 3981 | key_name[1] = KEY2TERMCAP1(key); |
| 3982 | } |
| 3983 | else |
| 3984 | { |
| 3985 | key_name[0] = KS_KEY; |
| 3986 | key_name[1] = (key & 0xff); |
| 3987 | } |
| 3988 | p = find_termcode(key_name); |
| 3989 | if (p != NULL) |
| 3990 | { |
| 3991 | if (stringval != NULL) |
| 3992 | *stringval = vim_strsave(p); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3993 | return gov_string; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 3994 | } |
| 3995 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 3996 | return gov_unknown; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 3997 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3998 | |
| 3999 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 4000 | |
| 4001 | if (options[opt_idx].flags & P_STRING) |
| 4002 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4003 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4004 | return gov_hidden_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4005 | if (stringval != NULL) |
| 4006 | { |
| 4007 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4008 | // never return the value of the crypt key |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 4009 | if ((char_u **)varp == &curbuf->b_p_key |
| 4010 | && **(char_u **)(varp) != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4011 | *stringval = vim_strsave((char_u *)"*****"); |
| 4012 | else |
| 4013 | #endif |
| 4014 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 4015 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4016 | return gov_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4019 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4020 | return (options[opt_idx].flags & P_NUM) |
| 4021 | ? gov_hidden_number : gov_hidden_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4022 | if (options[opt_idx].flags & P_NUM) |
| 4023 | *numval = *(long *)varp; |
| 4024 | else |
| 4025 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4026 | // Special case: 'modified' is b_changed, but we also want to consider |
| 4027 | // it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4028 | if ((int *)varp == &curbuf->b_changed) |
| 4029 | *numval = curbufIsChanged(); |
| 4030 | else |
Bram Moolenaar | 2acfbed | 2016-07-01 23:14:02 +0200 | [diff] [blame] | 4031 | *numval = (long) *(int *)varp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4032 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4033 | return (options[opt_idx].flags & P_NUM) ? gov_number : gov_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4034 | } |
| 4035 | #endif |
| 4036 | |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4037 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4038 | /* |
| 4039 | * Returns the option attributes and its value. Unlike the above function it |
| 4040 | * will return either global value or local value of the option depending on |
| 4041 | * what was requested, but it will never return global value if it was |
| 4042 | * requested to return local one and vice versa. Neither it will return |
| 4043 | * buffer-local value if it was requested to return window-local one. |
| 4044 | * |
| 4045 | * Pretends that option is absent if it is not present in the requested scope |
| 4046 | * (i.e. has no global, window-local or buffer-local value depending on |
| 4047 | * opt_type). Uses |
| 4048 | * |
| 4049 | * Returned flags: |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 4050 | * 0 hidden or unknown option, also option that does not have requested |
| 4051 | * type (see SREQ_* in vim.h) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4052 | * see SOPT_* in vim.h for other flags |
| 4053 | * |
| 4054 | * Possible opt_type values: see SREQ_* in vim.h |
| 4055 | */ |
| 4056 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4057 | get_option_value_strict( |
| 4058 | char_u *name, |
| 4059 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4060 | char_u **stringval, // NULL when only obtaining attributes |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4061 | int opt_type, |
| 4062 | void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4063 | { |
| 4064 | int opt_idx; |
Bram Moolenaar | 6800186 | 2013-05-11 13:45:05 +0200 | [diff] [blame] | 4065 | char_u *varp = NULL; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4066 | struct vimoption *p; |
| 4067 | int r = 0; |
| 4068 | |
| 4069 | opt_idx = findoption(name); |
| 4070 | if (opt_idx < 0) |
| 4071 | return 0; |
| 4072 | |
| 4073 | p = &(options[opt_idx]); |
| 4074 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4075 | // Hidden option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4076 | if (p->var == NULL) |
| 4077 | return 0; |
| 4078 | |
| 4079 | if (p->flags & P_BOOL) |
| 4080 | r |= SOPT_BOOL; |
| 4081 | else if (p->flags & P_NUM) |
| 4082 | r |= SOPT_NUM; |
| 4083 | else if (p->flags & P_STRING) |
| 4084 | r |= SOPT_STRING; |
| 4085 | |
| 4086 | if (p->indir == PV_NONE) |
| 4087 | { |
| 4088 | if (opt_type == SREQ_GLOBAL) |
| 4089 | r |= SOPT_GLOBAL; |
| 4090 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4091 | return 0; // Did not request global-only option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4092 | } |
| 4093 | else |
| 4094 | { |
| 4095 | if (p->indir & PV_BOTH) |
| 4096 | r |= SOPT_GLOBAL; |
| 4097 | else if (opt_type == SREQ_GLOBAL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4098 | return 0; // Requested global option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4099 | |
| 4100 | if (p->indir & PV_WIN) |
| 4101 | { |
| 4102 | if (opt_type == SREQ_BUF) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4103 | return 0; // Did not request window-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4104 | else |
| 4105 | r |= SOPT_WIN; |
| 4106 | } |
| 4107 | else if (p->indir & PV_BUF) |
| 4108 | { |
| 4109 | if (opt_type == SREQ_WIN) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4110 | return 0; // Did not request buffer-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4111 | else |
| 4112 | r |= SOPT_BUF; |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | if (stringval == NULL) |
| 4117 | return r; |
| 4118 | |
| 4119 | if (opt_type == SREQ_GLOBAL) |
| 4120 | varp = p->var; |
| 4121 | else |
| 4122 | { |
| 4123 | if (opt_type == SREQ_BUF) |
| 4124 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4125 | // Special case: 'modified' is b_changed, but we also want to |
| 4126 | // consider it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4127 | if (p->indir == PV_MOD) |
| 4128 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 4129 | *numval = bufIsChanged((buf_T *)from); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4130 | varp = NULL; |
| 4131 | } |
| 4132 | #ifdef FEAT_CRYPT |
| 4133 | else if (p->indir == PV_KEY) |
| 4134 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4135 | // never return the value of the crypt key |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4136 | *stringval = NULL; |
| 4137 | varp = NULL; |
| 4138 | } |
| 4139 | #endif |
| 4140 | else |
| 4141 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 4142 | buf_T *save_curbuf = curbuf; |
| 4143 | |
| 4144 | // only getting a pointer, no need to use aucmd_prepbuf() |
| 4145 | curbuf = (buf_T *)from; |
| 4146 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4147 | varp = get_varp(p); |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 4148 | curbuf = save_curbuf; |
| 4149 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4150 | } |
| 4151 | } |
| 4152 | else if (opt_type == SREQ_WIN) |
| 4153 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 4154 | win_T *save_curwin = curwin; |
| 4155 | |
| 4156 | curwin = (win_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4157 | curbuf = curwin->w_buffer; |
| 4158 | varp = get_varp(p); |
| 4159 | curwin = save_curwin; |
| 4160 | curbuf = curwin->w_buffer; |
| 4161 | } |
| 4162 | if (varp == p->var) |
| 4163 | return (r | SOPT_UNSET); |
| 4164 | } |
| 4165 | |
| 4166 | if (varp != NULL) |
| 4167 | { |
| 4168 | if (p->flags & P_STRING) |
| 4169 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 4170 | else if (p->flags & P_NUM) |
| 4171 | *numval = *(long *) varp; |
| 4172 | else |
| 4173 | *numval = *(int *)varp; |
| 4174 | } |
| 4175 | |
| 4176 | return r; |
| 4177 | } |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4178 | |
| 4179 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 4180 | * Iterate over options. First argument is a pointer to a pointer to a |
| 4181 | * structure inside options[] array, second is option type like in the above |
| 4182 | * function. |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4183 | * |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 4184 | * If first argument points to NULL it is assumed that iteration just started |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4185 | * and caller needs the very first value. |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 4186 | * If first argument points to the end marker function returns NULL and sets |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4187 | * first argument to NULL. |
| 4188 | * |
| 4189 | * Returns full option name for current option on each call. |
| 4190 | */ |
| 4191 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4192 | option_iter_next(void **option, int opt_type) |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4193 | { |
| 4194 | struct vimoption *ret = NULL; |
| 4195 | do |
| 4196 | { |
| 4197 | if (*option == NULL) |
| 4198 | *option = (void *) options; |
| 4199 | else if (((struct vimoption *) (*option))->fullname == NULL) |
| 4200 | { |
| 4201 | *option = NULL; |
| 4202 | return NULL; |
| 4203 | } |
| 4204 | else |
| 4205 | *option = (void *) (((struct vimoption *) (*option)) + 1); |
| 4206 | |
| 4207 | ret = ((struct vimoption *) (*option)); |
| 4208 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4209 | // Hidden option |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4210 | if (ret->var == NULL) |
| 4211 | { |
| 4212 | ret = NULL; |
| 4213 | continue; |
| 4214 | } |
| 4215 | |
| 4216 | switch (opt_type) |
| 4217 | { |
| 4218 | case SREQ_GLOBAL: |
| 4219 | if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH)) |
| 4220 | ret = NULL; |
| 4221 | break; |
| 4222 | case SREQ_BUF: |
| 4223 | if (!(ret->indir & PV_BUF)) |
| 4224 | ret = NULL; |
| 4225 | break; |
| 4226 | case SREQ_WIN: |
| 4227 | if (!(ret->indir & PV_WIN)) |
| 4228 | ret = NULL; |
| 4229 | break; |
| 4230 | default: |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 4231 | internal_error("option_iter_next()"); |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4232 | return NULL; |
| 4233 | } |
| 4234 | } |
| 4235 | while (ret == NULL); |
| 4236 | |
| 4237 | return (char_u *)ret->fullname; |
| 4238 | } |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4239 | #endif |
| 4240 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4241 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4242 | * Return the flags for the option at 'opt_idx'. |
| 4243 | */ |
| 4244 | long_u |
| 4245 | get_option_flags(int opt_idx) |
| 4246 | { |
| 4247 | return options[opt_idx].flags; |
| 4248 | } |
| 4249 | |
| 4250 | /* |
| 4251 | * Set a flag for the option at 'opt_idx'. |
| 4252 | */ |
| 4253 | void |
| 4254 | set_option_flag(int opt_idx, long_u flag) |
| 4255 | { |
| 4256 | options[opt_idx].flags |= flag; |
| 4257 | } |
| 4258 | |
| 4259 | /* |
| 4260 | * Clear a flag for the option at 'opt_idx'. |
| 4261 | */ |
| 4262 | void |
| 4263 | clear_option_flag(int opt_idx, long_u flag) |
| 4264 | { |
| 4265 | options[opt_idx].flags &= ~flag; |
| 4266 | } |
| 4267 | |
| 4268 | /* |
| 4269 | * Returns TRUE if the option at 'opt_idx' is a global option |
| 4270 | */ |
| 4271 | int |
| 4272 | is_global_option(int opt_idx) |
| 4273 | { |
| 4274 | return options[opt_idx].indir == PV_NONE; |
| 4275 | } |
| 4276 | |
| 4277 | /* |
| 4278 | * Returns TRUE if the option at 'opt_idx' is a global option which also has a |
| 4279 | * local value. |
| 4280 | */ |
| 4281 | int |
| 4282 | is_global_local_option(int opt_idx) |
| 4283 | { |
| 4284 | return options[opt_idx].indir & PV_BOTH; |
| 4285 | } |
| 4286 | |
| 4287 | /* |
| 4288 | * Returns TRUE if the option at 'opt_idx' is a window-local option |
| 4289 | */ |
| 4290 | int |
| 4291 | is_window_local_option(int opt_idx) |
| 4292 | { |
| 4293 | return options[opt_idx].var == VAR_WIN; |
| 4294 | } |
| 4295 | |
| 4296 | /* |
| 4297 | * Returns TRUE if the option at 'opt_idx' is a hidden option |
| 4298 | */ |
| 4299 | int |
| 4300 | is_hidden_option(int opt_idx) |
| 4301 | { |
| 4302 | return options[opt_idx].var == NULL; |
| 4303 | } |
| 4304 | |
| 4305 | #if defined(FEAT_CRYPT) || defined(PROTO) |
| 4306 | /* |
| 4307 | * Returns TRUE if the option at 'opt_idx' is a crypt key option |
| 4308 | */ |
| 4309 | int |
| 4310 | is_crypt_key_option(int opt_idx) |
| 4311 | { |
| 4312 | return options[opt_idx].indir == PV_KEY; |
| 4313 | } |
| 4314 | #endif |
| 4315 | |
| 4316 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4317 | * Set the value of option "name". |
| 4318 | * Use "string" for string options, use "number" for other options. |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4319 | * |
| 4320 | * Returns NULL on success or error message on error. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4321 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 4322 | char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4323 | set_option_value( |
| 4324 | char_u *name, |
| 4325 | long number, |
| 4326 | char_u *string, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4327 | int opt_flags) // OPT_LOCAL or 0 (both) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4328 | { |
| 4329 | int opt_idx; |
| 4330 | char_u *varp; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4331 | long_u flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4332 | |
| 4333 | opt_idx = findoption(name); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 4334 | if (opt_idx < 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4335 | { |
| 4336 | int key; |
| 4337 | |
| 4338 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4339 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4340 | { |
| 4341 | char_u key_name[2]; |
| 4342 | |
| 4343 | if (key < 0) |
| 4344 | { |
| 4345 | key_name[0] = KEY2TERMCAP0(key); |
| 4346 | key_name[1] = KEY2TERMCAP1(key); |
| 4347 | } |
| 4348 | else |
| 4349 | { |
| 4350 | key_name[0] = KS_KEY; |
| 4351 | key_name[1] = (key & 0xff); |
| 4352 | } |
| 4353 | add_termcode(key_name, string, FALSE); |
| 4354 | if (full_screen) |
| 4355 | ttest(FALSE); |
| 4356 | redraw_all_later(CLEAR); |
| 4357 | return NULL; |
| 4358 | } |
| 4359 | |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 4360 | semsg(_("E355: Unknown option: %s"), name); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4361 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4362 | else |
| 4363 | { |
| 4364 | flags = options[opt_idx].flags; |
| 4365 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4366 | // Disallow changing some options in the sandbox |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4367 | if (sandbox > 0 && (flags & P_SECURE)) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 4368 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4369 | emsg(_(e_not_allowed_in_sandbox)); |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4370 | return NULL; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 4371 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4372 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 4373 | if (flags & P_STRING) |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4374 | return set_string_option(opt_idx, string, opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4375 | else |
| 4376 | { |
Bram Moolenaar | b316376 | 2008-07-08 15:15:08 +0000 | [diff] [blame] | 4377 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4378 | if (varp != NULL) // hidden option is not changed |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4379 | { |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4380 | if (number == 0 && string != NULL) |
| 4381 | { |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4382 | int idx; |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4383 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4384 | // Either we are given a string or we are setting option |
| 4385 | // to zero. |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4386 | for (idx = 0; string[idx] == '0'; ++idx) |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4387 | ; |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 4388 | if (string[idx] != NUL || idx == 0) |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4389 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4390 | // There's another character after zeros or the string |
| 4391 | // is empty. In both cases, we are trying to set a |
| 4392 | // num option using a string. |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 4393 | semsg(_("E521: Number required: &%s = '%s'"), |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4394 | name, string); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4395 | return NULL; // do nothing as we hit an error |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 4396 | |
| 4397 | } |
| 4398 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4399 | if (flags & P_NUM) |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4400 | return set_num_option(opt_idx, varp, number, |
Bram Moolenaar | 555b280 | 2005-05-19 21:08:39 +0000 | [diff] [blame] | 4401 | NULL, 0, opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4402 | else |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4403 | return set_bool_option(opt_idx, varp, (int)number, |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 4404 | opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4405 | } |
| 4406 | } |
| 4407 | } |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 4408 | return NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | /* |
| 4412 | * Get the terminal code for a terminal option. |
| 4413 | * Returns NULL when not found. |
| 4414 | */ |
| 4415 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4416 | get_term_code(char_u *tname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4417 | { |
| 4418 | int opt_idx; |
| 4419 | char_u *varp; |
| 4420 | |
| 4421 | if (tname[0] != 't' || tname[1] != '_' || |
| 4422 | tname[2] == NUL || tname[3] == NUL) |
| 4423 | return NULL; |
| 4424 | if ((opt_idx = findoption(tname)) >= 0) |
| 4425 | { |
| 4426 | varp = get_varp(&(options[opt_idx])); |
| 4427 | if (varp != NULL) |
| 4428 | varp = *(char_u **)(varp); |
| 4429 | return varp; |
| 4430 | } |
| 4431 | return find_termcode(tname + 2); |
| 4432 | } |
| 4433 | |
| 4434 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4435 | get_highlight_default(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4436 | { |
| 4437 | int i; |
| 4438 | |
| 4439 | i = findoption((char_u *)"hl"); |
| 4440 | if (i >= 0) |
| 4441 | return options[i].def_val[VI_DEFAULT]; |
| 4442 | return (char_u *)NULL; |
| 4443 | } |
| 4444 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4445 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4446 | get_encoding_default(void) |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4447 | { |
| 4448 | int i; |
| 4449 | |
| 4450 | i = findoption((char_u *)"enc"); |
| 4451 | if (i >= 0) |
| 4452 | return options[i].def_val[VI_DEFAULT]; |
| 4453 | return (char_u *)NULL; |
| 4454 | } |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4455 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4456 | /* |
| 4457 | * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number. |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4458 | * When "has_lt" is true there is a '<' before "*arg_arg". |
| 4459 | * Returns 0 when the key is not recognized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4460 | */ |
| 4461 | static int |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4462 | find_key_option(char_u *arg_arg, int has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4463 | { |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4464 | int key = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4465 | int modifiers; |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4466 | char_u *arg = arg_arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4467 | |
| 4468 | /* |
| 4469 | * Don't use get_special_key_code() for t_xx, we don't want it to call |
| 4470 | * add_termcap_entry(). |
| 4471 | */ |
| 4472 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 4473 | key = TERMCAP2KEY(arg[2], arg[3]); |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 4474 | else if (has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4475 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4476 | --arg; // put arg at the '<' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4477 | modifiers = 0; |
Bram Moolenaar | ebe9d34 | 2020-05-30 21:52:54 +0200 | [diff] [blame] | 4478 | key = find_special_key(&arg, &modifiers, |
| 4479 | FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4480 | if (modifiers) // can't handle modifiers here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4481 | key = 0; |
| 4482 | } |
| 4483 | return key; |
| 4484 | } |
| 4485 | |
| 4486 | /* |
| 4487 | * if 'all' == 0: show changed options |
| 4488 | * if 'all' == 1: show all normal options |
| 4489 | * if 'all' == 2: show all terminal options |
| 4490 | */ |
| 4491 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4492 | showoptions( |
| 4493 | int all, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4494 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4495 | { |
| 4496 | struct vimoption *p; |
| 4497 | int col; |
| 4498 | int isterm; |
| 4499 | char_u *varp; |
| 4500 | struct vimoption **items; |
| 4501 | int item_count; |
| 4502 | int run; |
| 4503 | int row, rows; |
| 4504 | int cols; |
| 4505 | int i; |
| 4506 | int len; |
| 4507 | |
| 4508 | #define INC 20 |
| 4509 | #define GAP 3 |
| 4510 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4511 | items = ALLOC_MULT(struct vimoption *, OPTION_COUNT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4512 | if (items == NULL) |
| 4513 | return; |
| 4514 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4515 | // Highlight title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4516 | if (all == 2) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4517 | msg_puts_title(_("\n--- Terminal codes ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4518 | else if (opt_flags & OPT_GLOBAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4519 | msg_puts_title(_("\n--- Global option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4520 | else if (opt_flags & OPT_LOCAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4521 | msg_puts_title(_("\n--- Local option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4522 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4523 | msg_puts_title(_("\n--- Options ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4524 | |
| 4525 | /* |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4526 | * Do the loop two times: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4527 | * 1. display the short items |
| 4528 | * 2. display the long items (only strings and numbers) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4529 | * When "opt_flags" has OPT_ONECOLUMN do everything in run 2. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4530 | */ |
| 4531 | for (run = 1; run <= 2 && !got_int; ++run) |
| 4532 | { |
| 4533 | /* |
| 4534 | * collect the items in items[] |
| 4535 | */ |
| 4536 | item_count = 0; |
| 4537 | for (p = &options[0]; p->fullname != NULL; p++) |
| 4538 | { |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 4539 | // apply :filter /pat/ |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4540 | if (message_filtered((char_u *)p->fullname)) |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 4541 | continue; |
| 4542 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4543 | varp = NULL; |
| 4544 | isterm = istermoption(p); |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4545 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4546 | { |
| 4547 | if (p->indir != PV_NONE && !isterm) |
| 4548 | varp = get_varp_scope(p, opt_flags); |
| 4549 | } |
| 4550 | else |
| 4551 | varp = get_varp(p); |
| 4552 | if (varp != NULL |
| 4553 | && ((all == 2 && isterm) |
| 4554 | || (all == 1 && !isterm) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 4555 | || (all == 0 && !optval_default(p, varp, p_cp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4556 | { |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 4557 | if (opt_flags & OPT_ONECOLUMN) |
| 4558 | len = Columns; |
| 4559 | else if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4560 | len = 1; // a toggle option fits always |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4561 | else |
| 4562 | { |
| 4563 | option_value2string(p, opt_flags); |
| 4564 | len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; |
| 4565 | } |
| 4566 | if ((len <= INC - GAP && run == 1) || |
| 4567 | (len > INC - GAP && run == 2)) |
| 4568 | items[item_count++] = p; |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | /* |
| 4573 | * display the items |
| 4574 | */ |
| 4575 | if (run == 1) |
| 4576 | { |
| 4577 | cols = (Columns + GAP - 3) / INC; |
| 4578 | if (cols == 0) |
| 4579 | cols = 1; |
| 4580 | rows = (item_count + cols - 1) / cols; |
| 4581 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4582 | else // run == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4583 | rows = item_count; |
| 4584 | for (row = 0; row < rows && !got_int; ++row) |
| 4585 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4586 | msg_putchar('\n'); // go to next line |
| 4587 | if (got_int) // 'q' typed in more |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4588 | break; |
| 4589 | col = 0; |
| 4590 | for (i = row; i < item_count; i += rows) |
| 4591 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4592 | msg_col = col; // make columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4593 | showoneopt(items[i], opt_flags); |
| 4594 | col += INC; |
| 4595 | } |
| 4596 | out_flush(); |
| 4597 | ui_breakcheck(); |
| 4598 | } |
| 4599 | } |
| 4600 | vim_free(items); |
| 4601 | } |
| 4602 | |
| 4603 | /* |
| 4604 | * Return TRUE if option "p" has its default value. |
| 4605 | */ |
| 4606 | static int |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 4607 | optval_default(struct vimoption *p, char_u *varp, int compatible) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4608 | { |
| 4609 | int dvi; |
| 4610 | |
| 4611 | if (varp == NULL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4612 | return TRUE; // hidden option is always at default |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 4613 | dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4614 | if (p->flags & P_NUM) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4615 | return (*(long *)varp == (long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4616 | if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4617 | // the cast to long is required for Manx C, long_i is |
| 4618 | // needed for MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4619 | return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4620 | // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4621 | return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); |
| 4622 | } |
| 4623 | |
| 4624 | /* |
| 4625 | * showoneopt: show the value of one option |
| 4626 | * must not be called with a hidden option! |
| 4627 | */ |
| 4628 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4629 | showoneopt( |
| 4630 | struct vimoption *p, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4631 | int opt_flags) // OPT_LOCAL or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4632 | { |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 4633 | char_u *varp; |
| 4634 | int save_silent = silent_mode; |
| 4635 | |
| 4636 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4637 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4638 | |
| 4639 | varp = get_varp_scope(p, opt_flags); |
| 4640 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4641 | // for 'modified' we also need to check if 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4642 | if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed |
| 4643 | ? !curbufIsChanged() : !*(int *)varp)) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4644 | msg_puts("no"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4645 | else if ((p->flags & P_BOOL) && *(int *)varp < 0) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4646 | msg_puts("--"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4647 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4648 | msg_puts(" "); |
| 4649 | msg_puts(p->fullname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4650 | if (!(p->flags & P_BOOL)) |
| 4651 | { |
| 4652 | msg_putchar('='); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4653 | // put value string in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4654 | option_value2string(p, opt_flags); |
| 4655 | msg_outtrans(NameBuff); |
| 4656 | } |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 4657 | |
| 4658 | silent_mode = save_silent; |
| 4659 | info_message = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | /* |
| 4663 | * Write modified options as ":set" commands to a file. |
| 4664 | * |
| 4665 | * There are three values for "opt_flags": |
| 4666 | * OPT_GLOBAL: Write global option values and fresh values of |
| 4667 | * buffer-local options (used for start of a session |
| 4668 | * file). |
| 4669 | * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for |
| 4670 | * curwin (used for a vimrc file). |
| 4671 | * OPT_LOCAL: Write buffer-local option values for curbuf, fresh |
| 4672 | * and local values for window-local options of |
| 4673 | * curwin. Local values are also written when at the |
| 4674 | * default value, because a modeline or autocommand |
| 4675 | * may have set them when doing ":edit file" and the |
| 4676 | * user has set them back at the default or fresh |
| 4677 | * value. |
| 4678 | * When "local_only" is TRUE, don't write fresh |
| 4679 | * values, only local values (for ":mkview"). |
| 4680 | * (fresh value = value used for a new buffer or window for a local option). |
| 4681 | * |
| 4682 | * Return FAIL on error, OK otherwise. |
| 4683 | */ |
| 4684 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4685 | makeset(FILE *fd, int opt_flags, int local_only) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4686 | { |
| 4687 | struct vimoption *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4688 | char_u *varp; // currently used value |
| 4689 | char_u *varp_fresh; // local value |
| 4690 | char_u *varp_local = NULL; // fresh value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4691 | char *cmd; |
| 4692 | int round; |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 4693 | int pri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4694 | |
| 4695 | /* |
| 4696 | * The options that don't have a default (terminal name, columns, lines) |
| 4697 | * are never written. Terminal options are also not written. |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 4698 | * Do the loop over "options[]" twice: once for options with the |
| 4699 | * P_PRI_MKRC flag and once without. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4700 | */ |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 4701 | for (pri = 1; pri >= 0; --pri) |
| 4702 | { |
| 4703 | for (p = &options[0]; !istermoption(p); p++) |
| 4704 | if (!(p->flags & P_NO_MKRC) |
| 4705 | && !istermoption(p) |
| 4706 | && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4707 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4708 | // skip global option when only doing locals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4709 | if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) |
| 4710 | continue; |
| 4711 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4712 | // Do not store options like 'bufhidden' and 'syntax' in a vimrc |
| 4713 | // file, they are always buffer-specific. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4714 | if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) |
| 4715 | continue; |
| 4716 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4717 | // Global values are only written when not at the default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4718 | varp = get_varp_scope(p, opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 4719 | if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4720 | continue; |
| 4721 | |
Bram Moolenaar | d23b714 | 2021-04-17 21:04:34 +0200 | [diff] [blame] | 4722 | if ((opt_flags & OPT_SKIPRTP) && (p->var == (char_u *)&p_rtp |
| 4723 | || p->var == (char_u *)&p_pp)) |
Bram Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 4724 | continue; |
| 4725 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4726 | round = 2; |
| 4727 | if (p->indir != PV_NONE) |
| 4728 | { |
| 4729 | if (p->var == VAR_WIN) |
| 4730 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4731 | // skip window-local option when only doing globals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4732 | if (!(opt_flags & OPT_LOCAL)) |
| 4733 | continue; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4734 | // When fresh value of window-local option is not at the |
| 4735 | // default, need to write it too. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4736 | if (!(opt_flags & OPT_GLOBAL) && !local_only) |
| 4737 | { |
| 4738 | varp_fresh = get_varp_scope(p, OPT_GLOBAL); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 4739 | if (!optval_default(p, varp_fresh, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4740 | { |
| 4741 | round = 1; |
| 4742 | varp_local = varp; |
| 4743 | varp = varp_fresh; |
| 4744 | } |
| 4745 | } |
| 4746 | } |
| 4747 | } |
| 4748 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4749 | // Round 1: fresh value for window-local options. |
| 4750 | // Round 2: other values |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4751 | for ( ; round <= 2; varp = varp_local, ++round) |
| 4752 | { |
| 4753 | if (round == 1 || (opt_flags & OPT_GLOBAL)) |
| 4754 | cmd = "set"; |
| 4755 | else |
| 4756 | cmd = "setlocal"; |
| 4757 | |
| 4758 | if (p->flags & P_BOOL) |
| 4759 | { |
| 4760 | if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) |
| 4761 | return FAIL; |
| 4762 | } |
| 4763 | else if (p->flags & P_NUM) |
| 4764 | { |
| 4765 | if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) |
| 4766 | return FAIL; |
| 4767 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4768 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4769 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 4770 | int do_endif = FALSE; |
| 4771 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4772 | // Don't set 'syntax' and 'filetype' again if the value is |
| 4773 | // already right, avoids reloading the syntax file. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 4774 | if ( |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 4775 | #if defined(FEAT_SYN_HL) |
| 4776 | p->indir == PV_SYN || |
| 4777 | #endif |
| 4778 | p->indir == PV_FT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4779 | { |
| 4780 | if (fprintf(fd, "if &%s != '%s'", p->fullname, |
| 4781 | *(char_u **)(varp)) < 0 |
| 4782 | || put_eol(fd) < 0) |
| 4783 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 4784 | do_endif = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4785 | } |
| 4786 | if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4787 | p->flags) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4788 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 4789 | if (do_endif) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4790 | { |
| 4791 | if (put_line(fd, "endif") == FAIL) |
| 4792 | return FAIL; |
| 4793 | } |
| 4794 | } |
| 4795 | } |
| 4796 | } |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 4797 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4798 | return OK; |
| 4799 | } |
| 4800 | |
| 4801 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 4802 | /* |
| 4803 | * Generate set commands for the local fold options only. Used when |
| 4804 | * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". |
| 4805 | */ |
| 4806 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4807 | makefoldset(FILE *fd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4808 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4809 | if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4810 | # ifdef FEAT_EVAL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4811 | || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4812 | == FAIL |
| 4813 | # endif |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4814 | || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4815 | == FAIL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4816 | || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4817 | == FAIL |
| 4818 | || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL |
| 4819 | || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL |
| 4820 | || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL |
| 4821 | || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL |
| 4822 | ) |
| 4823 | return FAIL; |
| 4824 | |
| 4825 | return OK; |
| 4826 | } |
| 4827 | #endif |
| 4828 | |
| 4829 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4830 | put_setstring( |
| 4831 | FILE *fd, |
| 4832 | char *cmd, |
| 4833 | char *name, |
| 4834 | char_u **valuep, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4835 | long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4836 | { |
| 4837 | char_u *s; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4838 | char_u *buf = NULL; |
| 4839 | char_u *part = NULL; |
| 4840 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4841 | |
| 4842 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 4843 | return FAIL; |
| 4844 | if (*valuep != NULL) |
| 4845 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4846 | // Output 'pastetoggle' as key names. For other |
| 4847 | // options some characters have to be escaped with |
| 4848 | // CTRL-V or backslash |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4849 | if (valuep == &p_pt) |
| 4850 | { |
| 4851 | s = *valuep; |
| 4852 | while (*s != NUL) |
Bram Moolenaar | 7d96acd | 2008-06-09 15:07:54 +0000 | [diff] [blame] | 4853 | if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4854 | return FAIL; |
| 4855 | } |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4856 | // expand the option value, replace $HOME by ~ |
| 4857 | else if ((flags & P_EXPAND) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4858 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4859 | int size = (int)STRLEN(*valuep) + 1; |
| 4860 | |
| 4861 | // replace home directory in the whole option value into "buf" |
| 4862 | buf = alloc(size); |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 4863 | if (buf == NULL) |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4864 | goto fail; |
| 4865 | home_replace(NULL, *valuep, buf, size, FALSE); |
| 4866 | |
| 4867 | // If the option value is longer than MAXPATHL, we need to append |
Bram Moolenaar | 32aa102 | 2019-11-02 22:54:41 +0100 | [diff] [blame] | 4868 | // each comma separated part of the option separately, so that it |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4869 | // can be expanded when read back. |
| 4870 | if (size >= MAXPATHL && (flags & P_COMMA) != 0 |
| 4871 | && vim_strchr(*valuep, ',') != NULL) |
| 4872 | { |
| 4873 | part = alloc(size); |
| 4874 | if (part == NULL) |
| 4875 | goto fail; |
| 4876 | |
| 4877 | // write line break to clear the option, e.g. ':set rtp=' |
| 4878 | if (put_eol(fd) == FAIL) |
| 4879 | goto fail; |
| 4880 | |
| 4881 | p = buf; |
| 4882 | while (*p != NUL) |
| 4883 | { |
| 4884 | // for each comma separated option part, append value to |
| 4885 | // the option, :set rtp+=value |
| 4886 | if (fprintf(fd, "%s %s+=", cmd, name) < 0) |
| 4887 | goto fail; |
| 4888 | (void)copy_option_part(&p, part, size, ","); |
| 4889 | if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) |
| 4890 | goto fail; |
| 4891 | } |
| 4892 | vim_free(buf); |
| 4893 | vim_free(part); |
| 4894 | return OK; |
| 4895 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4896 | if (put_escstr(fd, buf, 2) == FAIL) |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 4897 | { |
| 4898 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4899 | return FAIL; |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 4900 | } |
| 4901 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4902 | } |
| 4903 | else if (put_escstr(fd, *valuep, 2) == FAIL) |
| 4904 | return FAIL; |
| 4905 | } |
| 4906 | if (put_eol(fd) < 0) |
| 4907 | return FAIL; |
| 4908 | return OK; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 4909 | fail: |
| 4910 | vim_free(buf); |
| 4911 | vim_free(part); |
| 4912 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4916 | put_setnum( |
| 4917 | FILE *fd, |
| 4918 | char *cmd, |
| 4919 | char *name, |
| 4920 | long *valuep) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4921 | { |
| 4922 | long wc; |
| 4923 | |
| 4924 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 4925 | return FAIL; |
| 4926 | if (wc_use_keyname((char_u *)valuep, &wc)) |
| 4927 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4928 | // print 'wildchar' and 'wildcharm' as a key name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4929 | if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) |
| 4930 | return FAIL; |
| 4931 | } |
| 4932 | else if (fprintf(fd, "%ld", *valuep) < 0) |
| 4933 | return FAIL; |
| 4934 | if (put_eol(fd) < 0) |
| 4935 | return FAIL; |
| 4936 | return OK; |
| 4937 | } |
| 4938 | |
| 4939 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4940 | put_setbool( |
| 4941 | FILE *fd, |
| 4942 | char *cmd, |
| 4943 | char *name, |
| 4944 | int value) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4945 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4946 | if (value < 0) // global/local option using global value |
Bram Moolenaar | 893de92 | 2007-10-02 18:40:57 +0000 | [diff] [blame] | 4947 | return OK; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4948 | if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 |
| 4949 | || put_eol(fd) < 0) |
| 4950 | return FAIL; |
| 4951 | return OK; |
| 4952 | } |
| 4953 | |
| 4954 | /* |
| 4955 | * Clear all the terminal options. |
| 4956 | * If the option has been allocated, free the memory. |
| 4957 | * Terminal options are never hidden or indirect. |
| 4958 | */ |
| 4959 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4960 | clear_termoptions(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4961 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4962 | /* |
| 4963 | * Reset a few things before clearing the old options. This may cause |
| 4964 | * outputting a few things that the terminal doesn't understand, but the |
| 4965 | * screen will be cleared later, so this is OK. |
| 4966 | */ |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 4967 | mch_setmouse(FALSE); // switch mouse off |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4968 | #ifdef FEAT_TITLE |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4969 | mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4970 | #endif |
| 4971 | #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4972 | // When starting the GUI close the display opened for the clipboard. |
| 4973 | // After restoring the title, because that will need the display. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4974 | if (gui.starting) |
| 4975 | clear_xterm_clip(); |
| 4976 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4977 | stoptermcap(); // stop termcap mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4978 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 4979 | free_termoptions(); |
| 4980 | } |
| 4981 | |
| 4982 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4983 | free_termoptions(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 4984 | { |
| 4985 | struct vimoption *p; |
| 4986 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 4987 | for (p = options; p->fullname != NULL; p++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4988 | if (istermoption(p)) |
| 4989 | { |
| 4990 | if (p->flags & P_ALLOCED) |
| 4991 | free_string_option(*(char_u **)(p->var)); |
| 4992 | if (p->flags & P_DEF_ALLOCED) |
| 4993 | free_string_option(p->def_val[VI_DEFAULT]); |
| 4994 | *(char_u **)(p->var) = empty_option; |
| 4995 | p->def_val[VI_DEFAULT] = empty_option; |
| 4996 | p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 4997 | #ifdef FEAT_EVAL |
| 4998 | // remember where the option was cleared |
| 4999 | set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx); |
| 5000 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5001 | } |
| 5002 | clear_termcodes(); |
| 5003 | } |
| 5004 | |
| 5005 | /* |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 5006 | * Free the string for one term option, if it was allocated. |
| 5007 | * Set the string to empty_option and clear allocated flag. |
| 5008 | * "var" points to the option value. |
| 5009 | */ |
| 5010 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5011 | free_one_termoption(char_u *var) |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 5012 | { |
| 5013 | struct vimoption *p; |
| 5014 | |
| 5015 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5016 | if (p->var == var) |
| 5017 | { |
| 5018 | if (p->flags & P_ALLOCED) |
| 5019 | free_string_option(*(char_u **)(p->var)); |
| 5020 | *(char_u **)(p->var) = empty_option; |
| 5021 | p->flags &= ~P_ALLOCED; |
| 5022 | break; |
| 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5027 | * Set the terminal option defaults to the current value. |
| 5028 | * Used after setting the terminal name. |
| 5029 | */ |
| 5030 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5031 | set_term_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5032 | { |
| 5033 | struct vimoption *p; |
| 5034 | |
| 5035 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5036 | { |
| 5037 | if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) |
| 5038 | { |
| 5039 | if (p->flags & P_DEF_ALLOCED) |
| 5040 | { |
| 5041 | free_string_option(p->def_val[VI_DEFAULT]); |
| 5042 | p->flags &= ~P_DEF_ALLOCED; |
| 5043 | } |
| 5044 | p->def_val[VI_DEFAULT] = *(char_u **)(p->var); |
| 5045 | if (p->flags & P_ALLOCED) |
| 5046 | { |
| 5047 | p->flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5048 | p->flags &= ~P_ALLOCED; // don't free the value now |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | } |
| 5052 | } |
| 5053 | |
| 5054 | /* |
| 5055 | * return TRUE if 'p' starts with 't_' |
| 5056 | */ |
| 5057 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5058 | istermoption(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5059 | { |
| 5060 | return (p->fullname[0] == 't' && p->fullname[1] == '_'); |
| 5061 | } |
| 5062 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5063 | /* |
| 5064 | * Returns TRUE if the option at 'opt_idx' starts with 't_' |
| 5065 | */ |
| 5066 | int |
| 5067 | istermoption_idx(int opt_idx) |
| 5068 | { |
| 5069 | return istermoption(&options[opt_idx]); |
| 5070 | } |
| 5071 | |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 5072 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5073 | /* |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5074 | * Unset local option value, similar to ":set opt<". |
| 5075 | */ |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5076 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5077 | unset_global_local_option(char_u *name, void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5078 | { |
| 5079 | struct vimoption *p; |
| 5080 | int opt_idx; |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5081 | buf_T *buf = (buf_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5082 | |
| 5083 | opt_idx = findoption(name); |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 5084 | if (opt_idx < 0) |
| 5085 | return; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5086 | p = &(options[opt_idx]); |
| 5087 | |
| 5088 | switch ((int)p->indir) |
| 5089 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5090 | // global option with local value: use local value if it's been set |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5091 | case PV_EP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5092 | clear_string_option(&buf->b_p_ep); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5093 | break; |
| 5094 | case PV_KP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5095 | clear_string_option(&buf->b_p_kp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5096 | break; |
| 5097 | case PV_PATH: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5098 | clear_string_option(&buf->b_p_path); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5099 | break; |
| 5100 | case PV_AR: |
| 5101 | buf->b_p_ar = -1; |
| 5102 | break; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5103 | case PV_BKC: |
| 5104 | clear_string_option(&buf->b_p_bkc); |
| 5105 | buf->b_bkc_flags = 0; |
| 5106 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5107 | case PV_TAGS: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5108 | clear_string_option(&buf->b_p_tags); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5109 | break; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 5110 | case PV_TC: |
| 5111 | clear_string_option(&buf->b_p_tc); |
| 5112 | buf->b_tc_flags = 0; |
| 5113 | break; |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 5114 | case PV_SISO: |
| 5115 | curwin->w_p_siso = -1; |
| 5116 | break; |
| 5117 | case PV_SO: |
| 5118 | curwin->w_p_so = -1; |
| 5119 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5120 | #ifdef FEAT_FIND_ID |
| 5121 | case PV_DEF: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5122 | clear_string_option(&buf->b_p_def); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5123 | break; |
| 5124 | case PV_INC: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5125 | clear_string_option(&buf->b_p_inc); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5126 | break; |
| 5127 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5128 | case PV_DICT: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5129 | clear_string_option(&buf->b_p_dict); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5130 | break; |
| 5131 | case PV_TSR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5132 | clear_string_option(&buf->b_p_tsr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5133 | break; |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 5134 | case PV_FP: |
| 5135 | clear_string_option(&buf->b_p_fp); |
| 5136 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5137 | #ifdef FEAT_QUICKFIX |
| 5138 | case PV_EFM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5139 | clear_string_option(&buf->b_p_efm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5140 | break; |
| 5141 | case PV_GP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5142 | clear_string_option(&buf->b_p_gp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5143 | break; |
| 5144 | case PV_MP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5145 | clear_string_option(&buf->b_p_mp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5146 | break; |
| 5147 | #endif |
| 5148 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 5149 | case PV_BEXPR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5150 | clear_string_option(&buf->b_p_bexpr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5151 | break; |
| 5152 | #endif |
| 5153 | #if defined(FEAT_CRYPT) |
| 5154 | case PV_CM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5155 | clear_string_option(&buf->b_p_cm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5156 | break; |
| 5157 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5158 | #ifdef FEAT_LINEBREAK |
| 5159 | case PV_SBR: |
| 5160 | clear_string_option(&((win_T *)from)->w_p_sbr); |
| 5161 | break; |
| 5162 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5163 | #ifdef FEAT_STL_OPT |
| 5164 | case PV_STL: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5165 | clear_string_option(&((win_T *)from)->w_p_stl); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5166 | break; |
| 5167 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 5168 | case PV_UL: |
| 5169 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
| 5170 | break; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 5171 | #ifdef FEAT_LISP |
| 5172 | case PV_LW: |
| 5173 | clear_string_option(&buf->b_p_lw); |
| 5174 | break; |
| 5175 | #endif |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 5176 | case PV_MENC: |
| 5177 | clear_string_option(&buf->b_p_menc); |
| 5178 | break; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5179 | case PV_LCS: |
| 5180 | clear_string_option(&((win_T *)from)->w_p_lcs); |
| 5181 | set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs); |
| 5182 | redraw_later(NOT_VALID); |
| 5183 | break; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 5184 | case PV_VE: |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5185 | clear_string_option(&((win_T *)from)->w_p_ve); |
| 5186 | ((win_T *)from)->w_ve_flags = 0; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 5187 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5188 | } |
| 5189 | } |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 5190 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5191 | |
| 5192 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5193 | * Get pointer to option variable, depending on local or global scope. |
| 5194 | */ |
| 5195 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5196 | get_varp_scope(struct vimoption *p, int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5197 | { |
| 5198 | if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) |
| 5199 | { |
| 5200 | if (p->var == VAR_WIN) |
| 5201 | return (char_u *)GLOBAL_WO(get_varp(p)); |
| 5202 | return p->var; |
| 5203 | } |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 5204 | if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5205 | { |
| 5206 | switch ((int)p->indir) |
| 5207 | { |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 5208 | case PV_FP: return (char_u *)&(curbuf->b_p_fp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5209 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5210 | case PV_EFM: return (char_u *)&(curbuf->b_p_efm); |
| 5211 | case PV_GP: return (char_u *)&(curbuf->b_p_gp); |
| 5212 | case PV_MP: return (char_u *)&(curbuf->b_p_mp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5213 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5214 | case PV_EP: return (char_u *)&(curbuf->b_p_ep); |
| 5215 | case PV_KP: return (char_u *)&(curbuf->b_p_kp); |
| 5216 | case PV_PATH: return (char_u *)&(curbuf->b_p_path); |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 5217 | case PV_AR: return (char_u *)&(curbuf->b_p_ar); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5218 | case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 5219 | case PV_TC: return (char_u *)&(curbuf->b_p_tc); |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 5220 | case PV_SISO: return (char_u *)&(curwin->w_p_siso); |
| 5221 | case PV_SO: return (char_u *)&(curwin->w_p_so); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5222 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5223 | case PV_DEF: return (char_u *)&(curbuf->b_p_def); |
| 5224 | case PV_INC: return (char_u *)&(curbuf->b_p_inc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5225 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5226 | case PV_DICT: return (char_u *)&(curbuf->b_p_dict); |
| 5227 | case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 5228 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 5229 | case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr); |
| 5230 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 5231 | #if defined(FEAT_CRYPT) |
| 5232 | case PV_CM: return (char_u *)&(curbuf->b_p_cm); |
| 5233 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5234 | #ifdef FEAT_LINEBREAK |
| 5235 | case PV_SBR: return (char_u *)&(curwin->w_p_sbr); |
| 5236 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5237 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5238 | case PV_STL: return (char_u *)&(curwin->w_p_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5239 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 5240 | case PV_UL: return (char_u *)&(curbuf->b_p_ul); |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 5241 | #ifdef FEAT_LISP |
| 5242 | case PV_LW: return (char_u *)&(curbuf->b_p_lw); |
| 5243 | #endif |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5244 | case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 5245 | case PV_MENC: return (char_u *)&(curbuf->b_p_menc); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 5246 | case PV_LCS: return (char_u *)&(curwin->w_p_lcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5247 | case PV_VE: return (char_u *)&(curwin->w_p_ve); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5248 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5249 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5250 | return NULL; // "cannot happen" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5251 | } |
| 5252 | return get_varp(p); |
| 5253 | } |
| 5254 | |
| 5255 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5256 | * Get pointer to option variable at 'opt_idx', depending on local or global |
| 5257 | * scope. |
| 5258 | */ |
| 5259 | char_u * |
| 5260 | get_option_varp_scope(int opt_idx, int opt_flags) |
| 5261 | { |
| 5262 | return get_varp_scope(&(options[opt_idx]), opt_flags); |
| 5263 | } |
| 5264 | |
| 5265 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5266 | * Get pointer to option variable. |
| 5267 | */ |
| 5268 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5269 | get_varp(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5270 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5271 | // hidden option, always return NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5272 | if (p->var == NULL) |
| 5273 | return NULL; |
| 5274 | |
| 5275 | switch ((int)p->indir) |
| 5276 | { |
| 5277 | case PV_NONE: return p->var; |
| 5278 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5279 | // global option with local value: use local value if it's been set |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5280 | case PV_EP: return *curbuf->b_p_ep != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5281 | ? (char_u *)&curbuf->b_p_ep : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5282 | case PV_KP: return *curbuf->b_p_kp != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5283 | ? (char_u *)&curbuf->b_p_kp : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5284 | case PV_PATH: return *curbuf->b_p_path != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5285 | ? (char_u *)&(curbuf->b_p_path) : p->var; |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 5286 | case PV_AR: return curbuf->b_p_ar >= 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5287 | ? (char_u *)&(curbuf->b_p_ar) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5288 | case PV_TAGS: return *curbuf->b_p_tags != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5289 | ? (char_u *)&(curbuf->b_p_tags) : p->var; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 5290 | case PV_TC: return *curbuf->b_p_tc != NUL |
| 5291 | ? (char_u *)&(curbuf->b_p_tc) : p->var; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5292 | case PV_BKC: return *curbuf->b_p_bkc != NUL |
| 5293 | ? (char_u *)&(curbuf->b_p_bkc) : p->var; |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 5294 | case PV_SISO: return curwin->w_p_siso >= 0 |
| 5295 | ? (char_u *)&(curwin->w_p_siso) : p->var; |
| 5296 | case PV_SO: return curwin->w_p_so >= 0 |
| 5297 | ? (char_u *)&(curwin->w_p_so) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5298 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5299 | case PV_DEF: return *curbuf->b_p_def != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5300 | ? (char_u *)&(curbuf->b_p_def) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5301 | case PV_INC: return *curbuf->b_p_inc != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5302 | ? (char_u *)&(curbuf->b_p_inc) : p->var; |
| 5303 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5304 | case PV_DICT: return *curbuf->b_p_dict != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5305 | ? (char_u *)&(curbuf->b_p_dict) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5306 | case PV_TSR: return *curbuf->b_p_tsr != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5307 | ? (char_u *)&(curbuf->b_p_tsr) : p->var; |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 5308 | case PV_FP: return *curbuf->b_p_fp != NUL |
| 5309 | ? (char_u *)&(curbuf->b_p_fp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5310 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5311 | case PV_EFM: return *curbuf->b_p_efm != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5312 | ? (char_u *)&(curbuf->b_p_efm) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5313 | case PV_GP: return *curbuf->b_p_gp != NUL |
| 5314 | ? (char_u *)&(curbuf->b_p_gp) : p->var; |
| 5315 | case PV_MP: return *curbuf->b_p_mp != NUL |
| 5316 | ? (char_u *)&(curbuf->b_p_mp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5317 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 5318 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 5319 | case PV_BEXPR: return *curbuf->b_p_bexpr != NUL |
| 5320 | ? (char_u *)&(curbuf->b_p_bexpr) : p->var; |
| 5321 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 5322 | #if defined(FEAT_CRYPT) |
| 5323 | case PV_CM: return *curbuf->b_p_cm != NUL |
| 5324 | ? (char_u *)&(curbuf->b_p_cm) : p->var; |
| 5325 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5326 | #ifdef FEAT_LINEBREAK |
| 5327 | case PV_SBR: return *curwin->w_p_sbr != NUL |
| 5328 | ? (char_u *)&(curwin->w_p_sbr) : p->var; |
| 5329 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5330 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5331 | case PV_STL: return *curwin->w_p_stl != NUL |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5332 | ? (char_u *)&(curwin->w_p_stl) : p->var; |
| 5333 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 5334 | case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL |
| 5335 | ? (char_u *)&(curbuf->b_p_ul) : p->var; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 5336 | #ifdef FEAT_LISP |
| 5337 | case PV_LW: return *curbuf->b_p_lw != NUL |
| 5338 | ? (char_u *)&(curbuf->b_p_lw) : p->var; |
| 5339 | #endif |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 5340 | case PV_MENC: return *curbuf->b_p_menc != NUL |
| 5341 | ? (char_u *)&(curbuf->b_p_menc) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5342 | #ifdef FEAT_ARABIC |
| 5343 | case PV_ARAB: return (char_u *)&(curwin->w_p_arab); |
| 5344 | #endif |
| 5345 | case PV_LIST: return (char_u *)&(curwin->w_p_list); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5346 | case PV_LCS: return *curwin->w_p_lcs != NUL |
| 5347 | ? (char_u *)&(curwin->w_p_lcs) : p->var; |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5348 | case PV_VE: return *curwin->w_p_ve != NUL |
| 5349 | ? (char_u *)&(curwin->w_p_ve) : p->var; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5350 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 5351 | case PV_SPELL: return (char_u *)&(curwin->w_p_spell); |
| 5352 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5353 | #ifdef FEAT_SYN_HL |
| 5354 | case PV_CUC: return (char_u *)&(curwin->w_p_cuc); |
| 5355 | case PV_CUL: return (char_u *)&(curwin->w_p_cul); |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 5356 | case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5357 | case PV_CC: return (char_u *)&(curwin->w_p_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5358 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5359 | #ifdef FEAT_DIFF |
| 5360 | case PV_DIFF: return (char_u *)&(curwin->w_p_diff); |
| 5361 | #endif |
| 5362 | #ifdef FEAT_FOLDING |
| 5363 | case PV_FDC: return (char_u *)&(curwin->w_p_fdc); |
| 5364 | case PV_FEN: return (char_u *)&(curwin->w_p_fen); |
| 5365 | case PV_FDI: return (char_u *)&(curwin->w_p_fdi); |
| 5366 | case PV_FDL: return (char_u *)&(curwin->w_p_fdl); |
| 5367 | case PV_FDM: return (char_u *)&(curwin->w_p_fdm); |
| 5368 | case PV_FML: return (char_u *)&(curwin->w_p_fml); |
| 5369 | case PV_FDN: return (char_u *)&(curwin->w_p_fdn); |
| 5370 | # ifdef FEAT_EVAL |
| 5371 | case PV_FDE: return (char_u *)&(curwin->w_p_fde); |
| 5372 | case PV_FDT: return (char_u *)&(curwin->w_p_fdt); |
| 5373 | # endif |
| 5374 | case PV_FMR: return (char_u *)&(curwin->w_p_fmr); |
| 5375 | #endif |
| 5376 | case PV_NU: return (char_u *)&(curwin->w_p_nu); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5377 | case PV_RNU: return (char_u *)&(curwin->w_p_rnu); |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 5378 | #ifdef FEAT_LINEBREAK |
| 5379 | case PV_NUW: return (char_u *)&(curwin->w_p_nuw); |
| 5380 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5381 | case PV_WFH: return (char_u *)&(curwin->w_p_wfh); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 5382 | case PV_WFW: return (char_u *)&(curwin->w_p_wfw); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 5383 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5384 | case PV_PVW: return (char_u *)&(curwin->w_p_pvw); |
| 5385 | #endif |
| 5386 | #ifdef FEAT_RIGHTLEFT |
| 5387 | case PV_RL: return (char_u *)&(curwin->w_p_rl); |
| 5388 | case PV_RLC: return (char_u *)&(curwin->w_p_rlc); |
| 5389 | #endif |
| 5390 | case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); |
| 5391 | case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); |
| 5392 | #ifdef FEAT_LINEBREAK |
| 5393 | case PV_LBR: return (char_u *)&(curwin->w_p_lbr); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 5394 | case PV_BRI: return (char_u *)&(curwin->w_p_bri); |
| 5395 | case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5396 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5397 | case PV_WCR: return (char_u *)&(curwin->w_p_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5398 | case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5399 | case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5400 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5401 | case PV_COCU: return (char_u *)&(curwin->w_p_cocu); |
| 5402 | case PV_COLE: return (char_u *)&(curwin->w_p_cole); |
| 5403 | #endif |
| 5404 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 5405 | case PV_TWK: return (char_u *)&(curwin->w_p_twk); |
| 5406 | case PV_TWS: return (char_u *)&(curwin->w_p_tws); |
| 5407 | case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5408 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5409 | |
| 5410 | case PV_AI: return (char_u *)&(curbuf->b_p_ai); |
| 5411 | case PV_BIN: return (char_u *)&(curbuf->b_p_bin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5412 | case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5413 | case PV_BH: return (char_u *)&(curbuf->b_p_bh); |
| 5414 | case PV_BT: return (char_u *)&(curbuf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5415 | case PV_BL: return (char_u *)&(curbuf->b_p_bl); |
| 5416 | case PV_CI: return (char_u *)&(curbuf->b_p_ci); |
| 5417 | #ifdef FEAT_CINDENT |
| 5418 | case PV_CIN: return (char_u *)&(curbuf->b_p_cin); |
| 5419 | case PV_CINK: return (char_u *)&(curbuf->b_p_cink); |
| 5420 | case PV_CINO: return (char_u *)&(curbuf->b_p_cino); |
| 5421 | #endif |
| 5422 | #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) |
| 5423 | case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); |
| 5424 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5425 | case PV_COM: return (char_u *)&(curbuf->b_p_com); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5426 | #ifdef FEAT_FOLDING |
| 5427 | case PV_CMS: return (char_u *)&(curbuf->b_p_cms); |
| 5428 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5429 | case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 5430 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 5431 | case PV_CSL: return (char_u *)&(curbuf->b_p_csl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5432 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 5433 | #ifdef FEAT_COMPL_FUNC |
| 5434 | case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 5435 | case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); |
Bram Moolenaar | d4c4bfa | 2021-10-16 21:14:11 +0100 | [diff] [blame] | 5436 | case PV_THSFU: return (char_u *)&(curbuf->b_p_tsrfu); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 5437 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 5438 | #ifdef FEAT_EVAL |
| 5439 | case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); |
| 5440 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5441 | case PV_EOL: return (char_u *)&(curbuf->b_p_eol); |
Bram Moolenaar | 34d72d4 | 2015-07-17 14:18:08 +0200 | [diff] [blame] | 5442 | case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5443 | case PV_ET: return (char_u *)&(curbuf->b_p_et); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5444 | case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5445 | case PV_FF: return (char_u *)&(curbuf->b_p_ff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5446 | case PV_FT: return (char_u *)&(curbuf->b_p_ft); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5447 | case PV_FO: return (char_u *)&(curbuf->b_p_fo); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 5448 | case PV_FLP: return (char_u *)&(curbuf->b_p_flp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5449 | case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); |
| 5450 | case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); |
| 5451 | case PV_INF: return (char_u *)&(curbuf->b_p_inf); |
| 5452 | case PV_ISK: return (char_u *)&(curbuf->b_p_isk); |
| 5453 | #ifdef FEAT_FIND_ID |
| 5454 | # ifdef FEAT_EVAL |
| 5455 | case PV_INEX: return (char_u *)&(curbuf->b_p_inex); |
| 5456 | # endif |
| 5457 | #endif |
| 5458 | #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) |
| 5459 | case PV_INDE: return (char_u *)&(curbuf->b_p_inde); |
| 5460 | case PV_INDK: return (char_u *)&(curbuf->b_p_indk); |
| 5461 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5462 | #ifdef FEAT_EVAL |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 5463 | case PV_FEX: return (char_u *)&(curbuf->b_p_fex); |
| 5464 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5465 | #ifdef FEAT_CRYPT |
| 5466 | case PV_KEY: return (char_u *)&(curbuf->b_p_key); |
| 5467 | #endif |
| 5468 | #ifdef FEAT_LISP |
| 5469 | case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); |
| 5470 | #endif |
| 5471 | case PV_ML: return (char_u *)&(curbuf->b_p_ml); |
| 5472 | case PV_MPS: return (char_u *)&(curbuf->b_p_mps); |
| 5473 | case PV_MA: return (char_u *)&(curbuf->b_p_ma); |
| 5474 | case PV_MOD: return (char_u *)&(curbuf->b_changed); |
| 5475 | case PV_NF: return (char_u *)&(curbuf->b_p_nf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5476 | case PV_PI: return (char_u *)&(curbuf->b_p_pi); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 5477 | #ifdef FEAT_TEXTOBJ |
| 5478 | case PV_QE: return (char_u *)&(curbuf->b_p_qe); |
| 5479 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5480 | case PV_RO: return (char_u *)&(curbuf->b_p_ro); |
| 5481 | #ifdef FEAT_SMARTINDENT |
| 5482 | case PV_SI: return (char_u *)&(curbuf->b_p_si); |
| 5483 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5484 | case PV_SN: return (char_u *)&(curbuf->b_p_sn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5485 | case PV_STS: return (char_u *)&(curbuf->b_p_sts); |
| 5486 | #ifdef FEAT_SEARCHPATH |
| 5487 | case PV_SUA: return (char_u *)&(curbuf->b_p_sua); |
| 5488 | #endif |
| 5489 | case PV_SWF: return (char_u *)&(curbuf->b_p_swf); |
| 5490 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 5491 | case PV_SMC: return (char_u *)&(curbuf->b_p_smc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5492 | case PV_SYN: return (char_u *)&(curbuf->b_p_syn); |
| 5493 | #endif |
| 5494 | #ifdef FEAT_SPELL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5495 | case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); |
| 5496 | case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); |
| 5497 | case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 5498 | case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5499 | #endif |
| 5500 | case PV_SW: return (char_u *)&(curbuf->b_p_sw); |
| 5501 | case PV_TS: return (char_u *)&(curbuf->b_p_ts); |
| 5502 | case PV_TW: return (char_u *)&(curbuf->b_p_tw); |
| 5503 | case PV_TX: return (char_u *)&(curbuf->b_p_tx); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 5504 | #ifdef FEAT_PERSISTENT_UNDO |
| 5505 | case PV_UDF: return (char_u *)&(curbuf->b_p_udf); |
| 5506 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5507 | case PV_WM: return (char_u *)&(curbuf->b_p_wm); |
| 5508 | #ifdef FEAT_KEYMAP |
| 5509 | case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); |
| 5510 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 5511 | #ifdef FEAT_SIGNS |
| 5512 | case PV_SCL: return (char_u *)&(curwin->w_p_scl); |
| 5513 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 5514 | #ifdef FEAT_VARTABS |
| 5515 | case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); |
| 5516 | case PV_VTS: return (char_u *)&(curbuf->b_p_vts); |
| 5517 | #endif |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 5518 | default: iemsg(_("E356: get_varp ERROR")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5519 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5520 | // always return a valid pointer to avoid a crash! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5521 | return (char_u *)&(curbuf->b_p_wm); |
| 5522 | } |
| 5523 | |
| 5524 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5525 | * Return a pointer to the variable for option at 'opt_idx' |
| 5526 | */ |
| 5527 | char_u * |
| 5528 | get_option_var(int opt_idx) |
| 5529 | { |
| 5530 | return options[opt_idx].var; |
| 5531 | } |
| 5532 | |
| 5533 | /* |
| 5534 | * Return the full name of the option at 'opt_idx' |
| 5535 | */ |
| 5536 | char_u * |
| 5537 | get_option_fullname(int opt_idx) |
| 5538 | { |
| 5539 | return (char_u *)options[opt_idx].fullname; |
| 5540 | } |
| 5541 | |
| 5542 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5543 | * Get the value of 'equalprg', either the buffer-local one or the global one. |
| 5544 | */ |
| 5545 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5546 | get_equalprg(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5547 | { |
| 5548 | if (*curbuf->b_p_ep == NUL) |
| 5549 | return p_ep; |
| 5550 | return curbuf->b_p_ep; |
| 5551 | } |
| 5552 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5553 | /* |
| 5554 | * Copy options from one window to another. |
| 5555 | * Used when splitting a window. |
| 5556 | */ |
| 5557 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5558 | win_copy_options(win_T *wp_from, win_T *wp_to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5559 | { |
| 5560 | copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); |
| 5561 | copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 5562 | after_copy_winopt(wp_to); |
| 5563 | } |
| 5564 | |
| 5565 | /* |
| 5566 | * After copying window options: update variables depending on options. |
| 5567 | */ |
| 5568 | void |
Bram Moolenaar | 473952e | 2019-09-28 16:30:04 +0200 | [diff] [blame] | 5569 | after_copy_winopt(win_T *wp UNUSED) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 5570 | { |
| 5571 | #ifdef FEAT_LINEBREAK |
| 5572 | briopt_check(wp); |
Bram Moolenaar | 285ed7e | 2014-08-24 21:39:49 +0200 | [diff] [blame] | 5573 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 5574 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 5575 | fill_culopt_flags(NULL, wp); |
| 5576 | check_colorcolumn(wp); |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 5577 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5578 | set_chars_option(wp, &wp->w_p_lcs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5579 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5580 | |
| 5581 | /* |
| 5582 | * Copy the options from one winopt_T to another. |
| 5583 | * Doesn't free the old option values in "to", use clear_winopt() for that. |
| 5584 | * The 'scroll' option is not copied, because it depends on the window height. |
| 5585 | * The 'previewwindow' option is reset, there can be only one preview window. |
| 5586 | */ |
| 5587 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5588 | copy_winopt(winopt_T *from, winopt_T *to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5589 | { |
| 5590 | #ifdef FEAT_ARABIC |
| 5591 | to->wo_arab = from->wo_arab; |
| 5592 | #endif |
| 5593 | to->wo_list = from->wo_list; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5594 | to->wo_lcs = vim_strsave(from->wo_lcs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5595 | to->wo_nu = from->wo_nu; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5596 | to->wo_rnu = from->wo_rnu; |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5597 | to->wo_ve = vim_strsave(from->wo_ve); |
| 5598 | to->wo_ve_flags = from->wo_ve_flags; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 5599 | #ifdef FEAT_LINEBREAK |
| 5600 | to->wo_nuw = from->wo_nuw; |
| 5601 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5602 | #ifdef FEAT_RIGHTLEFT |
| 5603 | to->wo_rl = from->wo_rl; |
| 5604 | to->wo_rlc = vim_strsave(from->wo_rlc); |
| 5605 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5606 | #ifdef FEAT_LINEBREAK |
| 5607 | to->wo_sbr = vim_strsave(from->wo_sbr); |
| 5608 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5609 | #ifdef FEAT_STL_OPT |
| 5610 | to->wo_stl = vim_strsave(from->wo_stl); |
| 5611 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5612 | to->wo_wrap = from->wo_wrap; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5613 | #ifdef FEAT_DIFF |
| 5614 | to->wo_wrap_save = from->wo_wrap_save; |
| 5615 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5616 | #ifdef FEAT_LINEBREAK |
| 5617 | to->wo_lbr = from->wo_lbr; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 5618 | to->wo_bri = from->wo_bri; |
| 5619 | to->wo_briopt = vim_strsave(from->wo_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5620 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5621 | to->wo_wcr = vim_strsave(from->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5622 | to->wo_scb = from->wo_scb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5623 | to->wo_scb_save = from->wo_scb_save; |
Bram Moolenaar | 4161dcc | 2010-12-02 15:33:21 +0100 | [diff] [blame] | 5624 | to->wo_crb = from->wo_crb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5625 | to->wo_crb_save = from->wo_crb_save; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5626 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 5627 | to->wo_spell = from->wo_spell; |
| 5628 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5629 | #ifdef FEAT_SYN_HL |
| 5630 | to->wo_cuc = from->wo_cuc; |
| 5631 | to->wo_cul = from->wo_cul; |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 5632 | to->wo_culopt = vim_strsave(from->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5633 | to->wo_cc = vim_strsave(from->wo_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 5634 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5635 | #ifdef FEAT_DIFF |
| 5636 | to->wo_diff = from->wo_diff; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5637 | to->wo_diff_saved = from->wo_diff_saved; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5638 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5639 | #ifdef FEAT_CONCEAL |
| 5640 | to->wo_cocu = vim_strsave(from->wo_cocu); |
Bram Moolenaar | d497a30 | 2010-07-23 22:27:03 +0200 | [diff] [blame] | 5641 | to->wo_cole = from->wo_cole; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5642 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5643 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 5644 | to->wo_twk = vim_strsave(from->wo_twk); |
| 5645 | to->wo_tws = vim_strsave(from->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5646 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5647 | #ifdef FEAT_FOLDING |
| 5648 | to->wo_fdc = from->wo_fdc; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5649 | to->wo_fdc_save = from->wo_fdc_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5650 | to->wo_fen = from->wo_fen; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5651 | to->wo_fen_save = from->wo_fen_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5652 | to->wo_fdi = vim_strsave(from->wo_fdi); |
| 5653 | to->wo_fml = from->wo_fml; |
| 5654 | to->wo_fdl = from->wo_fdl; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5655 | to->wo_fdl_save = from->wo_fdl_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5656 | to->wo_fdm = vim_strsave(from->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5657 | to->wo_fdm_save = from->wo_diff_saved |
| 5658 | ? vim_strsave(from->wo_fdm_save) : empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5659 | to->wo_fdn = from->wo_fdn; |
| 5660 | # ifdef FEAT_EVAL |
| 5661 | to->wo_fde = vim_strsave(from->wo_fde); |
| 5662 | to->wo_fdt = vim_strsave(from->wo_fdt); |
| 5663 | # endif |
| 5664 | to->wo_fmr = vim_strsave(from->wo_fmr); |
| 5665 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 5666 | #ifdef FEAT_SIGNS |
| 5667 | to->wo_scl = vim_strsave(from->wo_scl); |
| 5668 | #endif |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5669 | |
| 5670 | #ifdef FEAT_EVAL |
| 5671 | // Copy the script context so that we know where the value was last set. |
| 5672 | mch_memmove(to->wo_script_ctx, from->wo_script_ctx, |
| 5673 | sizeof(to->wo_script_ctx)); |
| 5674 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5675 | check_winopt(to); // don't want NULL pointers |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | /* |
| 5679 | * Check string options in a window for a NULL value. |
| 5680 | */ |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 5681 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5682 | check_win_options(win_T *win) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5683 | { |
| 5684 | check_winopt(&win->w_onebuf_opt); |
| 5685 | check_winopt(&win->w_allbuf_opt); |
| 5686 | } |
| 5687 | |
| 5688 | /* |
| 5689 | * Check for NULL pointers in a winopt_T and replace them with empty_option. |
| 5690 | */ |
Bram Moolenaar | 8dc907d | 2014-06-25 14:44:10 +0200 | [diff] [blame] | 5691 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5692 | check_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5693 | { |
| 5694 | #ifdef FEAT_FOLDING |
| 5695 | check_string_option(&wop->wo_fdi); |
| 5696 | check_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5697 | check_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5698 | # ifdef FEAT_EVAL |
| 5699 | check_string_option(&wop->wo_fde); |
| 5700 | check_string_option(&wop->wo_fdt); |
| 5701 | # endif |
| 5702 | check_string_option(&wop->wo_fmr); |
| 5703 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 5704 | #ifdef FEAT_SIGNS |
| 5705 | check_string_option(&wop->wo_scl); |
| 5706 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5707 | #ifdef FEAT_RIGHTLEFT |
| 5708 | check_string_option(&wop->wo_rlc); |
| 5709 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5710 | #ifdef FEAT_LINEBREAK |
| 5711 | check_string_option(&wop->wo_sbr); |
| 5712 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5713 | #ifdef FEAT_STL_OPT |
| 5714 | check_string_option(&wop->wo_stl); |
| 5715 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5716 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 5717 | check_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5718 | check_string_option(&wop->wo_cc); |
| 5719 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5720 | #ifdef FEAT_CONCEAL |
| 5721 | check_string_option(&wop->wo_cocu); |
| 5722 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5723 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 5724 | check_string_option(&wop->wo_twk); |
| 5725 | check_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5726 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 5727 | #ifdef FEAT_LINEBREAK |
| 5728 | check_string_option(&wop->wo_briopt); |
| 5729 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5730 | check_string_option(&wop->wo_wcr); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5731 | check_string_option(&wop->wo_lcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5732 | check_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | /* |
| 5736 | * Free the allocated memory inside a winopt_T. |
| 5737 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5738 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5739 | clear_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5740 | { |
| 5741 | #ifdef FEAT_FOLDING |
| 5742 | clear_string_option(&wop->wo_fdi); |
| 5743 | clear_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 5744 | clear_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5745 | # ifdef FEAT_EVAL |
| 5746 | clear_string_option(&wop->wo_fde); |
| 5747 | clear_string_option(&wop->wo_fdt); |
| 5748 | # endif |
| 5749 | clear_string_option(&wop->wo_fmr); |
| 5750 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 5751 | #ifdef FEAT_SIGNS |
| 5752 | clear_string_option(&wop->wo_scl); |
| 5753 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 5754 | #ifdef FEAT_LINEBREAK |
| 5755 | clear_string_option(&wop->wo_briopt); |
| 5756 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5757 | clear_string_option(&wop->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5758 | #ifdef FEAT_RIGHTLEFT |
| 5759 | clear_string_option(&wop->wo_rlc); |
| 5760 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 5761 | #ifdef FEAT_LINEBREAK |
| 5762 | clear_string_option(&wop->wo_sbr); |
| 5763 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5764 | #ifdef FEAT_STL_OPT |
| 5765 | clear_string_option(&wop->wo_stl); |
| 5766 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5767 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 5768 | clear_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5769 | clear_string_option(&wop->wo_cc); |
| 5770 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5771 | #ifdef FEAT_CONCEAL |
| 5772 | clear_string_option(&wop->wo_cocu); |
| 5773 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5774 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 5775 | clear_string_option(&wop->wo_twk); |
| 5776 | clear_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 5777 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 5778 | clear_string_option(&wop->wo_lcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 5779 | clear_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5782 | #ifdef FEAT_EVAL |
| 5783 | // Index into the options table for a buffer-local option enum. |
| 5784 | static int buf_opt_idx[BV_COUNT]; |
| 5785 | # define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].script_ctx |
| 5786 | |
| 5787 | /* |
| 5788 | * Initialize buf_opt_idx[] if not done already. |
| 5789 | */ |
| 5790 | static void |
| 5791 | init_buf_opt_idx(void) |
| 5792 | { |
| 5793 | static int did_init_buf_opt_idx = FALSE; |
| 5794 | int i; |
| 5795 | |
| 5796 | if (did_init_buf_opt_idx) |
| 5797 | return; |
| 5798 | did_init_buf_opt_idx = TRUE; |
| 5799 | for (i = 0; !istermoption_idx(i); i++) |
| 5800 | if (options[i].indir & PV_BUF) |
| 5801 | buf_opt_idx[options[i].indir & PV_MASK] = i; |
| 5802 | } |
| 5803 | #else |
| 5804 | # define COPY_OPT_SCTX(buf, bv) |
| 5805 | #endif |
| 5806 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5807 | /* |
| 5808 | * Copy global option values to local options for one buffer. |
| 5809 | * Used when creating a new buffer and sometimes when entering a buffer. |
| 5810 | * flags: |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5811 | * BCO_ENTER We will enter the buffer "buf". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5812 | * BCO_ALWAYS Always copy the options, but only set b_p_initialized when |
| 5813 | * appropriate. |
| 5814 | * BCO_NOHELP Don't copy the values to a help buffer. |
| 5815 | */ |
| 5816 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5817 | buf_copy_options(buf_T *buf, int flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5818 | { |
| 5819 | int should_copy = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5820 | char_u *save_p_isk = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5821 | int dont_do_help; |
| 5822 | int did_isk = FALSE; |
| 5823 | |
| 5824 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5825 | * Skip this when the option defaults have not been set yet. Happens when |
| 5826 | * main() allocates the first buffer. |
| 5827 | */ |
| 5828 | if (p_cpo != NULL) |
| 5829 | { |
| 5830 | /* |
| 5831 | * Always copy when entering and 'cpo' contains 'S'. |
| 5832 | * Don't copy when already initialized. |
| 5833 | * Don't copy when 'cpo' contains 's' and not entering. |
| 5834 | * 'S' BCO_ENTER initialized 's' should_copy |
| 5835 | * yes yes X X TRUE |
| 5836 | * yes no yes X FALSE |
| 5837 | * no X yes X FALSE |
| 5838 | * X no no yes FALSE |
| 5839 | * X no no no TRUE |
| 5840 | * no yes no X TRUE |
| 5841 | */ |
| 5842 | if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) |
| 5843 | && (buf->b_p_initialized |
| 5844 | || (!(flags & BCO_ENTER) |
| 5845 | && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) |
| 5846 | should_copy = FALSE; |
| 5847 | |
| 5848 | if (should_copy || (flags & BCO_ALWAYS)) |
| 5849 | { |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5850 | #ifdef FEAT_EVAL |
Bram Moolenaar | a80faa8 | 2020-04-12 19:37:17 +0200 | [diff] [blame] | 5851 | CLEAR_FIELD(buf->b_p_script_ctx); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5852 | init_buf_opt_idx(); |
| 5853 | #endif |
| 5854 | // Don't copy the options specific to a help buffer when |
| 5855 | // BCO_NOHELP is given or the options were initialized already |
| 5856 | // (jumping back to a help file with CTRL-T or CTRL-O) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5857 | dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) |
| 5858 | || buf->b_p_initialized; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5859 | if (dont_do_help) // don't free b_p_isk |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5860 | { |
| 5861 | save_p_isk = buf->b_p_isk; |
| 5862 | buf->b_p_isk = NULL; |
| 5863 | } |
| 5864 | /* |
Bram Moolenaar | 40385db | 2018-08-07 22:31:44 +0200 | [diff] [blame] | 5865 | * Always free the allocated strings. If not already initialized, |
| 5866 | * reset 'readonly' and copy 'fileformat'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5867 | */ |
| 5868 | if (!buf->b_p_initialized) |
| 5869 | { |
| 5870 | free_buf_options(buf, TRUE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5871 | buf->b_p_ro = FALSE; // don't copy readonly |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5872 | buf->b_p_tx = p_tx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5873 | buf->b_p_fenc = vim_strsave(p_fenc); |
Bram Moolenaar | e8ef3a0 | 2016-10-12 17:45:29 +0200 | [diff] [blame] | 5874 | switch (*p_ffs) |
| 5875 | { |
| 5876 | case 'm': |
| 5877 | buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break; |
| 5878 | case 'd': |
| 5879 | buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break; |
| 5880 | case 'u': |
| 5881 | buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break; |
| 5882 | default: |
| 5883 | buf->b_p_ff = vim_strsave(p_ff); |
| 5884 | } |
| 5885 | if (buf->b_p_ff != NULL) |
| 5886 | buf->b_start_ffc = *buf->b_p_ff; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5887 | buf->b_p_bh = empty_option; |
| 5888 | buf->b_p_bt = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5889 | } |
| 5890 | else |
| 5891 | free_buf_options(buf, FALSE); |
| 5892 | |
| 5893 | buf->b_p_ai = p_ai; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5894 | COPY_OPT_SCTX(buf, BV_AI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5895 | buf->b_p_ai_nopaste = p_ai_nopaste; |
| 5896 | buf->b_p_sw = p_sw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5897 | COPY_OPT_SCTX(buf, BV_SW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5898 | buf->b_p_tw = p_tw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5899 | COPY_OPT_SCTX(buf, BV_TW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5900 | buf->b_p_tw_nopaste = p_tw_nopaste; |
| 5901 | buf->b_p_tw_nobin = p_tw_nobin; |
| 5902 | buf->b_p_wm = p_wm; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5903 | COPY_OPT_SCTX(buf, BV_WM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5904 | buf->b_p_wm_nopaste = p_wm_nopaste; |
| 5905 | buf->b_p_wm_nobin = p_wm_nobin; |
| 5906 | buf->b_p_bin = p_bin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5907 | COPY_OPT_SCTX(buf, BV_BIN); |
Bram Moolenaar | e8bb255 | 2005-07-08 22:26:47 +0000 | [diff] [blame] | 5908 | buf->b_p_bomb = p_bomb; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5909 | COPY_OPT_SCTX(buf, BV_BOMB); |
Bram Moolenaar | b388be0 | 2015-07-22 22:19:38 +0200 | [diff] [blame] | 5910 | buf->b_p_fixeol = p_fixeol; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5911 | COPY_OPT_SCTX(buf, BV_FIXEOL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5912 | buf->b_p_et = p_et; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5913 | COPY_OPT_SCTX(buf, BV_ET); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5914 | buf->b_p_et_nobin = p_et_nobin; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 5915 | buf->b_p_et_nopaste = p_et_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5916 | buf->b_p_ml = p_ml; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5917 | COPY_OPT_SCTX(buf, BV_ML); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5918 | buf->b_p_ml_nobin = p_ml_nobin; |
| 5919 | buf->b_p_inf = p_inf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5920 | COPY_OPT_SCTX(buf, BV_INF); |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 5921 | if (cmdmod.cmod_flags & CMOD_NOSWAPFILE) |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5922 | buf->b_p_swf = FALSE; |
| 5923 | else |
| 5924 | { |
| 5925 | buf->b_p_swf = p_swf; |
| 5926 | COPY_OPT_SCTX(buf, BV_INF); |
| 5927 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5928 | buf->b_p_cpt = vim_strsave(p_cpt); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5929 | COPY_OPT_SCTX(buf, BV_CPT); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 5930 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 5931 | buf->b_p_csl = vim_strsave(p_csl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5932 | COPY_OPT_SCTX(buf, BV_CSL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5933 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 5934 | #ifdef FEAT_COMPL_FUNC |
| 5935 | buf->b_p_cfu = vim_strsave(p_cfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5936 | COPY_OPT_SCTX(buf, BV_CFU); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 5937 | buf->b_p_ofu = vim_strsave(p_ofu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5938 | COPY_OPT_SCTX(buf, BV_OFU); |
Bram Moolenaar | d4c4bfa | 2021-10-16 21:14:11 +0100 | [diff] [blame] | 5939 | buf->b_p_tsrfu = vim_strsave(p_thsfu); |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 5940 | COPY_OPT_SCTX(buf, BV_THSFU); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 5941 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 5942 | #ifdef FEAT_EVAL |
| 5943 | buf->b_p_tfu = vim_strsave(p_tfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5944 | COPY_OPT_SCTX(buf, BV_TFU); |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 5945 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5946 | buf->b_p_sts = p_sts; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5947 | COPY_OPT_SCTX(buf, BV_STS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5948 | buf->b_p_sts_nopaste = p_sts_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 5949 | #ifdef FEAT_VARTABS |
| 5950 | buf->b_p_vsts = vim_strsave(p_vsts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5951 | COPY_OPT_SCTX(buf, BV_VSTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 5952 | if (p_vsts && p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 5953 | (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 5954 | else |
| 5955 | buf->b_p_vsts_array = 0; |
| 5956 | buf->b_p_vsts_nopaste = p_vsts_nopaste |
| 5957 | ? vim_strsave(p_vsts_nopaste) : NULL; |
| 5958 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5959 | buf->b_p_sn = p_sn; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5960 | COPY_OPT_SCTX(buf, BV_SN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5961 | buf->b_p_com = vim_strsave(p_com); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5962 | COPY_OPT_SCTX(buf, BV_COM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5963 | #ifdef FEAT_FOLDING |
| 5964 | buf->b_p_cms = vim_strsave(p_cms); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5965 | COPY_OPT_SCTX(buf, BV_CMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5966 | #endif |
| 5967 | buf->b_p_fo = vim_strsave(p_fo); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5968 | COPY_OPT_SCTX(buf, BV_FO); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 5969 | buf->b_p_flp = vim_strsave(p_flp); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5970 | COPY_OPT_SCTX(buf, BV_FLP); |
Bram Moolenaar | 473952e | 2019-09-28 16:30:04 +0200 | [diff] [blame] | 5971 | // NOTE: Valgrind may report a bogus memory leak for 'nrformats' |
| 5972 | // when it is set to 8 bytes in defaults.vim. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5973 | buf->b_p_nf = vim_strsave(p_nf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5974 | COPY_OPT_SCTX(buf, BV_NF); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5975 | buf->b_p_mps = vim_strsave(p_mps); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5976 | COPY_OPT_SCTX(buf, BV_MPS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5977 | #ifdef FEAT_SMARTINDENT |
| 5978 | buf->b_p_si = p_si; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5979 | COPY_OPT_SCTX(buf, BV_SI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5980 | #endif |
| 5981 | buf->b_p_ci = p_ci; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5982 | COPY_OPT_SCTX(buf, BV_CI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5983 | #ifdef FEAT_CINDENT |
| 5984 | buf->b_p_cin = p_cin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5985 | COPY_OPT_SCTX(buf, BV_CIN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5986 | buf->b_p_cink = vim_strsave(p_cink); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5987 | COPY_OPT_SCTX(buf, BV_CINK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5988 | buf->b_p_cino = vim_strsave(p_cino); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5989 | COPY_OPT_SCTX(buf, BV_CINO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5990 | #endif |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5991 | // Don't copy 'filetype', it must be detected |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5992 | buf->b_p_ft = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5993 | buf->b_p_pi = p_pi; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5994 | COPY_OPT_SCTX(buf, BV_PI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5995 | #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) |
| 5996 | buf->b_p_cinw = vim_strsave(p_cinw); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 5997 | COPY_OPT_SCTX(buf, BV_CINW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5998 | #endif |
| 5999 | #ifdef FEAT_LISP |
| 6000 | buf->b_p_lisp = p_lisp; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6001 | COPY_OPT_SCTX(buf, BV_LISP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6002 | #endif |
| 6003 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6004 | // Don't copy 'syntax', it must be set |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6005 | buf->b_p_syn = empty_option; |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 6006 | buf->b_p_smc = p_smc; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6007 | COPY_OPT_SCTX(buf, BV_SMC); |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 6008 | buf->b_s.b_syn_isk = empty_option; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6009 | #endif |
| 6010 | #ifdef FEAT_SPELL |
Bram Moolenaar | d5784f9 | 2010-10-13 14:05:35 +0200 | [diff] [blame] | 6011 | buf->b_s.b_p_spc = vim_strsave(p_spc); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6012 | COPY_OPT_SCTX(buf, BV_SPC); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6013 | (void)compile_cap_prog(&buf->b_s); |
| 6014 | buf->b_s.b_p_spf = vim_strsave(p_spf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6015 | COPY_OPT_SCTX(buf, BV_SPF); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6016 | buf->b_s.b_p_spl = vim_strsave(p_spl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6017 | COPY_OPT_SCTX(buf, BV_SPL); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 6018 | buf->b_s.b_p_spo = vim_strsave(p_spo); |
| 6019 | COPY_OPT_SCTX(buf, BV_SPO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6020 | #endif |
| 6021 | #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) |
| 6022 | buf->b_p_inde = vim_strsave(p_inde); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6023 | COPY_OPT_SCTX(buf, BV_INDE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6024 | buf->b_p_indk = vim_strsave(p_indk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6025 | COPY_OPT_SCTX(buf, BV_INDK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6026 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6027 | buf->b_p_fp = empty_option; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6028 | #if defined(FEAT_EVAL) |
| 6029 | buf->b_p_fex = vim_strsave(p_fex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6030 | COPY_OPT_SCTX(buf, BV_FEX); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6031 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6032 | #ifdef FEAT_CRYPT |
| 6033 | buf->b_p_key = vim_strsave(p_key); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6034 | COPY_OPT_SCTX(buf, BV_KEY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6035 | #endif |
| 6036 | #ifdef FEAT_SEARCHPATH |
| 6037 | buf->b_p_sua = vim_strsave(p_sua); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6038 | COPY_OPT_SCTX(buf, BV_SUA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6039 | #endif |
| 6040 | #ifdef FEAT_KEYMAP |
| 6041 | buf->b_p_keymap = vim_strsave(p_keymap); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6042 | COPY_OPT_SCTX(buf, BV_KMAP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6043 | buf->b_kmap_state |= KEYMAP_INIT; |
| 6044 | #endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6045 | #ifdef FEAT_TERMINAL |
| 6046 | buf->b_p_twsl = p_twsl; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6047 | COPY_OPT_SCTX(buf, BV_TWSL); |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6048 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6049 | // This isn't really an option, but copying the langmap and IME |
| 6050 | // state from the current buffer is better than resetting it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6051 | buf->b_p_iminsert = p_iminsert; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6052 | COPY_OPT_SCTX(buf, BV_IMI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6053 | buf->b_p_imsearch = p_imsearch; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6054 | COPY_OPT_SCTX(buf, BV_IMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6055 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6056 | // options that are normally global but also have a local value |
| 6057 | // are not copied, start using the global value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6058 | buf->b_p_ar = -1; |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6059 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6060 | buf->b_p_bkc = empty_option; |
| 6061 | buf->b_bkc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6062 | #ifdef FEAT_QUICKFIX |
| 6063 | buf->b_p_gp = empty_option; |
| 6064 | buf->b_p_mp = empty_option; |
| 6065 | buf->b_p_efm = empty_option; |
| 6066 | #endif |
| 6067 | buf->b_p_ep = empty_option; |
| 6068 | buf->b_p_kp = empty_option; |
| 6069 | buf->b_p_path = empty_option; |
| 6070 | buf->b_p_tags = empty_option; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6071 | buf->b_p_tc = empty_option; |
| 6072 | buf->b_tc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6073 | #ifdef FEAT_FIND_ID |
| 6074 | buf->b_p_def = empty_option; |
| 6075 | buf->b_p_inc = empty_option; |
| 6076 | # ifdef FEAT_EVAL |
| 6077 | buf->b_p_inex = vim_strsave(p_inex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6078 | COPY_OPT_SCTX(buf, BV_INEX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6079 | # endif |
| 6080 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6081 | buf->b_p_dict = empty_option; |
| 6082 | buf->b_p_tsr = empty_option; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6083 | #ifdef FEAT_TEXTOBJ |
| 6084 | buf->b_p_qe = vim_strsave(p_qe); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6085 | COPY_OPT_SCTX(buf, BV_QE); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6086 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6087 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6088 | buf->b_p_bexpr = empty_option; |
| 6089 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6090 | #if defined(FEAT_CRYPT) |
| 6091 | buf->b_p_cm = empty_option; |
| 6092 | #endif |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 6093 | #ifdef FEAT_PERSISTENT_UNDO |
| 6094 | buf->b_p_udf = p_udf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6095 | COPY_OPT_SCTX(buf, BV_UDF); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 6096 | #endif |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6097 | #ifdef FEAT_LISP |
| 6098 | buf->b_p_lw = empty_option; |
| 6099 | #endif |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6100 | buf->b_p_menc = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6101 | |
| 6102 | /* |
| 6103 | * Don't copy the options set by ex_help(), use the saved values, |
| 6104 | * when going from a help buffer to a non-help buffer. |
| 6105 | * Don't touch these at all when BCO_NOHELP is used and going from |
| 6106 | * or to a help buffer. |
| 6107 | */ |
| 6108 | if (dont_do_help) |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6109 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6110 | buf->b_p_isk = save_p_isk; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6111 | #ifdef FEAT_VARTABS |
| 6112 | if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 6113 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6114 | else |
| 6115 | buf->b_p_vts_array = NULL; |
| 6116 | #endif |
| 6117 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6118 | else |
| 6119 | { |
| 6120 | buf->b_p_isk = vim_strsave(p_isk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6121 | COPY_OPT_SCTX(buf, BV_ISK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6122 | did_isk = TRUE; |
| 6123 | buf->b_p_ts = p_ts; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6124 | #ifdef FEAT_VARTABS |
| 6125 | buf->b_p_vts = vim_strsave(p_vts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6126 | COPY_OPT_SCTX(buf, BV_VTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6127 | if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 6128 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6129 | else |
| 6130 | buf->b_p_vts_array = NULL; |
| 6131 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6132 | buf->b_help = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6133 | if (buf->b_p_bt[0] == 'h') |
| 6134 | clear_string_option(&buf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6135 | buf->b_p_ma = p_ma; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6136 | COPY_OPT_SCTX(buf, BV_MA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | /* |
| 6141 | * When the options should be copied (ignoring BCO_ALWAYS), set the |
| 6142 | * flag that indicates that the options have been initialized. |
| 6143 | */ |
| 6144 | if (should_copy) |
| 6145 | buf->b_p_initialized = TRUE; |
| 6146 | } |
| 6147 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6148 | check_buf_options(buf); // make sure we don't have NULLs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6149 | if (did_isk) |
| 6150 | (void)buf_init_chartab(buf, FALSE); |
| 6151 | } |
| 6152 | |
| 6153 | /* |
| 6154 | * Reset the 'modifiable' option and its default value. |
| 6155 | */ |
| 6156 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6157 | reset_modifiable(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6158 | { |
| 6159 | int opt_idx; |
| 6160 | |
| 6161 | curbuf->b_p_ma = FALSE; |
| 6162 | p_ma = FALSE; |
| 6163 | opt_idx = findoption((char_u *)"ma"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 6164 | if (opt_idx >= 0) |
| 6165 | options[opt_idx].def_val[VI_DEFAULT] = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | /* |
| 6169 | * Set the global value for 'iminsert' to the local value. |
| 6170 | */ |
| 6171 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6172 | set_iminsert_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6173 | { |
| 6174 | p_iminsert = curbuf->b_p_iminsert; |
| 6175 | } |
| 6176 | |
| 6177 | /* |
| 6178 | * Set the global value for 'imsearch' to the local value. |
| 6179 | */ |
| 6180 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6181 | set_imsearch_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6182 | { |
| 6183 | p_imsearch = curbuf->b_p_imsearch; |
| 6184 | } |
| 6185 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6186 | static int expand_option_idx = -1; |
| 6187 | static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; |
| 6188 | static int expand_option_flags = 0; |
| 6189 | |
| 6190 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6191 | set_context_in_set_cmd( |
| 6192 | expand_T *xp, |
| 6193 | char_u *arg, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6194 | int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6195 | { |
| 6196 | int nextchar; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6197 | long_u flags = 0; // init for GCC |
| 6198 | int opt_idx = 0; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6199 | char_u *p; |
| 6200 | char_u *s; |
| 6201 | int is_term_option = FALSE; |
| 6202 | int key; |
| 6203 | |
| 6204 | expand_option_flags = opt_flags; |
| 6205 | |
| 6206 | xp->xp_context = EXPAND_SETTINGS; |
| 6207 | if (*arg == NUL) |
| 6208 | { |
| 6209 | xp->xp_pattern = arg; |
| 6210 | return; |
| 6211 | } |
| 6212 | p = arg + STRLEN(arg) - 1; |
| 6213 | if (*p == ' ' && *(p - 1) != '\\') |
| 6214 | { |
| 6215 | xp->xp_pattern = p + 1; |
| 6216 | return; |
| 6217 | } |
| 6218 | while (p > arg) |
| 6219 | { |
| 6220 | s = p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6221 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6222 | if (*p == ' ' || *p == ',') |
| 6223 | { |
| 6224 | while (s > arg && *(s - 1) == '\\') |
| 6225 | --s; |
| 6226 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6227 | // break at a space with an even number of backslashes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6228 | if (*p == ' ' && ((p - s) & 1) == 0) |
| 6229 | { |
| 6230 | ++p; |
| 6231 | break; |
| 6232 | } |
| 6233 | --p; |
| 6234 | } |
Bram Moolenaar | 2a7b9ee | 2009-06-16 15:50:33 +0000 | [diff] [blame] | 6235 | if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6236 | { |
| 6237 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
| 6238 | p += 2; |
| 6239 | } |
| 6240 | if (STRNCMP(p, "inv", 3) == 0) |
| 6241 | { |
| 6242 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
| 6243 | p += 3; |
| 6244 | } |
| 6245 | xp->xp_pattern = arg = p; |
| 6246 | if (*arg == '<') |
| 6247 | { |
| 6248 | while (*p != '>') |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6249 | if (*p++ == NUL) // expand terminal option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6250 | return; |
| 6251 | key = get_special_key_code(arg + 1); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6252 | if (key == 0) // unknown name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6253 | { |
| 6254 | xp->xp_context = EXPAND_NOTHING; |
| 6255 | return; |
| 6256 | } |
| 6257 | nextchar = *++p; |
| 6258 | is_term_option = TRUE; |
| 6259 | expand_option_name[2] = KEY2TERMCAP0(key); |
| 6260 | expand_option_name[3] = KEY2TERMCAP1(key); |
| 6261 | } |
| 6262 | else |
| 6263 | { |
| 6264 | if (p[0] == 't' && p[1] == '_') |
| 6265 | { |
| 6266 | p += 2; |
| 6267 | if (*p != NUL) |
| 6268 | ++p; |
| 6269 | if (*p == NUL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6270 | return; // expand option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6271 | nextchar = *++p; |
| 6272 | is_term_option = TRUE; |
| 6273 | expand_option_name[2] = p[-2]; |
| 6274 | expand_option_name[3] = p[-1]; |
| 6275 | } |
| 6276 | else |
| 6277 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6278 | // Allow * wildcard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6279 | while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') |
| 6280 | p++; |
| 6281 | if (*p == NUL) |
| 6282 | return; |
| 6283 | nextchar = *p; |
| 6284 | *p = NUL; |
| 6285 | opt_idx = findoption(arg); |
| 6286 | *p = nextchar; |
| 6287 | if (opt_idx == -1 || options[opt_idx].var == NULL) |
| 6288 | { |
| 6289 | xp->xp_context = EXPAND_NOTHING; |
| 6290 | return; |
| 6291 | } |
| 6292 | flags = options[opt_idx].flags; |
| 6293 | if (flags & P_BOOL) |
| 6294 | { |
| 6295 | xp->xp_context = EXPAND_NOTHING; |
| 6296 | return; |
| 6297 | } |
| 6298 | } |
| 6299 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6300 | // handle "-=" and "+=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') |
| 6302 | { |
| 6303 | ++p; |
| 6304 | nextchar = '='; |
| 6305 | } |
| 6306 | if ((nextchar != '=' && nextchar != ':') |
| 6307 | || xp->xp_context == EXPAND_BOOL_SETTINGS) |
| 6308 | { |
| 6309 | xp->xp_context = EXPAND_UNSUCCESSFUL; |
| 6310 | return; |
| 6311 | } |
| 6312 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL) |
| 6313 | { |
| 6314 | xp->xp_context = EXPAND_OLD_SETTING; |
| 6315 | if (is_term_option) |
| 6316 | expand_option_idx = -1; |
| 6317 | else |
| 6318 | expand_option_idx = opt_idx; |
| 6319 | xp->xp_pattern = p + 1; |
| 6320 | return; |
| 6321 | } |
| 6322 | xp->xp_context = EXPAND_NOTHING; |
| 6323 | if (is_term_option || (flags & P_NUM)) |
| 6324 | return; |
| 6325 | |
| 6326 | xp->xp_pattern = p + 1; |
| 6327 | |
| 6328 | if (flags & P_EXPAND) |
| 6329 | { |
| 6330 | p = options[opt_idx].var; |
| 6331 | if (p == (char_u *)&p_bdir |
| 6332 | || p == (char_u *)&p_dir |
| 6333 | || p == (char_u *)&p_path |
Bram Moolenaar | f6fee0e | 2016-02-21 23:02:49 +0100 | [diff] [blame] | 6334 | || p == (char_u *)&p_pp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6335 | || p == (char_u *)&p_rtp |
| 6336 | #ifdef FEAT_SEARCHPATH |
| 6337 | || p == (char_u *)&p_cdpath |
| 6338 | #endif |
| 6339 | #ifdef FEAT_SESSION |
| 6340 | || p == (char_u *)&p_vdir |
| 6341 | #endif |
| 6342 | ) |
| 6343 | { |
| 6344 | xp->xp_context = EXPAND_DIRECTORIES; |
| 6345 | if (p == (char_u *)&p_path |
| 6346 | #ifdef FEAT_SEARCHPATH |
| 6347 | || p == (char_u *)&p_cdpath |
| 6348 | #endif |
| 6349 | ) |
| 6350 | xp->xp_backslash = XP_BS_THREE; |
| 6351 | else |
| 6352 | xp->xp_backslash = XP_BS_ONE; |
| 6353 | } |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 6354 | else if (p == (char_u *)&p_ft) |
| 6355 | { |
| 6356 | xp->xp_context = EXPAND_FILETYPE; |
| 6357 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6358 | else |
| 6359 | { |
| 6360 | xp->xp_context = EXPAND_FILES; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6361 | // for 'tags' need three backslashes for a space |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6362 | if (p == (char_u *)&p_tags) |
| 6363 | xp->xp_backslash = XP_BS_THREE; |
| 6364 | else |
| 6365 | xp->xp_backslash = XP_BS_ONE; |
| 6366 | } |
| 6367 | } |
| 6368 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6369 | // For an option that is a list of file names, find the start of the |
| 6370 | // last file name. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6371 | for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) |
| 6372 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6373 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6374 | if (*p == ' ' || *p == ',') |
| 6375 | { |
| 6376 | s = p; |
| 6377 | while (s > xp->xp_pattern && *(s - 1) == '\\') |
| 6378 | --s; |
| 6379 | if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) |
| 6380 | || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) |
| 6381 | { |
| 6382 | xp->xp_pattern = p + 1; |
| 6383 | break; |
| 6384 | } |
| 6385 | } |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 6386 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6387 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6388 | // for 'spellsuggest' start at "file:" |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 6389 | if (options[opt_idx].var == (char_u *)&p_sps |
| 6390 | && STRNCMP(p, "file:", 5) == 0) |
| 6391 | { |
| 6392 | xp->xp_pattern = p + 5; |
| 6393 | break; |
| 6394 | } |
| 6395 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6396 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
| 6399 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6400 | ExpandSettings( |
| 6401 | expand_T *xp, |
| 6402 | regmatch_T *regmatch, |
| 6403 | int *num_file, |
| 6404 | char_u ***file) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6405 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6406 | int num_normal = 0; // Nr of matching non-term-code settings |
| 6407 | int num_term = 0; // Nr of matching terminal code settings |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6408 | int opt_idx; |
| 6409 | int match; |
| 6410 | int count = 0; |
| 6411 | char_u *str; |
| 6412 | int loop; |
| 6413 | int is_term_opt; |
| 6414 | char_u name_buf[MAX_KEY_NAME_LEN]; |
| 6415 | static char *(names[]) = {"all", "termcap"}; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6416 | int ic = regmatch->rm_ic; // remember the ignore-case flag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6417 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6418 | // do this loop twice: |
| 6419 | // loop == 0: count the number of matching options |
| 6420 | // loop == 1: copy the matching options into allocated memory |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6421 | for (loop = 0; loop <= 1; ++loop) |
| 6422 | { |
| 6423 | regmatch->rm_ic = ic; |
| 6424 | if (xp->xp_context != EXPAND_BOOL_SETTINGS) |
| 6425 | { |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 6426 | for (match = 0; match < (int)ARRAY_LENGTH(names); ++match) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6427 | if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0)) |
| 6428 | { |
| 6429 | if (loop == 0) |
| 6430 | num_normal++; |
| 6431 | else |
| 6432 | (*file)[count++] = vim_strsave((char_u *)names[match]); |
| 6433 | } |
| 6434 | } |
| 6435 | for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; |
| 6436 | opt_idx++) |
| 6437 | { |
| 6438 | if (options[opt_idx].var == NULL) |
| 6439 | continue; |
| 6440 | if (xp->xp_context == EXPAND_BOOL_SETTINGS |
| 6441 | && !(options[opt_idx].flags & P_BOOL)) |
| 6442 | continue; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6443 | is_term_opt = istermoption_idx(opt_idx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6444 | if (is_term_opt && num_normal > 0) |
| 6445 | continue; |
| 6446 | match = FALSE; |
| 6447 | if (vim_regexec(regmatch, str, (colnr_T)0) |
| 6448 | || (options[opt_idx].shortname != NULL |
| 6449 | && vim_regexec(regmatch, |
| 6450 | (char_u *)options[opt_idx].shortname, (colnr_T)0))) |
| 6451 | match = TRUE; |
| 6452 | else if (is_term_opt) |
| 6453 | { |
| 6454 | name_buf[0] = '<'; |
| 6455 | name_buf[1] = 't'; |
| 6456 | name_buf[2] = '_'; |
| 6457 | name_buf[3] = str[2]; |
| 6458 | name_buf[4] = str[3]; |
| 6459 | name_buf[5] = '>'; |
| 6460 | name_buf[6] = NUL; |
| 6461 | if (vim_regexec(regmatch, name_buf, (colnr_T)0)) |
| 6462 | { |
| 6463 | match = TRUE; |
| 6464 | str = name_buf; |
| 6465 | } |
| 6466 | } |
| 6467 | if (match) |
| 6468 | { |
| 6469 | if (loop == 0) |
| 6470 | { |
| 6471 | if (is_term_opt) |
| 6472 | num_term++; |
| 6473 | else |
| 6474 | num_normal++; |
| 6475 | } |
| 6476 | else |
| 6477 | (*file)[count++] = vim_strsave(str); |
| 6478 | } |
| 6479 | } |
| 6480 | /* |
| 6481 | * Check terminal key codes, these are not in the option table |
| 6482 | */ |
| 6483 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) |
| 6484 | { |
| 6485 | for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) |
| 6486 | { |
| 6487 | if (!isprint(str[0]) || !isprint(str[1])) |
| 6488 | continue; |
| 6489 | |
| 6490 | name_buf[0] = 't'; |
| 6491 | name_buf[1] = '_'; |
| 6492 | name_buf[2] = str[0]; |
| 6493 | name_buf[3] = str[1]; |
| 6494 | name_buf[4] = NUL; |
| 6495 | |
| 6496 | match = FALSE; |
| 6497 | if (vim_regexec(regmatch, name_buf, (colnr_T)0)) |
| 6498 | match = TRUE; |
| 6499 | else |
| 6500 | { |
| 6501 | name_buf[0] = '<'; |
| 6502 | name_buf[1] = 't'; |
| 6503 | name_buf[2] = '_'; |
| 6504 | name_buf[3] = str[0]; |
| 6505 | name_buf[4] = str[1]; |
| 6506 | name_buf[5] = '>'; |
| 6507 | name_buf[6] = NUL; |
| 6508 | |
| 6509 | if (vim_regexec(regmatch, name_buf, (colnr_T)0)) |
| 6510 | match = TRUE; |
| 6511 | } |
| 6512 | if (match) |
| 6513 | { |
| 6514 | if (loop == 0) |
| 6515 | num_term++; |
| 6516 | else |
| 6517 | (*file)[count++] = vim_strsave(name_buf); |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | /* |
| 6522 | * Check special key names. |
| 6523 | */ |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6524 | regmatch->rm_ic = TRUE; // ignore case here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6525 | for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) |
| 6526 | { |
| 6527 | name_buf[0] = '<'; |
| 6528 | STRCPY(name_buf + 1, str); |
| 6529 | STRCAT(name_buf, ">"); |
| 6530 | |
| 6531 | if (vim_regexec(regmatch, name_buf, (colnr_T)0)) |
| 6532 | { |
| 6533 | if (loop == 0) |
| 6534 | num_term++; |
| 6535 | else |
| 6536 | (*file)[count++] = vim_strsave(name_buf); |
| 6537 | } |
| 6538 | } |
| 6539 | } |
| 6540 | if (loop == 0) |
| 6541 | { |
| 6542 | if (num_normal > 0) |
| 6543 | *num_file = num_normal; |
| 6544 | else if (num_term > 0) |
| 6545 | *num_file = num_term; |
| 6546 | else |
| 6547 | return OK; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6548 | *file = ALLOC_MULT(char_u *, *num_file); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6549 | if (*file == NULL) |
| 6550 | { |
| 6551 | *file = (char_u **)""; |
| 6552 | return FAIL; |
| 6553 | } |
| 6554 | } |
| 6555 | } |
| 6556 | return OK; |
| 6557 | } |
| 6558 | |
| 6559 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6560 | ExpandOldSetting(int *num_file, char_u ***file) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6561 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6562 | char_u *var = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6563 | char_u *buf; |
| 6564 | |
| 6565 | *num_file = 0; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6566 | *file = ALLOC_ONE(char_u *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6567 | if (*file == NULL) |
| 6568 | return FAIL; |
| 6569 | |
| 6570 | /* |
| 6571 | * For a terminal key code expand_option_idx is < 0. |
| 6572 | */ |
| 6573 | if (expand_option_idx < 0) |
| 6574 | { |
| 6575 | var = find_termcode(expand_option_name + 2); |
| 6576 | if (var == NULL) |
| 6577 | expand_option_idx = findoption(expand_option_name); |
| 6578 | } |
| 6579 | |
| 6580 | if (expand_option_idx >= 0) |
| 6581 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6582 | // put string of option value in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6583 | option_value2string(&options[expand_option_idx], expand_option_flags); |
| 6584 | var = NameBuff; |
| 6585 | } |
| 6586 | else if (var == NULL) |
| 6587 | var = (char_u *)""; |
| 6588 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6589 | // A backslash is required before some characters. This is the reverse of |
| 6590 | // what happens in do_set(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6591 | buf = vim_strsave_escaped(var, escape_chars); |
| 6592 | |
| 6593 | if (buf == NULL) |
| 6594 | { |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 6595 | VIM_CLEAR(*file); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6596 | return FAIL; |
| 6597 | } |
| 6598 | |
| 6599 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6600 | // For MS-Windows et al. we don't double backslashes at the start and |
| 6601 | // before a file name character. |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 6602 | for (var = buf; *var != NUL; MB_PTR_ADV(var)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6603 | if (var[0] == '\\' && var[1] == '\\' |
| 6604 | && expand_option_idx >= 0 |
| 6605 | && (options[expand_option_idx].flags & P_EXPAND) |
| 6606 | && vim_isfilec(var[2]) |
| 6607 | && (var[2] != '\\' || (var == buf && var[4] != '\\'))) |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 6608 | STRMOVE(var, var + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6609 | #endif |
| 6610 | |
| 6611 | *file[0] = buf; |
| 6612 | *num_file = 1; |
| 6613 | return OK; |
| 6614 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6615 | |
| 6616 | /* |
| 6617 | * Get the value for the numeric or string option *opp in a nice format into |
| 6618 | * NameBuff[]. Must not be called with a hidden option! |
| 6619 | */ |
| 6620 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6621 | option_value2string( |
| 6622 | struct vimoption *opp, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6623 | int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6624 | { |
| 6625 | char_u *varp; |
| 6626 | |
| 6627 | varp = get_varp_scope(opp, opt_flags); |
| 6628 | |
| 6629 | if (opp->flags & P_NUM) |
| 6630 | { |
| 6631 | long wc = 0; |
| 6632 | |
| 6633 | if (wc_use_keyname(varp, &wc)) |
| 6634 | STRCPY(NameBuff, get_special_key_name((int)wc, 0)); |
| 6635 | else if (wc != 0) |
| 6636 | STRCPY(NameBuff, transchar((int)wc)); |
| 6637 | else |
| 6638 | sprintf((char *)NameBuff, "%ld", *(long *)varp); |
| 6639 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6640 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6641 | { |
| 6642 | varp = *(char_u **)(varp); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6643 | if (varp == NULL) // just in case |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6644 | NameBuff[0] = NUL; |
| 6645 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6646 | // don't show the actual value of 'key', only that it's set |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 6647 | else if (opp->var == (char_u *)&p_key && *varp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | STRCPY(NameBuff, "*****"); |
| 6649 | #endif |
| 6650 | else if (opp->flags & P_EXPAND) |
| 6651 | home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6652 | // Translate 'pastetoggle' into special key names |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6653 | else if ((char_u **)opp->var == &p_pt) |
| 6654 | str2specialbuf(p_pt, NameBuff, MAXPATHL); |
| 6655 | else |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 6656 | vim_strncpy(NameBuff, varp, MAXPATHL - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | /* |
| 6661 | * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be |
| 6662 | * printed as a keyname. |
| 6663 | * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. |
| 6664 | */ |
| 6665 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6666 | wc_use_keyname(char_u *varp, long *wcp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6667 | { |
| 6668 | if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) |
| 6669 | { |
| 6670 | *wcp = *(long *)varp; |
| 6671 | if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) |
| 6672 | return TRUE; |
| 6673 | } |
| 6674 | return FALSE; |
| 6675 | } |
| 6676 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6677 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6678 | * Return TRUE if "x" is present in 'shortmess' option, or |
| 6679 | * 'shortmess' contains 'a' and "x" is present in SHM_A. |
| 6680 | */ |
| 6681 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6682 | shortmess(int x) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6683 | { |
Bram Moolenaar | 7f29f7a | 2012-02-29 13:51:37 +0100 | [diff] [blame] | 6684 | return p_shm != NULL && |
| 6685 | ( vim_strchr(p_shm, x) != NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6686 | || (vim_strchr(p_shm, 'a') != NULL |
| 6687 | && vim_strchr((char_u *)SHM_A, x) != NULL)); |
| 6688 | } |
| 6689 | |
| 6690 | /* |
| 6691 | * paste_option_changed() - Called after p_paste was set or reset. |
| 6692 | */ |
| 6693 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6694 | paste_option_changed(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6695 | { |
| 6696 | static int old_p_paste = FALSE; |
| 6697 | static int save_sm = 0; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6698 | static int save_sta = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6699 | #ifdef FEAT_CMDL_INFO |
| 6700 | static int save_ru = 0; |
| 6701 | #endif |
| 6702 | #ifdef FEAT_RIGHTLEFT |
| 6703 | static int save_ri = 0; |
| 6704 | static int save_hkmap = 0; |
| 6705 | #endif |
| 6706 | buf_T *buf; |
| 6707 | |
| 6708 | if (p_paste) |
| 6709 | { |
| 6710 | /* |
| 6711 | * Paste switched from off to on. |
| 6712 | * Save the current values, so they can be restored later. |
| 6713 | */ |
| 6714 | if (!old_p_paste) |
| 6715 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6716 | // save options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6717 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6718 | { |
| 6719 | buf->b_p_tw_nopaste = buf->b_p_tw; |
| 6720 | buf->b_p_wm_nopaste = buf->b_p_wm; |
| 6721 | buf->b_p_sts_nopaste = buf->b_p_sts; |
| 6722 | buf->b_p_ai_nopaste = buf->b_p_ai; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6723 | buf->b_p_et_nopaste = buf->b_p_et; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6724 | #ifdef FEAT_VARTABS |
| 6725 | if (buf->b_p_vsts_nopaste) |
| 6726 | vim_free(buf->b_p_vsts_nopaste); |
| 6727 | buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option |
| 6728 | ? vim_strsave(buf->b_p_vsts) : NULL; |
| 6729 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6732 | // save global options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6733 | save_sm = p_sm; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6734 | save_sta = p_sta; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6735 | #ifdef FEAT_CMDL_INFO |
| 6736 | save_ru = p_ru; |
| 6737 | #endif |
| 6738 | #ifdef FEAT_RIGHTLEFT |
| 6739 | save_ri = p_ri; |
| 6740 | save_hkmap = p_hkmap; |
| 6741 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6742 | // save global values for local buffer options |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6743 | p_ai_nopaste = p_ai; |
| 6744 | p_et_nopaste = p_et; |
| 6745 | p_sts_nopaste = p_sts; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6746 | p_tw_nopaste = p_tw; |
| 6747 | p_wm_nopaste = p_wm; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6748 | #ifdef FEAT_VARTABS |
| 6749 | if (p_vsts_nopaste) |
| 6750 | vim_free(p_vsts_nopaste); |
| 6751 | p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL; |
| 6752 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6753 | } |
| 6754 | |
| 6755 | /* |
| 6756 | * Always set the option values, also when 'paste' is set when it is |
| 6757 | * already on. |
| 6758 | */ |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6759 | // set options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6760 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6761 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6762 | buf->b_p_tw = 0; // textwidth is 0 |
| 6763 | buf->b_p_wm = 0; // wrapmargin is 0 |
| 6764 | buf->b_p_sts = 0; // softtabstop is 0 |
| 6765 | buf->b_p_ai = 0; // no auto-indent |
| 6766 | buf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6767 | #ifdef FEAT_VARTABS |
| 6768 | if (buf->b_p_vsts) |
| 6769 | free_string_option(buf->b_p_vsts); |
| 6770 | buf->b_p_vsts = empty_option; |
| 6771 | if (buf->b_p_vsts_array) |
| 6772 | vim_free(buf->b_p_vsts_array); |
| 6773 | buf->b_p_vsts_array = 0; |
| 6774 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6775 | } |
| 6776 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6777 | // set global options |
| 6778 | p_sm = 0; // no showmatch |
| 6779 | p_sta = 0; // no smarttab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6780 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6781 | if (p_ru) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6782 | status_redraw_all(); // redraw to remove the ruler |
| 6783 | p_ru = 0; // no ruler |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6784 | #endif |
| 6785 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6786 | p_ri = 0; // no reverse insert |
| 6787 | p_hkmap = 0; // no Hebrew keyboard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6788 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6789 | // set global values for local buffer options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6790 | p_tw = 0; |
| 6791 | p_wm = 0; |
| 6792 | p_sts = 0; |
| 6793 | p_ai = 0; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6794 | #ifdef FEAT_VARTABS |
| 6795 | if (p_vsts) |
| 6796 | free_string_option(p_vsts); |
| 6797 | p_vsts = empty_option; |
| 6798 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6799 | } |
| 6800 | |
| 6801 | /* |
| 6802 | * Paste switched from on to off: Restore saved values. |
| 6803 | */ |
| 6804 | else if (old_p_paste) |
| 6805 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6806 | // restore options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6807 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6808 | { |
| 6809 | buf->b_p_tw = buf->b_p_tw_nopaste; |
| 6810 | buf->b_p_wm = buf->b_p_wm_nopaste; |
| 6811 | buf->b_p_sts = buf->b_p_sts_nopaste; |
| 6812 | buf->b_p_ai = buf->b_p_ai_nopaste; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6813 | buf->b_p_et = buf->b_p_et_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6814 | #ifdef FEAT_VARTABS |
| 6815 | if (buf->b_p_vsts) |
| 6816 | free_string_option(buf->b_p_vsts); |
| 6817 | buf->b_p_vsts = buf->b_p_vsts_nopaste |
| 6818 | ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option; |
| 6819 | if (buf->b_p_vsts_array) |
| 6820 | vim_free(buf->b_p_vsts_array); |
| 6821 | if (buf->b_p_vsts && buf->b_p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 6822 | (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6823 | else |
| 6824 | buf->b_p_vsts_array = 0; |
| 6825 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6828 | // restore global options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6829 | p_sm = save_sm; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6830 | p_sta = save_sta; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6831 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6832 | if (p_ru != save_ru) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6833 | status_redraw_all(); // redraw to draw the ruler |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6834 | p_ru = save_ru; |
| 6835 | #endif |
| 6836 | #ifdef FEAT_RIGHTLEFT |
| 6837 | p_ri = save_ri; |
| 6838 | p_hkmap = save_hkmap; |
| 6839 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6840 | // set global values for local buffer options |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6841 | p_ai = p_ai_nopaste; |
| 6842 | p_et = p_et_nopaste; |
| 6843 | p_sts = p_sts_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6844 | p_tw = p_tw_nopaste; |
| 6845 | p_wm = p_wm_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6846 | #ifdef FEAT_VARTABS |
| 6847 | if (p_vsts) |
| 6848 | free_string_option(p_vsts); |
| 6849 | p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; |
| 6850 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | old_p_paste = p_paste; |
| 6854 | } |
| 6855 | |
| 6856 | /* |
| 6857 | * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. |
| 6858 | * |
| 6859 | * Reset 'compatible' and set the values for options that didn't get set yet |
| 6860 | * to the Vim defaults. |
| 6861 | * Don't do this if the 'compatible' option has been set or reset before. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6862 | * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6863 | */ |
| 6864 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6865 | vimrc_found(char_u *fname, char_u *envname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6866 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6867 | int opt_idx; |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 6868 | int dofree = FALSE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6869 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6870 | |
| 6871 | if (!option_was_set((char_u *)"cp")) |
| 6872 | { |
| 6873 | p_cp = FALSE; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6874 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6875 | if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) |
| 6876 | set_option_default(opt_idx, OPT_FREE, FALSE); |
| 6877 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 6878 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6879 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6880 | |
| 6881 | if (fname != NULL) |
| 6882 | { |
| 6883 | p = vim_getenv(envname, &dofree); |
| 6884 | if (p == NULL) |
| 6885 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6886 | // Set $MYVIMRC to the first vimrc file found. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6887 | p = FullName_save(fname, FALSE); |
| 6888 | if (p != NULL) |
| 6889 | { |
| 6890 | vim_setenv(envname, p); |
| 6891 | vim_free(p); |
| 6892 | } |
| 6893 | } |
| 6894 | else if (dofree) |
| 6895 | vim_free(p); |
| 6896 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6897 | } |
| 6898 | |
| 6899 | /* |
| 6900 | * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. |
| 6901 | */ |
| 6902 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6903 | change_compatible(int on) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6904 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 6905 | int opt_idx; |
| 6906 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6907 | if (p_cp != on) |
| 6908 | { |
| 6909 | p_cp = on; |
| 6910 | compatible_set(); |
| 6911 | } |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 6912 | opt_idx = findoption((char_u *)"cp"); |
| 6913 | if (opt_idx >= 0) |
| 6914 | options[opt_idx].flags |= P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | /* |
| 6918 | * Return TRUE when option "name" has been set. |
Bram Moolenaar | 1a4a75c | 2013-07-28 16:03:06 +0200 | [diff] [blame] | 6919 | * Only works correctly for global options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6920 | */ |
| 6921 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6922 | option_was_set(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6923 | { |
| 6924 | int idx; |
| 6925 | |
| 6926 | idx = findoption(name); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6927 | if (idx < 0) // unknown option |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6928 | return FALSE; |
| 6929 | if (options[idx].flags & P_WAS_SET) |
| 6930 | return TRUE; |
| 6931 | return FALSE; |
| 6932 | } |
| 6933 | |
| 6934 | /* |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 6935 | * Reset the flag indicating option "name" was set. |
| 6936 | */ |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 6937 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6938 | reset_option_was_set(char_u *name) |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 6939 | { |
| 6940 | int idx = findoption(name); |
| 6941 | |
| 6942 | if (idx >= 0) |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 6943 | { |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 6944 | options[idx].flags &= ~P_WAS_SET; |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 6945 | return OK; |
| 6946 | } |
| 6947 | return FAIL; |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6951 | * compatible_set() - Called when 'compatible' has been set or unset. |
| 6952 | * |
| 6953 | * When 'compatible' set: Set all relevant options (those that have the P_VIM) |
| 6954 | * flag) to a Vi compatible value. |
| 6955 | * When 'compatible' is unset: Set all options that have a different default |
| 6956 | * for Vim (without the P_VI_DEF flag) to that default. |
| 6957 | */ |
| 6958 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6959 | compatible_set(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6960 | { |
| 6961 | int opt_idx; |
| 6962 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6963 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6964 | if ( ((options[opt_idx].flags & P_VIM) && p_cp) |
| 6965 | || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) |
| 6966 | set_option_default(opt_idx, OPT_FREE, p_cp); |
| 6967 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 6968 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6969 | } |
| 6970 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6971 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6972 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6973 | /* |
| 6974 | * fill_breakat_flags() -- called when 'breakat' changes value. |
| 6975 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6976 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6977 | fill_breakat_flags(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6978 | { |
Bram Moolenaar | ac6e65f | 2005-08-29 22:25:38 +0000 | [diff] [blame] | 6979 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6980 | int i; |
| 6981 | |
| 6982 | for (i = 0; i < 256; i++) |
| 6983 | breakat_flags[i] = FALSE; |
| 6984 | |
| 6985 | if (p_breakat != NULL) |
Bram Moolenaar | ac6e65f | 2005-08-29 22:25:38 +0000 | [diff] [blame] | 6986 | for (p = p_breakat; *p; p++) |
| 6987 | breakat_flags[*p] = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6988 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6989 | #endif |
| 6990 | |
| 6991 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6992 | * Check if backspacing over something is allowed. |
| 6993 | */ |
| 6994 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6995 | can_bs( |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 6996 | int what) // BS_INDENT, BS_EOL, BS_START or BS_NOSTOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6997 | { |
Bram Moolenaar | 6b810d9 | 2018-06-04 17:28:44 +0200 | [diff] [blame] | 6998 | #ifdef FEAT_JOB_CHANNEL |
| 6999 | if (what == BS_START && bt_prompt(curbuf)) |
| 7000 | return FALSE; |
| 7001 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7002 | switch (*p_bs) |
| 7003 | { |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 7004 | case '3': return TRUE; |
| 7005 | case '2': return (what != BS_NOSTOP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7006 | case '1': return (what != BS_START); |
| 7007 | case '0': return FALSE; |
| 7008 | } |
| 7009 | return vim_strchr(p_bs, what) != NULL; |
| 7010 | } |
| 7011 | |
| 7012 | /* |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 7013 | * Return the effective 'scrolloff' value for the current window, using the |
| 7014 | * global value when appropriate. |
| 7015 | */ |
| 7016 | long |
| 7017 | get_scrolloff_value(void) |
| 7018 | { |
| 7019 | return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; |
| 7020 | } |
| 7021 | |
| 7022 | /* |
| 7023 | * Return the effective 'sidescrolloff' value for the current window, using the |
| 7024 | * global value when appropriate. |
| 7025 | */ |
| 7026 | long |
| 7027 | get_sidescrolloff_value(void) |
| 7028 | { |
| 7029 | return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; |
| 7030 | } |
| 7031 | |
| 7032 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7033 | * Get the local or global value of 'backupcopy'. |
| 7034 | */ |
| 7035 | unsigned int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7036 | get_bkc_value(buf_T *buf) |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7037 | { |
| 7038 | return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; |
| 7039 | } |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 7040 | |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 7041 | /* |
| 7042 | * Get the local or global value of the 'virtualedit' flags. |
| 7043 | */ |
| 7044 | unsigned int |
| 7045 | get_ve_flags(void) |
| 7046 | { |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 7047 | return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) |
| 7048 | & ~(VE_NONE | VE_NONEU); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 7049 | } |
| 7050 | |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 7051 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 7052 | /* |
| 7053 | * Get the local or global value of 'showbreak'. |
| 7054 | */ |
| 7055 | char_u * |
| 7056 | get_showbreak_value(win_T *win) |
| 7057 | { |
| 7058 | if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) |
| 7059 | return p_sbr; |
| 7060 | if (STRCMP(win->w_p_sbr, "NONE") == 0) |
| 7061 | return empty_option; |
| 7062 | return win->w_p_sbr; |
| 7063 | } |
| 7064 | #endif |
| 7065 | |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 7066 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 7067 | /* |
| 7068 | * Get window or buffer local options. |
| 7069 | */ |
| 7070 | dict_T * |
| 7071 | get_winbuf_options(int bufopt) |
| 7072 | { |
| 7073 | dict_T *d; |
| 7074 | int opt_idx; |
| 7075 | |
| 7076 | d = dict_alloc(); |
| 7077 | if (d == NULL) |
| 7078 | return NULL; |
| 7079 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7080 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 7081 | { |
| 7082 | struct vimoption *opt = &options[opt_idx]; |
| 7083 | |
| 7084 | if ((bufopt && (opt->indir & PV_BUF)) |
| 7085 | || (!bufopt && (opt->indir & PV_WIN))) |
| 7086 | { |
| 7087 | char_u *varp = get_varp(opt); |
| 7088 | |
| 7089 | if (varp != NULL) |
| 7090 | { |
| 7091 | if (opt->flags & P_STRING) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 7092 | dict_add_string(d, opt->fullname, *(char_u **)varp); |
Bram Moolenaar | 789a5c0 | 2016-09-12 19:51:11 +0200 | [diff] [blame] | 7093 | else if (opt->flags & P_NUM) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 7094 | dict_add_number(d, opt->fullname, *(long *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 7095 | else |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 7096 | dict_add_number(d, opt->fullname, *(int *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 7097 | } |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | return d; |
| 7102 | } |
| 7103 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 7104 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7105 | #if defined(FEAT_SYN_HL) || defined(PROTO) |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 7106 | /* |
| 7107 | * This is called when 'culopt' is changed |
| 7108 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7109 | int |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 7110 | fill_culopt_flags(char_u *val, win_T *wp) |
| 7111 | { |
| 7112 | char_u *p; |
| 7113 | char_u culopt_flags_new = 0; |
| 7114 | |
| 7115 | if (val == NULL) |
| 7116 | p = wp->w_p_culopt; |
| 7117 | else |
| 7118 | p = val; |
| 7119 | while (*p != NUL) |
| 7120 | { |
| 7121 | if (STRNCMP(p, "line", 4) == 0) |
| 7122 | { |
| 7123 | p += 4; |
| 7124 | culopt_flags_new |= CULOPT_LINE; |
| 7125 | } |
| 7126 | else if (STRNCMP(p, "both", 4) == 0) |
| 7127 | { |
| 7128 | p += 4; |
| 7129 | culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; |
| 7130 | } |
| 7131 | else if (STRNCMP(p, "number", 6) == 0) |
| 7132 | { |
| 7133 | p += 6; |
| 7134 | culopt_flags_new |= CULOPT_NBR; |
| 7135 | } |
| 7136 | else if (STRNCMP(p, "screenline", 10) == 0) |
| 7137 | { |
| 7138 | p += 10; |
| 7139 | culopt_flags_new |= CULOPT_SCRLINE; |
| 7140 | } |
| 7141 | |
| 7142 | if (*p != ',' && *p != NUL) |
| 7143 | return FAIL; |
| 7144 | if (*p == ',') |
| 7145 | ++p; |
| 7146 | } |
| 7147 | |
| 7148 | // Can't have both "line" and "screenline". |
| 7149 | if ((culopt_flags_new & CULOPT_LINE) && (culopt_flags_new & CULOPT_SCRLINE)) |
| 7150 | return FAIL; |
| 7151 | wp->w_p_culopt_flags = culopt_flags_new; |
| 7152 | |
| 7153 | return OK; |
| 7154 | } |
| 7155 | #endif |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 7156 | |
| 7157 | /* |
| 7158 | * Get the value of 'magic' adjusted for Vim9 script. |
| 7159 | */ |
| 7160 | int |
| 7161 | magic_isset(void) |
| 7162 | { |
| 7163 | switch (magic_overruled) |
| 7164 | { |
Bram Moolenaar | d93a7fc | 2021-01-04 12:42:13 +0100 | [diff] [blame] | 7165 | case OPTION_MAGIC_ON: return TRUE; |
| 7166 | case OPTION_MAGIC_OFF: return FALSE; |
| 7167 | case OPTION_MAGIC_NOT_SET: break; |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 7168 | } |
| 7169 | #ifdef FEAT_EVAL |
| 7170 | if (in_vim9script()) |
| 7171 | return TRUE; |
| 7172 | #endif |
| 7173 | return p_magic; |
| 7174 | } |