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: |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 13 | * - Put it in the options array in optiondefs.h (copy an existing entry). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | * - For a global option: Add a variable for it in option.h. |
| 15 | * - For a buffer or window local option: |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 16 | * - Add a PV_XX macro definition to the optiondefs.h file. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | * - Add a variable to the window or buffer struct in structs.h. |
| 18 | * - For a window option, add some code to copy_winopt(). |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 19 | * - For a window string option, add code to check_win_options() and |
| 20 | * clear_winopt(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | * - For a buffer option, add some code to buf_copy_options(). |
| 22 | * - For a buffer string option, add code to check_buf_options(). |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 23 | * - If it's a numeric option, add any necessary bounds checks to |
| 24 | * set_num_option(). |
| 25 | * - If it's a list of flags, add some code in did_set_string_option(), search |
| 26 | * for WW_ALL. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 27 | * - When adding an option with expansion (P_EXPAND), but with a different |
| 28 | * 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] | 29 | * - Add documentation! One line in doc/quickref.txt, full description in |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | * options.txt, and any other related places. |
| 31 | * - Add an entry in runtime/optwin.vim. |
| 32 | * When making changes: |
| 33 | * - Adjust the help for the option in doc/option.txt. |
| 34 | * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a |
| 35 | * comment at the help for the 'compatible' option. |
| 36 | */ |
| 37 | |
| 38 | #define IN_OPTION_C |
| 39 | #include "vim.h" |
Bram Moolenaar | 0eddca4 | 2019-09-12 22:26:43 +0200 | [diff] [blame] | 40 | #include "optiondefs.h" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 42 | static void set_options_default(int opt_flags); |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 43 | 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] | 44 | 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] | 45 | static char_u *option_expand(int opt_idx, char_u *val); |
| 46 | static void didset_options(void); |
| 47 | static void didset_options2(void); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 48 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 49 | static long_u *insecure_flag(int opt_idx, int opt_flags); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 50 | #else |
| 51 | # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags) |
| 52 | #endif |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 53 | static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); |
| 54 | 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] | 55 | static int find_key_option(char_u *arg_arg, int has_lt); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 56 | static void showoptions(int all, int opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 57 | static int optval_default(struct vimoption *, char_u *varp, int compatible); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 58 | static void showoneopt(struct vimoption *, int opt_flags); |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 59 | 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] | 60 | static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); |
| 61 | static int put_setbool(FILE *fd, char *cmd, char *name, int value); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 62 | static int istermoption(struct vimoption *p); |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 63 | static char_u *get_varp_scope(struct vimoption *p, int scope); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 64 | static char_u *get_varp(struct vimoption *); |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 65 | static void check_win_options(win_T *win); |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 66 | static void option_value2string(struct vimoption *, int scope); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 67 | static void check_winopt(winopt_T *wop); |
| 68 | static int wc_use_keyname(char_u *varp, long *wcp); |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 69 | static void paste_option_changed(void); |
| 70 | static void compatible_set(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 71 | |
| 72 | /* |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 73 | * Initialize the 'shell' option to a default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | */ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 75 | static void |
| 76 | set_init_default_shell(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 77 | { |
| 78 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 80 | // Find default value for 'shell' option. |
| 81 | // Don't use it if it is empty. |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 82 | if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 83 | #if defined(MSWIN) |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 84 | || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) |
Bram Moolenaar | 6aa2cd4 | 2016-02-16 15:06:59 +0100 | [diff] [blame] | 85 | || ((p = (char_u *)default_shell()) != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 86 | #endif |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 87 | ) |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 88 | #if defined(MSWIN) |
| 89 | { |
| 90 | // For MS-Windows put the path in quotes instead of escaping spaces. |
| 91 | char_u *cmd; |
| 92 | size_t len; |
| 93 | |
| 94 | if (vim_strchr(p, ' ') != NULL) |
| 95 | { |
| 96 | len = STRLEN(p) + 3; // two quotes and a trailing NUL |
| 97 | cmd = alloc(len); |
Bram Moolenaar | 1671de3 | 2019-10-05 21:35:16 +0200 | [diff] [blame] | 98 | if (cmd != NULL) |
| 99 | { |
| 100 | vim_snprintf((char *)cmd, len, "\"%s\"", p); |
| 101 | set_string_default("sh", cmd); |
| 102 | vim_free(cmd); |
| 103 | } |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 104 | } |
| 105 | else |
| 106 | set_string_default("sh", p); |
| 107 | } |
| 108 | #else |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 109 | set_string_default_esc("sh", p, TRUE); |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 110 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 111 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 112 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 113 | /* |
| 114 | * Set the default for 'backupskip' to include environment variables for |
| 115 | * temp files. |
| 116 | */ |
| 117 | static void |
| 118 | set_init_default_backupskip(void) |
| 119 | { |
| 120 | int opt_idx; |
| 121 | long_u n; |
| 122 | char_u *p; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 123 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 124 | static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 125 | #else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 126 | static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 127 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 128 | int len; |
| 129 | garray_T ga; |
| 130 | int mustfree; |
| 131 | char_u *item; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 132 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 133 | opt_idx = findoption((char_u *)"backupskip"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 135 | ga_init2(&ga, 1, 100); |
| 136 | for (n = 0; n < (long)ARRAY_LENGTH(names); ++n) |
| 137 | { |
| 138 | mustfree = FALSE; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 139 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 140 | if (*names[n] == NUL) |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 141 | # ifdef MACOS_X |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 142 | p = (char_u *)"/private/tmp"; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 143 | # else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 144 | p = (char_u *)"/tmp"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 145 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 146 | else |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 147 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 148 | p = vim_getenv((char_u *)names[n], &mustfree); |
| 149 | if (p != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 151 | // First time count the NUL, otherwise count the ','. |
| 152 | len = (int)STRLEN(p) + 3; |
| 153 | item = alloc(len); |
| 154 | STRCPY(item, p); |
| 155 | add_pathsep(item); |
| 156 | STRCAT(item, "*"); |
| 157 | if (find_dup_item(ga.ga_data, item, options[opt_idx].flags) |
| 158 | == NULL |
| 159 | && ga_grow(&ga, len) == OK) |
| 160 | { |
| 161 | if (ga.ga_len > 0) |
| 162 | STRCAT(ga.ga_data, ","); |
| 163 | STRCAT(ga.ga_data, item); |
| 164 | ga.ga_len += len; |
| 165 | } |
| 166 | vim_free(item); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 167 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 168 | if (mustfree) |
| 169 | vim_free(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 171 | if (ga.ga_data != NULL) |
| 172 | { |
| 173 | set_string_default("bsk", ga.ga_data); |
| 174 | vim_free(ga.ga_data); |
| 175 | } |
| 176 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 177 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 178 | /* |
| 179 | * Initialize the 'maxmemtot' and 'maxmem' options to a default value. |
| 180 | * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory. |
| 181 | */ |
| 182 | static void |
| 183 | set_init_default_maxmemtot(void) |
| 184 | { |
| 185 | int opt_idx; |
| 186 | long_u n; |
| 187 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 188 | opt_idx = findoption((char_u *)"maxmemtot"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 189 | if (opt_idx < 0) |
| 190 | return; |
| 191 | |
| 192 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
| 193 | if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) |
| 194 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 195 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 196 | #if defined(HAVE_AVAIL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 197 | // Use amount of memory available at this moment. |
| 198 | n = (mch_avail_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 199 | #elif defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 200 | // Use amount of memory available to Vim. |
| 201 | n = (mch_total_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 202 | #else |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 203 | n = (0x7fffffff >> 11); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 204 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 205 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
| 206 | opt_idx = findoption((char_u *)"maxmem"); |
| 207 | if (opt_idx >= 0) |
| 208 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 209 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 210 | if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n |
| 211 | || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L) |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 212 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 213 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 214 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 215 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 216 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 217 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 218 | /* |
| 219 | * Initialize the 'cdpath' option to a default value. |
| 220 | */ |
| 221 | static void |
| 222 | set_init_default_cdpath(void) |
| 223 | { |
| 224 | int opt_idx; |
| 225 | char_u *cdpath; |
| 226 | char_u *buf; |
| 227 | int i; |
| 228 | int j; |
| 229 | int mustfree = FALSE; |
| 230 | |
| 231 | cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); |
| 232 | if (cdpath == NULL) |
| 233 | return; |
| 234 | |
| 235 | buf = alloc((STRLEN(cdpath) << 1) + 2); |
| 236 | if (buf != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 237 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 238 | buf[0] = ','; // start with ",", current dir first |
| 239 | j = 1; |
| 240 | for (i = 0; cdpath[i] != NUL; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 241 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 242 | if (vim_ispathlistsep(cdpath[i])) |
| 243 | buf[j++] = ','; |
| 244 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 245 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 246 | if (cdpath[i] == ' ' || cdpath[i] == ',') |
| 247 | buf[j++] = '\\'; |
| 248 | buf[j++] = cdpath[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 251 | buf[j] = NUL; |
| 252 | opt_idx = findoption((char_u *)"cdpath"); |
| 253 | if (opt_idx >= 0) |
| 254 | { |
| 255 | options[opt_idx].def_val[VI_DEFAULT] = buf; |
| 256 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 257 | } |
| 258 | else |
| 259 | vim_free(buf); // cannot happen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 260 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 261 | if (mustfree) |
| 262 | vim_free(cdpath); |
| 263 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 264 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 265 | /* |
| 266 | * Initialize the 'printencoding' option to a default value. |
| 267 | */ |
| 268 | static void |
| 269 | set_init_default_printencoding(void) |
| 270 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 271 | #if defined(FEAT_POSTSCRIPT) && \ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 272 | (defined(MSWIN) || defined(VMS) || defined(MAC) || defined(hpux)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 273 | // Set print encoding on platforms that don't default to latin1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 274 | set_string_default("penc", |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 275 | # if defined(MSWIN) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 276 | (char_u *)"cp1252" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 277 | # elif defined(VMS) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 278 | (char_u *)"dec-mcs" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 279 | # elif defined(MAC) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 280 | (char_u *)"mac-roman" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 281 | # else // HPUX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 282 | (char_u *)"hp-roman8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 283 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 284 | ); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 285 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 286 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 287 | |
| 288 | #ifdef FEAT_POSTSCRIPT |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 289 | /* |
| 290 | * Initialize the 'printexpr' option to a default value. |
| 291 | */ |
| 292 | static void |
| 293 | set_init_default_printexpr(void) |
| 294 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 295 | // 'printexpr' must be allocated to be able to evaluate it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 296 | set_string_default("pexpr", |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 297 | # if defined(MSWIN) |
Bram Moolenaar | ed20346 | 2004-06-16 11:19:22 +0000 | [diff] [blame] | 298 | (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 299 | # elif defined(VMS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 300 | (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" |
| 301 | |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 302 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 303 | (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 304 | # endif |
| 305 | ); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 306 | } |
| 307 | #endif |
| 308 | |
| 309 | #ifdef UNIX |
| 310 | /* |
| 311 | * Force restricted-mode on for "nologin" or "false" $SHELL |
| 312 | */ |
| 313 | static void |
| 314 | set_init_restricted_mode(void) |
| 315 | { |
| 316 | char_u *p; |
| 317 | |
| 318 | p = get_isolated_shell_name(); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 319 | if (p == NULL) |
| 320 | return; |
| 321 | if (fnamecmp(p, "nologin") == 0 || fnamecmp(p, "false") == 0) |
| 322 | restricted = TRUE; |
| 323 | vim_free(p); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 324 | } |
| 325 | #endif |
| 326 | |
| 327 | #ifdef CLEAN_RUNTIMEPATH |
| 328 | /* |
| 329 | * When Vim is started with the "--clean" argument, set the default value |
| 330 | * for the 'runtimepath' and 'packpath' options. |
| 331 | */ |
| 332 | static void |
| 333 | set_init_clean_rtp(void) |
| 334 | { |
| 335 | int opt_idx; |
| 336 | |
| 337 | opt_idx = findoption((char_u *)"runtimepath"); |
| 338 | if (opt_idx >= 0) |
| 339 | { |
| 340 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 341 | p_rtp = (char_u *)CLEAN_RUNTIMEPATH; |
| 342 | } |
| 343 | opt_idx = findoption((char_u *)"packpath"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 344 | if (opt_idx < 0) |
| 345 | return; |
| 346 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 347 | p_pp = (char_u *)CLEAN_RUNTIMEPATH; |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 348 | } |
| 349 | #endif |
| 350 | |
| 351 | /* |
| 352 | * Expand environment variables and things like "~" for the defaults. |
| 353 | * If option_expand() returns non-NULL the variable is expanded. This can |
| 354 | * only happen for non-indirect options. |
| 355 | * Also set the default to the expanded value, so ":set" does not list |
| 356 | * them. |
| 357 | * Don't set the P_ALLOCED flag, because we don't want to free the |
| 358 | * default. |
| 359 | */ |
| 360 | static void |
| 361 | set_init_expand_env(void) |
| 362 | { |
| 363 | int opt_idx; |
| 364 | char_u *p; |
| 365 | |
| 366 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
| 367 | { |
| 368 | if ((options[opt_idx].flags & P_GETTEXT) |
| 369 | && options[opt_idx].var != NULL) |
| 370 | p = (char_u *)_(*(char **)options[opt_idx].var); |
| 371 | else |
| 372 | p = option_expand(opt_idx, NULL); |
| 373 | if (p != NULL && (p = vim_strsave(p)) != NULL) |
| 374 | { |
| 375 | *(char_u **)options[opt_idx].var = p; |
| 376 | // VIMEXP |
| 377 | // Defaults for all expanded options are currently the same for Vi |
| 378 | // and Vim. When this changes, add some code here! Also need to |
| 379 | // split P_DEF_ALLOCED in two. |
| 380 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 381 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 382 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 383 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * Initialize the 'LANG' environment variable to a default value. |
| 390 | */ |
| 391 | static void |
| 392 | set_init_lang_env(void) |
| 393 | { |
| 394 | #if defined(MSWIN) && defined(FEAT_GETTEXT) |
| 395 | // If $LANG isn't set, try to get a good value for it. This makes the |
| 396 | // right language be used automatically. Don't do this for English. |
| 397 | if (mch_getenv((char_u *)"LANG") == NULL) |
| 398 | { |
| 399 | char buf[20]; |
| 400 | long_u n; |
| 401 | |
| 402 | // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. |
| 403 | // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use |
| 404 | // only the first two. |
| 405 | n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, |
| 406 | (LPTSTR)buf, 20); |
| 407 | if (n >= 2 && STRNICMP(buf, "en", 2) != 0) |
| 408 | { |
| 409 | // There are a few exceptions (probably more) |
| 410 | if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) |
| 411 | STRCPY(buf, "zh_TW"); |
| 412 | else if (STRNICMP(buf, "chs", 3) == 0 |
| 413 | || STRNICMP(buf, "zhc", 3) == 0) |
| 414 | STRCPY(buf, "zh_CN"); |
| 415 | else if (STRNICMP(buf, "jp", 2) == 0) |
| 416 | STRCPY(buf, "ja"); |
| 417 | else |
| 418 | buf[2] = NUL; // truncate to two-letter code |
| 419 | vim_setenv((char_u *)"LANG", (char_u *)buf); |
| 420 | } |
| 421 | } |
| 422 | #elif defined(MACOS_CONVERT) |
| 423 | // Moved to os_mac_conv.c to avoid dependency problems. |
| 424 | mac_lang_init(); |
| 425 | #endif |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Initialize the 'encoding' option to a default value. |
| 430 | */ |
| 431 | static void |
| 432 | set_init_default_encoding(void) |
| 433 | { |
| 434 | char_u *p; |
| 435 | int opt_idx; |
| 436 | |
| 437 | # ifdef MSWIN |
| 438 | // MS-Windows has builtin support for conversion to and from Unicode, using |
| 439 | // "utf-8" for 'encoding' should work best for most users. |
| 440 | p = vim_strsave((char_u *)ENC_DFLT); |
| 441 | # else |
| 442 | // enc_locale() will try to find the encoding of the current locale. |
| 443 | // This works best for properly configured systems, old and new. |
| 444 | p = enc_locale(); |
| 445 | # endif |
| 446 | if (p == NULL) |
| 447 | return; |
| 448 | |
| 449 | // Try setting 'encoding' and check if the value is valid. |
| 450 | // If not, go back to the default encoding. |
| 451 | char_u *save_enc = p_enc; |
| 452 | p_enc = p; |
| 453 | if (STRCMP(p_enc, "gb18030") == 0) |
| 454 | { |
| 455 | // We don't support "gb18030", but "cp936" is a good substitute |
| 456 | // for practical purposes, thus use that. It's not an alias to |
| 457 | // still support conversion between gb18030 and utf-8. |
| 458 | p_enc = vim_strsave((char_u *)"cp936"); |
| 459 | vim_free(p); |
| 460 | } |
| 461 | if (mb_init() == NULL) |
| 462 | { |
| 463 | opt_idx = findoption((char_u *)"encoding"); |
| 464 | if (opt_idx >= 0) |
| 465 | { |
| 466 | options[opt_idx].def_val[VI_DEFAULT] = p_enc; |
| 467 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 468 | } |
| 469 | |
| 470 | #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) |
| 471 | if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) |
| 472 | { |
| 473 | // Adjust the default for 'isprint' and 'iskeyword' to match |
| 474 | // latin1. Also set the defaults for when 'nocompatible' is |
| 475 | // set. |
| 476 | set_string_option_direct((char_u *)"isp", -1, |
| 477 | ISP_LATIN1, OPT_FREE, SID_NONE); |
| 478 | set_string_option_direct((char_u *)"isk", -1, |
| 479 | ISK_LATIN1, OPT_FREE, SID_NONE); |
| 480 | opt_idx = findoption((char_u *)"isp"); |
| 481 | if (opt_idx >= 0) |
| 482 | options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; |
| 483 | opt_idx = findoption((char_u *)"isk"); |
| 484 | if (opt_idx >= 0) |
| 485 | options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; |
| 486 | (void)init_chartab(); |
| 487 | } |
| 488 | #endif |
| 489 | |
| 490 | #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
| 491 | // Win32 console: When GetACP() returns a different value from |
| 492 | // GetConsoleCP() set 'termencoding'. |
| 493 | if ( |
| 494 | # ifdef VIMDLL |
| 495 | (!gui.in_use && !gui.starting) && |
| 496 | # endif |
| 497 | GetACP() != GetConsoleCP()) |
| 498 | { |
| 499 | char buf[50]; |
| 500 | |
| 501 | // Win32 console: In ConPTY, GetConsoleCP() returns zero. |
| 502 | // Use an alternative value. |
| 503 | if (GetConsoleCP() == 0) |
| 504 | sprintf(buf, "cp%ld", (long)GetACP()); |
| 505 | else |
| 506 | sprintf(buf, "cp%ld", (long)GetConsoleCP()); |
| 507 | p_tenc = vim_strsave((char_u *)buf); |
| 508 | if (p_tenc != NULL) |
| 509 | { |
| 510 | opt_idx = findoption((char_u *)"termencoding"); |
| 511 | if (opt_idx >= 0) |
| 512 | { |
| 513 | options[opt_idx].def_val[VI_DEFAULT] = p_tenc; |
| 514 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 515 | } |
| 516 | convert_setup(&input_conv, p_tenc, p_enc); |
| 517 | convert_setup(&output_conv, p_enc, p_tenc); |
| 518 | } |
| 519 | else |
| 520 | p_tenc = empty_option; |
| 521 | } |
| 522 | #endif |
| 523 | #if defined(MSWIN) |
| 524 | // $HOME may have characters in active code page. |
| 525 | init_homedir(); |
| 526 | #endif |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | vim_free(p_enc); |
| 531 | p_enc = save_enc; |
| 532 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Initialize the options, first part. |
| 537 | * |
| 538 | * Called only once from main(), just after creating the first buffer. |
| 539 | * If "clean_arg" is TRUE Vim was started with --clean. |
| 540 | */ |
| 541 | void |
| 542 | set_init_1(int clean_arg) |
| 543 | { |
| 544 | #ifdef FEAT_LANGMAP |
| 545 | langmap_init(); |
| 546 | #endif |
| 547 | |
| 548 | // Be Vi compatible by default |
| 549 | p_cp = TRUE; |
| 550 | |
| 551 | // Use POSIX compatibility when $VIM_POSIX is set. |
| 552 | if (mch_getenv((char_u *)"VIM_POSIX") != NULL) |
| 553 | { |
| 554 | set_string_default("cpo", (char_u *)CPO_ALL); |
| 555 | set_string_default("shm", (char_u *)SHM_POSIX); |
| 556 | } |
| 557 | |
| 558 | set_init_default_shell(); |
| 559 | set_init_default_backupskip(); |
| 560 | set_init_default_maxmemtot(); |
| 561 | set_init_default_cdpath(); |
| 562 | set_init_default_printencoding(); |
| 563 | #ifdef FEAT_POSTSCRIPT |
| 564 | set_init_default_printexpr(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 565 | #endif |
| 566 | |
| 567 | /* |
| 568 | * Set all the options (except the terminal options) to their default |
| 569 | * value. Also set the global value for local options. |
| 570 | */ |
| 571 | set_options_default(0); |
| 572 | |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 573 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 574 | set_init_restricted_mode(); |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 575 | #endif |
| 576 | |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 577 | #ifdef CLEAN_RUNTIMEPATH |
| 578 | if (clean_arg) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 579 | set_init_clean_rtp(); |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 580 | #endif |
| 581 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 582 | #ifdef FEAT_GUI |
| 583 | if (found_reverse_arg) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 584 | set_option_value_give_err((char_u *)"bg", 0L, (char_u *)"dark", 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 585 | #endif |
| 586 | |
| 587 | curbuf->b_p_initialized = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 588 | curbuf->b_p_ar = -1; // no local 'autoread' value |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 589 | curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 590 | check_buf_options(curbuf); |
| 591 | check_win_options(curwin); |
| 592 | check_options(); |
| 593 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 594 | // Must be before option_expand(), because that one needs vim_isIDc() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 595 | didset_options(); |
| 596 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 597 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 598 | // Use the current chartab for the generic chartab. This is not in |
| 599 | // didset_options() because it only depends on 'encoding'. |
Bram Moolenaar | 6bb6836 | 2005-03-22 23:03:44 +0000 | [diff] [blame] | 600 | init_spell_chartab(); |
| 601 | #endif |
| 602 | |
K.Takata | ce3189d | 2023-02-15 19:13:43 +0000 | [diff] [blame] | 603 | set_init_default_encoding(); |
| 604 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 605 | // Expand environment variables and things like "~" for the defaults. |
| 606 | set_init_expand_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 607 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 608 | save_file_ff(curbuf); // Buffer is unchanged |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 609 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 610 | #if defined(FEAT_ARABIC) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 611 | // Detect use of mlterm. |
| 612 | // Mlterm is a terminal emulator akin to xterm that has some special |
| 613 | // abilities (bidi namely). |
| 614 | // NOTE: mlterm's author is being asked to 'set' a variable |
| 615 | // instead of an environment variable due to inheritance. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 616 | if (mch_getenv((char_u *)"MLTERM") != NULL) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 617 | set_option_value_give_err((char_u *)"tbidi", 1L, NULL, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 618 | #endif |
| 619 | |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 620 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 621 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 622 | set_init_lang_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 623 | |
| 624 | #ifdef FEAT_MULTI_LANG |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 625 | // Set the default for 'helplang'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 626 | set_helplang_default(get_mess_lang()); |
| 627 | #endif |
| 628 | } |
| 629 | |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 630 | static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1"; |
| 631 | |
| 632 | /* |
| 633 | * Set the "fileencodings" option to the default value for when 'encoding' is |
| 634 | * utf-8. |
| 635 | */ |
| 636 | void |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 637 | set_fencs_unicode(void) |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 638 | { |
| 639 | set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, |
| 640 | OPT_FREE, 0); |
| 641 | } |
| 642 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 643 | /* |
| 644 | * Set an option to its default value. |
| 645 | * This does not take care of side effects! |
| 646 | */ |
| 647 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 648 | set_option_default( |
| 649 | int opt_idx, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 650 | int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
| 651 | int compatible) // use Vi default value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 652 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 653 | char_u *varp; // pointer to variable for current option |
| 654 | int dvi; // index in def_val[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 655 | long_u flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 656 | long_u *flagsp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 657 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 658 | |
| 659 | varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); |
| 660 | flags = options[opt_idx].flags; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 661 | if (varp != NULL) // skip hidden option, nothing to do for it |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 662 | { |
| 663 | dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
| 664 | if (flags & P_STRING) |
| 665 | { |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 666 | // 'fencs' default value depends on 'encoding' |
| 667 | if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8) |
| 668 | set_fencs_unicode(); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 669 | // Use set_string_option_direct() for local options to handle |
| 670 | // freeing and allocating the value. |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 671 | else if (options[opt_idx].indir != PV_NONE) |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 672 | set_string_option_direct(NULL, opt_idx, |
| 673 | options[opt_idx].def_val[dvi], opt_flags, 0); |
| 674 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 675 | { |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 676 | if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) |
| 677 | free_string_option(*(char_u **)(varp)); |
| 678 | *(char_u **)varp = options[opt_idx].def_val[dvi]; |
| 679 | options[opt_idx].flags &= ~P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | else if (flags & P_NUM) |
| 683 | { |
Bram Moolenaar | 5fc1a8b | 2006-10-17 16:34:24 +0000 | [diff] [blame] | 684 | if (options[opt_idx].indir == PV_SCROLL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 685 | win_comp_scroll(curwin); |
| 686 | else |
| 687 | { |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 688 | long def_val = (long)(long_i)options[opt_idx].def_val[dvi]; |
| 689 | |
| 690 | if ((long *)varp == &curwin->w_p_so |
| 691 | || (long *)varp == &curwin->w_p_siso) |
| 692 | // 'scrolloff' and 'sidescrolloff' local values have a |
| 693 | // different default value than the global default. |
| 694 | *(long *)varp = -1; |
| 695 | else |
| 696 | *(long *)varp = def_val; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 697 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 698 | if (both) |
| 699 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 700 | def_val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 701 | } |
| 702 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 703 | else // P_BOOL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 704 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 705 | // the cast to long is required for Manx C, long_i is needed for |
| 706 | // MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 707 | *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 708 | #ifdef UNIX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 709 | // 'modeline' defaults to off for root |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 710 | if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) |
| 711 | *(int *)varp = FALSE; |
| 712 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 713 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 714 | if (both) |
| 715 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
| 716 | *(int *)varp; |
| 717 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 718 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 719 | // The default value is not insecure. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 720 | flagsp = insecure_flag(opt_idx, opt_flags); |
| 721 | *flagsp = *flagsp & ~P_INSECURE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | #ifdef FEAT_EVAL |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 725 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 726 | #endif |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * Set all options (except terminal options) to their default value. |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 731 | * When "opt_flags" is non-zero skip 'encoding'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 732 | */ |
| 733 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 734 | set_options_default( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 735 | int opt_flags) // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 736 | { |
| 737 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 738 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 739 | tabpage_T *tp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 740 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 741 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 742 | if (!(options[i].flags & P_NODEFAULT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 743 | && (opt_flags == 0 |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 744 | || (options[i].var != (char_u *)&p_enc |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 745 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 746 | && options[i].var != (char_u *)&p_cm |
Bram Moolenaar | 8060687 | 2015-08-25 21:27:35 +0200 | [diff] [blame] | 747 | && options[i].var != (char_u *)&p_key |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 748 | # endif |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 749 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 750 | set_option_default(i, opt_flags, p_cp); |
| 751 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 752 | // The 'scroll' option must be computed for all windows. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 753 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | win_comp_scroll(wp); |
Bram Moolenaar | 5a4eceb | 2014-09-09 17:33:07 +0200 | [diff] [blame] | 755 | parse_cino(curbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* |
| 759 | * Set the Vi-default value of a string option. |
| 760 | * Used for 'sh', 'backupskip' and 'term'. |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 761 | * When "escape" is TRUE escape spaces with a backslash. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 762 | */ |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 763 | static void |
| 764 | set_string_default_esc(char *name, char_u *val, int escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 765 | { |
| 766 | char_u *p; |
| 767 | int opt_idx; |
| 768 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 769 | if (escape && vim_strchr(val, ' ') != NULL) |
| 770 | p = vim_strsave_escaped(val, (char_u *)" "); |
| 771 | else |
| 772 | p = vim_strsave(val); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 773 | if (p == NULL) // we don't want a NULL |
| 774 | return; |
| 775 | |
| 776 | opt_idx = findoption((char_u *)name); |
| 777 | if (opt_idx < 0) |
| 778 | return; |
| 779 | |
| 780 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 781 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 782 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 783 | options[opt_idx].flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 786 | void |
| 787 | set_string_default(char *name, char_u *val) |
| 788 | { |
| 789 | set_string_default_esc(name, val, FALSE); |
| 790 | } |
| 791 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 792 | /* |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 793 | * For an option value that contains comma separated items, find "newval" in |
| 794 | * "origval". Return NULL if not found. |
| 795 | */ |
| 796 | static char_u * |
| 797 | find_dup_item(char_u *origval, char_u *newval, long_u flags) |
| 798 | { |
Bram Moolenaar | 8f13d82 | 2020-09-12 21:04:23 +0200 | [diff] [blame] | 799 | int bs = 0; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 800 | size_t newlen; |
| 801 | char_u *s; |
| 802 | |
| 803 | if (origval == NULL) |
| 804 | return NULL; |
| 805 | |
| 806 | newlen = STRLEN(newval); |
| 807 | for (s = origval; *s != NUL; ++s) |
| 808 | { |
| 809 | if ((!(flags & P_COMMA) |
| 810 | || s == origval |
| 811 | || (s[-1] == ',' && !(bs & 1))) |
| 812 | && STRNCMP(s, newval, newlen) == 0 |
| 813 | && (!(flags & P_COMMA) |
| 814 | || s[newlen] == ',' |
| 815 | || s[newlen] == NUL)) |
| 816 | return s; |
| 817 | // Count backslashes. Only a comma with an even number of backslashes |
| 818 | // or a single backslash preceded by a comma before it is recognized as |
| 819 | // a separator. |
| 820 | if ((s > origval + 1 |
| 821 | && s[-1] == '\\' |
| 822 | && s[-2] != ',') |
| 823 | || (s == origval + 1 |
| 824 | && s[-1] == '\\')) |
| 825 | ++bs; |
| 826 | else |
| 827 | bs = 0; |
| 828 | } |
| 829 | return NULL; |
| 830 | } |
| 831 | |
| 832 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 833 | * Set the Vi-default value of a number option. |
| 834 | * Used for 'lines' and 'columns'. |
| 835 | */ |
| 836 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 837 | set_number_default(char *name, long val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 838 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 839 | int opt_idx; |
| 840 | |
| 841 | opt_idx = findoption((char_u *)name); |
| 842 | if (opt_idx >= 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 843 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 846 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 847 | /* |
| 848 | * Set all window-local and buffer-local options to the Vim default. |
| 849 | * local-global options will use the global value. |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 850 | * When "do_buffer" is FALSE don't set buffer-local options. |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 851 | */ |
| 852 | void |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 853 | set_local_options_default(win_T *wp, int do_buffer) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 854 | { |
| 855 | win_T *save_curwin = curwin; |
| 856 | int i; |
| 857 | |
| 858 | curwin = wp; |
| 859 | curbuf = curwin->w_buffer; |
| 860 | block_autocmds(); |
| 861 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 862 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 863 | { |
| 864 | struct vimoption *p = &(options[i]); |
| 865 | char_u *varp = get_varp_scope(p, OPT_LOCAL); |
| 866 | |
| 867 | if (p->indir != PV_NONE |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 868 | && (do_buffer || (p->indir & PV_BUF) == 0) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 869 | && !(options[i].flags & P_NODEFAULT) |
| 870 | && !optval_default(p, varp, FALSE)) |
Bram Moolenaar | 8617348 | 2019-10-01 17:02:16 +0200 | [diff] [blame] | 871 | set_option_default(i, OPT_FREE|OPT_LOCAL, FALSE); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | unblock_autocmds(); |
| 875 | curwin = save_curwin; |
| 876 | curbuf = curwin->w_buffer; |
| 877 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 878 | #endif |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 879 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 880 | #if defined(EXITFREE) || defined(PROTO) |
| 881 | /* |
| 882 | * Free all options. |
| 883 | */ |
| 884 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 885 | free_all_options(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 886 | { |
| 887 | int i; |
| 888 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 889 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 890 | { |
| 891 | if (options[i].indir == PV_NONE) |
| 892 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 893 | // global option: free value and default value. |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 894 | if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 895 | free_string_option(*(char_u **)options[i].var); |
| 896 | if (options[i].flags & P_DEF_ALLOCED) |
| 897 | free_string_option(options[i].def_val[VI_DEFAULT]); |
| 898 | } |
| 899 | else if (options[i].var != VAR_WIN |
| 900 | && (options[i].flags & P_STRING)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 901 | // buffer-local option: free global value |
Bram Moolenaar | 77111e2 | 2021-07-29 21:11:30 +0200 | [diff] [blame] | 902 | clear_string_option((char_u **)options[i].var); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 903 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 904 | free_operatorfunc_option(); |
Yegappan Lakshmanan | 19916a8 | 2021-11-24 16:32:55 +0000 | [diff] [blame] | 905 | free_tagfunc_option(); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 906 | } |
| 907 | #endif |
| 908 | |
| 909 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 910 | /* |
| 911 | * Initialize the options, part two: After getting Rows and Columns and |
| 912 | * setting 'term'. |
| 913 | */ |
| 914 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 915 | set_init_2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 916 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 917 | int idx; |
| 918 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 919 | /* |
Bram Moolenaar | af2d20c | 2017-10-29 15:26:57 +0100 | [diff] [blame] | 920 | * 'scroll' defaults to half the window height. The stored default is zero, |
| 921 | * which results in the actual value computed from the window height. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 922 | */ |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 923 | idx = findoption((char_u *)"scroll"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 924 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 925 | set_option_default(idx, OPT_LOCAL, p_cp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 926 | comp_col(); |
| 927 | |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 928 | /* |
| 929 | * 'window' is only for backwards compatibility with Vi. |
| 930 | * Default is Rows - 1. |
| 931 | */ |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 932 | if (!option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 933 | p_window = Rows - 1; |
| 934 | set_number_default("window", Rows - 1); |
| 935 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 936 | // For DOS console the default is always black. |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 937 | #if !((defined(MSWIN)) && !defined(FEAT_GUI)) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 938 | /* |
| 939 | * If 'background' wasn't set by the user, try guessing the value, |
| 940 | * depending on the terminal name. Only need to check for terminals |
| 941 | * with a dark background, that can handle color. |
| 942 | */ |
| 943 | idx = findoption((char_u *)"bg"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 944 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET) |
| 945 | && *term_bg_default() == 'd') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 946 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 947 | set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 948 | // don't mark it as set, when starting the GUI it may be |
| 949 | // changed again |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 950 | options[idx].flags &= ~P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 951 | } |
| 952 | #endif |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 953 | |
| 954 | #ifdef CURSOR_SHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 955 | parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 956 | #endif |
| 957 | #ifdef FEAT_MOUSESHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 958 | parse_shape_opt(SHAPE_MOUSE); // set mouse shapes from 'mouseshape' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 959 | #endif |
| 960 | #ifdef FEAT_PRINTER |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 961 | (void)parse_printoptions(NULL); // parse 'printoptions' default value |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 962 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /* |
| 966 | * Initialize the options, part three: After reading the .vimrc |
| 967 | */ |
| 968 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 969 | set_init_3(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 970 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 971 | #if defined(UNIX) || defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 972 | /* |
| 973 | * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. |
| 974 | * This is done after other initializations, where 'shell' might have been |
| 975 | * set, but only if they have not been set before. |
| 976 | */ |
| 977 | char_u *p; |
| 978 | int idx_srr; |
| 979 | int do_srr; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 980 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 981 | int idx_sp; |
| 982 | int do_sp; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 983 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 984 | |
| 985 | idx_srr = findoption((char_u *)"srr"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 986 | if (idx_srr < 0) |
| 987 | do_srr = FALSE; |
| 988 | else |
| 989 | do_srr = !(options[idx_srr].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 990 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 991 | idx_sp = findoption((char_u *)"sp"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 992 | if (idx_sp < 0) |
| 993 | do_sp = FALSE; |
| 994 | else |
| 995 | do_sp = !(options[idx_sp].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 996 | # endif |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 997 | p = get_isolated_shell_name(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 998 | if (p != NULL) |
| 999 | { |
| 1000 | /* |
| 1001 | * Default for p_sp is "| tee", for p_srr is ">". |
| 1002 | * For known shells it is changed here to include stderr. |
| 1003 | */ |
| 1004 | if ( fnamecmp(p, "csh") == 0 |
| 1005 | || fnamecmp(p, "tcsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1006 | # if defined(MSWIN) // also check with .exe extension |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1007 | || fnamecmp(p, "csh.exe") == 0 |
| 1008 | || fnamecmp(p, "tcsh.exe") == 0 |
| 1009 | # endif |
| 1010 | ) |
| 1011 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1012 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1013 | if (do_sp) |
| 1014 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1015 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1016 | p_sp = (char_u *)">&"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1017 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1018 | p_sp = (char_u *)"|& tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1019 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1020 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1021 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1022 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1023 | if (do_srr) |
| 1024 | { |
| 1025 | p_srr = (char_u *)">&"; |
| 1026 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1027 | } |
| 1028 | } |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1029 | # ifdef MSWIN |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1030 | // Windows PowerShell output is UTF-16 with BOM so re-encode to the |
| 1031 | // current codepage. |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1032 | else if ( fnamecmp(p, "powershell") == 0 |
| 1033 | || fnamecmp(p, "powershell.exe") == 0 |
| 1034 | ) |
| 1035 | { |
| 1036 | # if defined(FEAT_QUICKFIX) |
| 1037 | if (do_sp) |
| 1038 | { |
| 1039 | p_sp = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1040 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1041 | } |
| 1042 | # endif |
| 1043 | if (do_srr) |
| 1044 | { |
| 1045 | p_srr = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1046 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1047 | } |
| 1048 | } |
| 1049 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1050 | else |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1051 | // Always use POSIX shell style redirection if we reach this |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1052 | if ( fnamecmp(p, "sh") == 0 |
| 1053 | || fnamecmp(p, "ksh") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1054 | || fnamecmp(p, "mksh") == 0 |
| 1055 | || fnamecmp(p, "pdksh") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1056 | || fnamecmp(p, "zsh") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1057 | || fnamecmp(p, "zsh-beta") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1058 | || fnamecmp(p, "bash") == 0 |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 1059 | || fnamecmp(p, "fish") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1060 | || fnamecmp(p, "ash") == 0 |
| 1061 | || fnamecmp(p, "dash") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1062 | || fnamecmp(p, "pwsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1063 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1064 | || fnamecmp(p, "cmd") == 0 |
| 1065 | || fnamecmp(p, "sh.exe") == 0 |
| 1066 | || fnamecmp(p, "ksh.exe") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1067 | || fnamecmp(p, "mksh.exe") == 0 |
| 1068 | || fnamecmp(p, "pdksh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1069 | || fnamecmp(p, "zsh.exe") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1070 | || fnamecmp(p, "zsh-beta.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1071 | || fnamecmp(p, "bash.exe") == 0 |
| 1072 | || fnamecmp(p, "cmd.exe") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1073 | || fnamecmp(p, "dash.exe") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1074 | || fnamecmp(p, "pwsh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1075 | # endif |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1076 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1077 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1078 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1079 | if (do_sp) |
| 1080 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1081 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1082 | p_sp = (char_u *)">%s 2>&1"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1083 | # else |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1084 | if (fnamecmp(p, "pwsh") == 0) |
| 1085 | p_sp = (char_u *)">%s 2>&1"; |
| 1086 | else |
| 1087 | p_sp = (char_u *)"2>&1| tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1088 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1089 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1090 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1091 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1092 | if (do_srr) |
| 1093 | { |
| 1094 | p_srr = (char_u *)">%s 2>&1"; |
| 1095 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1096 | } |
| 1097 | } |
| 1098 | vim_free(p); |
| 1099 | } |
| 1100 | #endif |
| 1101 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1102 | #if defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1103 | /* |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1104 | * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the |
| 1105 | * 'shell' option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1106 | * This is done after other initializations, where 'shell' might have been |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1107 | * set, but only if they have not been set before. |
| 1108 | * Default values depend on shell (cmd.exe is default shell): |
| 1109 | * |
| 1110 | * p_shcf p_sxq |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 1111 | * cmd.exe - "/c" "(" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1112 | * powershell.exe - "-Command" "\"" |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1113 | * pwsh.exe - "-c" "\"" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1114 | * "sh" like shells - "-c" "\"" |
| 1115 | * |
| 1116 | * 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] | 1117 | */ |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1118 | if (strstr((char *)gettail(p_sh), "powershell") != NULL) |
| 1119 | { |
| 1120 | int idx_opt; |
| 1121 | |
| 1122 | idx_opt = findoption((char_u *)"shcf"); |
| 1123 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1124 | { |
| 1125 | p_shcf = (char_u*)"-Command"; |
| 1126 | options[idx_opt].def_val[VI_DEFAULT] = p_shcf; |
| 1127 | } |
| 1128 | |
| 1129 | idx_opt = findoption((char_u *)"sxq"); |
| 1130 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1131 | { |
| 1132 | p_sxq = (char_u*)"\""; |
| 1133 | options[idx_opt].def_val[VI_DEFAULT] = p_sxq; |
| 1134 | } |
| 1135 | } |
| 1136 | else if (strstr((char *)gettail(p_sh), "sh") != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1137 | { |
| 1138 | int idx3; |
| 1139 | |
| 1140 | idx3 = findoption((char_u *)"shcf"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1141 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1142 | { |
| 1143 | p_shcf = (char_u *)"-c"; |
| 1144 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1145 | } |
| 1146 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1147 | // Somehow Win32 requires the quotes around the redirection too |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1148 | idx3 = findoption((char_u *)"sxq"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1149 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1150 | { |
| 1151 | p_sxq = (char_u *)"\""; |
| 1152 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1153 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1154 | } |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1155 | else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL) |
| 1156 | { |
| 1157 | int idx3; |
| 1158 | |
| 1159 | /* |
| 1160 | * cmd.exe on Windows will strip the first and last double quote given |
| 1161 | * on the command line, e.g. most of the time things like: |
| 1162 | * cmd /c "my path/to/echo" "my args to echo" |
| 1163 | * become: |
| 1164 | * my path/to/echo" "my args to echo |
| 1165 | * when executed. |
| 1166 | * |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1167 | * To avoid this, set shellxquote to surround the command in |
| 1168 | * parenthesis. This appears to make most commands work, without |
| 1169 | * breaking commands that worked previously, such as |
| 1170 | * '"path with spaces/cmd" "a&b"'. |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1171 | */ |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1172 | idx3 = findoption((char_u *)"sxq"); |
| 1173 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1174 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1175 | p_sxq = (char_u *)"("; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1176 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1177 | } |
| 1178 | |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1179 | idx3 = findoption((char_u *)"shcf"); |
| 1180 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1181 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1182 | p_shcf = (char_u *)"/c"; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1183 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1184 | } |
| 1185 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1186 | #endif |
| 1187 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1188 | if (BUFEMPTY()) |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1189 | { |
| 1190 | int idx_ffs = findoption((char_u *)"ffs"); |
| 1191 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1192 | // Apply the first entry of 'fileformats' to the initial buffer. |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1193 | if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) |
| 1194 | set_fileformat(default_fileformat(), OPT_LOCAL); |
| 1195 | } |
| 1196 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1197 | set_title_defaults(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
| 1201 | /* |
| 1202 | * When 'helplang' is still at its default value, set it to "lang". |
| 1203 | * Only the first two characters of "lang" are used. |
| 1204 | */ |
| 1205 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1206 | set_helplang_default(char_u *lang) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1207 | { |
| 1208 | int idx; |
| 1209 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1210 | if (lang == NULL || STRLEN(lang) < 2) // safety check |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1211 | return; |
| 1212 | idx = findoption((char_u *)"hlg"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1213 | if (idx < 0 || (options[idx].flags & P_WAS_SET)) |
| 1214 | return; |
| 1215 | |
| 1216 | if (options[idx].flags & P_ALLOCED) |
| 1217 | free_string_option(p_hlg); |
| 1218 | p_hlg = vim_strsave(lang); |
| 1219 | if (p_hlg == NULL) |
| 1220 | p_hlg = empty_option; |
| 1221 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1222 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1223 | // zh_CN becomes "cn", zh_TW becomes "tw" |
| 1224 | if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1225 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1226 | p_hlg[0] = TOLOWER_ASC(p_hlg[3]); |
| 1227 | p_hlg[1] = TOLOWER_ASC(p_hlg[4]); |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1228 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1229 | // any C like setting, such as C.UTF-8, becomes "en" |
| 1230 | else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') |
| 1231 | { |
| 1232 | p_hlg[0] = 'e'; |
| 1233 | p_hlg[1] = 'n'; |
| 1234 | } |
| 1235 | p_hlg[2] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1236 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1237 | options[idx].flags |= P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1238 | } |
| 1239 | #endif |
| 1240 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1241 | /* |
| 1242 | * 'title' and 'icon' only default to true if they have not been set or reset |
| 1243 | * in .vimrc and we can read the old value. |
| 1244 | * When 'title' and 'icon' have been reset in .vimrc, we won't even check if |
| 1245 | * they can be reset. This reduces startup time when using X on a remote |
| 1246 | * machine. |
| 1247 | */ |
| 1248 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1249 | set_title_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | { |
| 1251 | int idx1; |
| 1252 | long val; |
| 1253 | |
| 1254 | /* |
| 1255 | * If GUI is (going to be) used, we can always set the window title and |
| 1256 | * icon name. Saves a bit of time, because the X11 display server does |
| 1257 | * not need to be contacted. |
| 1258 | */ |
| 1259 | idx1 = findoption((char_u *)"title"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1260 | if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1261 | { |
| 1262 | #ifdef FEAT_GUI |
| 1263 | if (gui.starting || gui.in_use) |
| 1264 | val = TRUE; |
| 1265 | else |
| 1266 | #endif |
| 1267 | val = mch_can_restore_title(); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1268 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1269 | p_title = val; |
| 1270 | } |
| 1271 | idx1 = findoption((char_u *)"icon"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1272 | if (idx1 < 0 || (options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1273 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1274 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1276 | |
| 1277 | #ifdef FEAT_GUI |
| 1278 | if (gui.starting || gui.in_use) |
| 1279 | val = TRUE; |
| 1280 | else |
| 1281 | #endif |
| 1282 | val = mch_can_restore_icon(); |
| 1283 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
| 1284 | p_icon = val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1285 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1286 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1287 | void |
| 1288 | ex_set(exarg_T *eap) |
| 1289 | { |
| 1290 | int flags = 0; |
| 1291 | |
| 1292 | if (eap->cmdidx == CMD_setlocal) |
| 1293 | flags = OPT_LOCAL; |
| 1294 | else if (eap->cmdidx == CMD_setglobal) |
| 1295 | flags = OPT_GLOBAL; |
| 1296 | #if defined(FEAT_EVAL) && defined(FEAT_BROWSE) |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 1297 | if ((cmdmod.cmod_flags & CMOD_BROWSE) && flags == 0) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1298 | ex_options(eap); |
| 1299 | else |
| 1300 | #endif |
| 1301 | { |
| 1302 | if (eap->forceit) |
| 1303 | flags |= OPT_ONECOLUMN; |
| 1304 | (void)do_set(eap->arg, flags); |
| 1305 | } |
| 1306 | } |
| 1307 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1308 | /* |
| 1309 | * :set operator types |
| 1310 | */ |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1311 | typedef enum { |
| 1312 | OP_NONE = 0, |
| 1313 | OP_ADDING, // "opt+=arg" |
| 1314 | OP_PREPENDING, // "opt^=arg" |
| 1315 | OP_REMOVING, // "opt-=arg" |
| 1316 | } set_op_T; |
| 1317 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1318 | typedef enum { |
| 1319 | PREFIX_NO = 0, // "no" prefix |
| 1320 | PREFIX_NONE, // no prefix |
| 1321 | PREFIX_INV, // "inv" prefix |
| 1322 | } set_prefix_T; |
| 1323 | |
| 1324 | /* |
| 1325 | * Return the prefix type for the option name in *argp. |
| 1326 | */ |
| 1327 | static set_prefix_T |
| 1328 | get_option_prefix(char_u **argp) |
| 1329 | { |
| 1330 | int prefix = PREFIX_NONE; |
| 1331 | char_u *arg = *argp; |
| 1332 | |
| 1333 | if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0) |
| 1334 | { |
| 1335 | prefix = PREFIX_NO; |
| 1336 | arg += 2; |
| 1337 | } |
| 1338 | else if (STRNCMP(arg, "inv", 3) == 0) |
| 1339 | { |
| 1340 | prefix = PREFIX_INV; |
| 1341 | arg += 3; |
| 1342 | } |
| 1343 | |
| 1344 | *argp = arg; |
| 1345 | return prefix; |
| 1346 | } |
| 1347 | |
| 1348 | /* |
| 1349 | * Parse the option name in "arg" and return the option index in "*opt_idxp", |
| 1350 | * and the option name length in "*lenp". For a <t_xx> option, return the key |
| 1351 | * number in "*keyp". |
| 1352 | * |
| 1353 | * Returns FAIL if an option starting with "<" doesn't end with a ">", |
| 1354 | * otherwise returns OK. |
| 1355 | */ |
| 1356 | static int |
| 1357 | parse_option_name(char_u *arg, int *opt_idxp, int *lenp, int *keyp) |
| 1358 | { |
| 1359 | int key = 0; |
| 1360 | int len; |
| 1361 | int opt_idx; |
| 1362 | |
| 1363 | if (*arg == '<') |
| 1364 | { |
| 1365 | opt_idx = -1; |
| 1366 | // look out for <t_>;> |
| 1367 | if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) |
| 1368 | len = 5; |
| 1369 | else |
| 1370 | { |
| 1371 | len = 1; |
| 1372 | while (arg[len] != NUL && arg[len] != '>') |
| 1373 | ++len; |
| 1374 | } |
| 1375 | if (arg[len] != '>') |
| 1376 | return FAIL; |
| 1377 | |
| 1378 | arg[len] = NUL; // put NUL after name |
| 1379 | if (arg[1] == 't' && arg[2] == '_') // could be term code |
| 1380 | opt_idx = findoption(arg + 1); |
| 1381 | arg[len++] = '>'; // restore '>' |
| 1382 | if (opt_idx == -1) |
| 1383 | key = find_key_option(arg + 1, TRUE); |
| 1384 | } |
| 1385 | else |
| 1386 | { |
| 1387 | int nextchar; // next non-white char after option name |
| 1388 | |
| 1389 | len = 0; |
| 1390 | /* |
| 1391 | * The two characters after "t_" may not be alphanumeric. |
| 1392 | */ |
| 1393 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 1394 | len = 4; |
| 1395 | else |
| 1396 | while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') |
| 1397 | ++len; |
| 1398 | nextchar = arg[len]; |
| 1399 | arg[len] = NUL; // put NUL after name |
| 1400 | opt_idx = findoption(arg); |
| 1401 | arg[len] = nextchar; // restore nextchar |
| 1402 | if (opt_idx == -1) |
| 1403 | key = find_key_option(arg, FALSE); |
| 1404 | } |
| 1405 | |
| 1406 | *keyp = key; |
| 1407 | *lenp = len; |
| 1408 | *opt_idxp = opt_idx; |
| 1409 | |
| 1410 | return OK; |
| 1411 | } |
| 1412 | |
| 1413 | /* |
| 1414 | * Get the option operator (+=, ^=, -=). |
| 1415 | */ |
| 1416 | static set_op_T |
| 1417 | get_opt_op(char_u *arg) |
| 1418 | { |
| 1419 | set_op_T op = OP_NONE; |
| 1420 | |
| 1421 | if (*arg != NUL && *(arg + 1) == '=') |
| 1422 | { |
| 1423 | if (*arg == '+') |
| 1424 | op = OP_ADDING; // "+=" |
| 1425 | else if (*arg == '^') |
| 1426 | op = OP_PREPENDING; // "^=" |
| 1427 | else if (*arg == '-') |
| 1428 | op = OP_REMOVING; // "-=" |
| 1429 | } |
| 1430 | |
| 1431 | return op; |
| 1432 | } |
| 1433 | |
| 1434 | /* |
| 1435 | * Validate whether the value of the option in "opt_idx" can be changed. |
| 1436 | * Returns FAIL if the option can be skipped or cannot be changed. Returns OK |
| 1437 | * if it can be changed. |
| 1438 | */ |
| 1439 | static int |
| 1440 | validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg) |
| 1441 | { |
| 1442 | // Skip all options that are not window-local (used when showing |
| 1443 | // an already loaded buffer in a window). |
| 1444 | if ((opt_flags & OPT_WINONLY) |
| 1445 | && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) |
| 1446 | return FAIL; |
| 1447 | |
| 1448 | // Skip all options that are window-local (used for :vimgrep). |
| 1449 | if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 |
| 1450 | && options[opt_idx].var == VAR_WIN) |
| 1451 | return FAIL; |
| 1452 | |
| 1453 | // Disallow changing some options from modelines. |
| 1454 | if (opt_flags & OPT_MODELINE) |
| 1455 | { |
| 1456 | if (flags & (P_SECURE | P_NO_ML)) |
| 1457 | { |
| 1458 | *errmsg = e_not_allowed_in_modeline; |
| 1459 | return FAIL; |
| 1460 | } |
| 1461 | if ((flags & P_MLE) && !p_mle) |
| 1462 | { |
| 1463 | *errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off; |
| 1464 | return FAIL; |
| 1465 | } |
| 1466 | #ifdef FEAT_DIFF |
| 1467 | // In diff mode some options are overruled. This avoids that |
| 1468 | // 'foldmethod' becomes "marker" instead of "diff" and that |
| 1469 | // "wrap" gets set. |
| 1470 | if (curwin->w_p_diff |
| 1471 | && opt_idx >= 0 // shut up coverity warning |
| 1472 | && ( |
| 1473 | # ifdef FEAT_FOLDING |
| 1474 | options[opt_idx].indir == PV_FDM || |
| 1475 | # endif |
| 1476 | options[opt_idx].indir == PV_WRAP)) |
| 1477 | return FAIL; |
| 1478 | #endif |
| 1479 | } |
| 1480 | |
| 1481 | #ifdef HAVE_SANDBOX |
| 1482 | // Disallow changing some options in the sandbox |
| 1483 | if (sandbox != 0 && (flags & P_SECURE)) |
| 1484 | { |
| 1485 | *errmsg = e_not_allowed_in_sandbox; |
| 1486 | return FAIL; |
| 1487 | } |
| 1488 | #endif |
| 1489 | |
| 1490 | return OK; |
| 1491 | } |
| 1492 | |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1493 | /* |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1494 | * Get the Vim/Vi default value for a string option. |
| 1495 | */ |
| 1496 | static char_u * |
| 1497 | stropt_get_default_val( |
| 1498 | int opt_idx, |
| 1499 | char_u *varp, |
| 1500 | int flags, |
| 1501 | int cp_val) |
| 1502 | { |
| 1503 | char_u *newval; |
| 1504 | |
| 1505 | newval = options[opt_idx].def_val[((flags & P_VI_DEF) || cp_val) |
| 1506 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1507 | if ((char_u **)varp == &p_bg) |
| 1508 | { |
| 1509 | // guess the value of 'background' |
| 1510 | #ifdef FEAT_GUI |
| 1511 | if (gui.in_use) |
| 1512 | newval = gui_bg_default(); |
| 1513 | else |
| 1514 | #endif |
| 1515 | newval = term_bg_default(); |
| 1516 | } |
| 1517 | else if ((char_u **)varp == &p_fencs && enc_utf8) |
| 1518 | newval = fencs_utf8_default; |
| 1519 | |
| 1520 | // expand environment variables and ~ since the default value was |
| 1521 | // already expanded, only required when an environment variable was set |
| 1522 | // later |
| 1523 | if (newval == NULL) |
| 1524 | newval = empty_option; |
| 1525 | else |
| 1526 | { |
| 1527 | char_u *s = option_expand(opt_idx, newval); |
| 1528 | if (s == NULL) |
| 1529 | s = newval; |
| 1530 | newval = vim_strsave(s); |
| 1531 | } |
| 1532 | |
| 1533 | return newval; |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * Convert the 'backspace' option number value to a string: for adding, |
| 1538 | * prepending and removing string. |
| 1539 | */ |
| 1540 | static void |
| 1541 | opt_backspace_nr2str( |
| 1542 | char_u *varp, |
| 1543 | char_u **origval_p, |
| 1544 | char_u **origval_l_p, |
| 1545 | char_u **origval_g_p, |
| 1546 | char_u **oldval_p) |
| 1547 | { |
| 1548 | int i = getdigits((char_u **)varp); |
| 1549 | |
| 1550 | switch (i) |
| 1551 | { |
| 1552 | case 0: |
| 1553 | *(char_u **)varp = empty_option; |
| 1554 | break; |
| 1555 | case 1: |
| 1556 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); |
| 1557 | break; |
| 1558 | case 2: |
| 1559 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start"); |
| 1560 | break; |
| 1561 | case 3: |
| 1562 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop"); |
| 1563 | break; |
| 1564 | } |
| 1565 | vim_free(*oldval_p); |
| 1566 | if (*origval_p == *oldval_p) |
| 1567 | *origval_p = *(char_u **)varp; |
| 1568 | if (*origval_l_p == *oldval_p) |
| 1569 | *origval_l_p = *(char_u **)varp; |
| 1570 | if (*origval_g_p == *oldval_p) |
| 1571 | *origval_g_p = *(char_u **)varp; |
| 1572 | *oldval_p = *(char_u **)varp; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * Convert the 'whichwrap' option number value to a string, for backwards |
| 1577 | * compatibility with Vim 3.0. |
| 1578 | * Note: 'argp' is a pointer to a char_u pointer and is updated. |
| 1579 | */ |
| 1580 | static char_u * |
| 1581 | opt_whichwrap_nr2str(char_u **argp, char_u *whichwrap) |
| 1582 | { |
| 1583 | *whichwrap = NUL; |
| 1584 | int i = getdigits(argp); |
| 1585 | if (i & 1) |
| 1586 | STRCAT(whichwrap, "b,"); |
| 1587 | if (i & 2) |
| 1588 | STRCAT(whichwrap, "s,"); |
| 1589 | if (i & 4) |
| 1590 | STRCAT(whichwrap, "h,l,"); |
| 1591 | if (i & 8) |
| 1592 | STRCAT(whichwrap, "<,>,"); |
| 1593 | if (i & 16) |
| 1594 | STRCAT(whichwrap, "[,],"); |
| 1595 | if (*whichwrap != NUL) // remove trailing , |
| 1596 | whichwrap[STRLEN(whichwrap) - 1] = NUL; |
| 1597 | |
| 1598 | return whichwrap; |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * Copy the new string value into allocated memory for the option. |
| 1603 | * Can't use set_string_option_direct(), because we need to remove the |
| 1604 | * backslashes. |
| 1605 | */ |
| 1606 | static char_u * |
| 1607 | stropt_copy_value( |
| 1608 | char_u *origval, |
| 1609 | char_u **argp, |
| 1610 | set_op_T op, |
| 1611 | int flags UNUSED) |
| 1612 | { |
| 1613 | char_u *arg = *argp; |
| 1614 | unsigned newlen; |
| 1615 | char_u *newval; |
| 1616 | char_u *s = NULL; |
| 1617 | |
| 1618 | // get a bit too much |
| 1619 | newlen = (unsigned)STRLEN(arg) + 1; |
| 1620 | if (op != OP_NONE) |
| 1621 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1622 | newval = alloc(newlen); |
| 1623 | if (newval == NULL) // out of mem, don't change |
| 1624 | return NULL; |
| 1625 | s = newval; |
| 1626 | |
| 1627 | // Copy the string, skip over escaped chars. |
| 1628 | // For MS-DOS and WIN32 backslashes before normal file name characters |
| 1629 | // are not removed, and keep backslash at start, for "\\machine\path", |
| 1630 | // but do remove it for "\\\\machine\\path". |
| 1631 | // The reverse is found in ExpandOldSetting(). |
| 1632 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
| 1633 | { |
| 1634 | int i; |
| 1635 | |
| 1636 | if (*arg == '\\' && arg[1] != NUL |
| 1637 | #ifdef BACKSLASH_IN_FILENAME |
| 1638 | && !((flags & P_EXPAND) |
| 1639 | && vim_isfilec(arg[1]) |
| 1640 | && !VIM_ISWHITE(arg[1]) |
| 1641 | && (arg[1] != '\\' |
| 1642 | || (s == newval && arg[2] != '\\'))) |
| 1643 | #endif |
| 1644 | ) |
| 1645 | ++arg; // remove backslash |
| 1646 | if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) |
| 1647 | { |
| 1648 | // copy multibyte char |
| 1649 | mch_memmove(s, arg, (size_t)i); |
| 1650 | arg += i; |
| 1651 | s += i; |
| 1652 | } |
| 1653 | else |
| 1654 | *s++ = *arg++; |
| 1655 | } |
| 1656 | *s = NUL; |
| 1657 | |
| 1658 | *argp = arg; |
| 1659 | return newval; |
| 1660 | } |
| 1661 | |
| 1662 | /* |
| 1663 | * Expand environment variables and ~ in string option value 'newval'. |
| 1664 | */ |
| 1665 | static char_u * |
| 1666 | stropt_expand_envvar( |
| 1667 | int opt_idx, |
| 1668 | char_u *origval, |
| 1669 | char_u *newval, |
| 1670 | set_op_T op) |
| 1671 | { |
| 1672 | char_u *s = option_expand(opt_idx, newval); |
| 1673 | if (s == NULL) |
| 1674 | return newval; |
| 1675 | |
| 1676 | vim_free(newval); |
| 1677 | unsigned newlen = (unsigned)STRLEN(s) + 1; |
| 1678 | if (op != OP_NONE) |
| 1679 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1680 | |
| 1681 | newval = alloc(newlen); |
| 1682 | if (newval == NULL) |
| 1683 | return NULL; |
| 1684 | |
| 1685 | STRCPY(newval, s); |
| 1686 | |
| 1687 | return newval; |
| 1688 | } |
| 1689 | |
| 1690 | /* |
| 1691 | * Concatenate the original and new values of a string option, adding a "," if |
| 1692 | * needed. |
| 1693 | */ |
| 1694 | static void |
| 1695 | stropt_concat_with_comma( |
| 1696 | char_u *origval, |
| 1697 | char_u *newval, |
| 1698 | set_op_T op, |
| 1699 | int flags) |
| 1700 | { |
| 1701 | int len = 0; |
| 1702 | |
| 1703 | int comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); |
| 1704 | if (op == OP_ADDING) |
| 1705 | { |
| 1706 | len = (int)STRLEN(origval); |
| 1707 | // strip a trailing comma, would get 2 |
| 1708 | if (comma && len > 1 |
| 1709 | && (flags & P_ONECOMMA) == P_ONECOMMA |
| 1710 | && origval[len - 1] == ',' |
| 1711 | && origval[len - 2] != '\\') |
| 1712 | len--; |
| 1713 | mch_memmove(newval + len + comma, newval, STRLEN(newval) + 1); |
| 1714 | mch_memmove(newval, origval, (size_t)len); |
| 1715 | } |
| 1716 | else |
| 1717 | { |
| 1718 | len = (int)STRLEN(newval); |
| 1719 | STRMOVE(newval + len + comma, origval); |
| 1720 | } |
| 1721 | if (comma) |
| 1722 | newval[len] = ','; |
| 1723 | } |
| 1724 | |
| 1725 | /* |
| 1726 | * Remove a value from a string option. Copy string option value in "origval" |
| 1727 | * to "newval" and then remove the string "strval" of length "len". |
| 1728 | */ |
| 1729 | static void |
| 1730 | stropt_remove_val( |
| 1731 | char_u *origval, |
| 1732 | char_u *newval, |
| 1733 | int flags, |
| 1734 | char_u *strval, |
| 1735 | int len) |
| 1736 | { |
| 1737 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1738 | // and is used here). |
| 1739 | STRCPY(newval, origval); |
| 1740 | if (*strval) |
| 1741 | { |
| 1742 | // may need to remove a comma |
| 1743 | if (flags & P_COMMA) |
| 1744 | { |
| 1745 | if (strval == origval) |
| 1746 | { |
| 1747 | // include comma after string |
| 1748 | if (strval[len] == ',') |
| 1749 | ++len; |
| 1750 | } |
| 1751 | else |
| 1752 | { |
| 1753 | // include comma before string |
| 1754 | --strval; |
| 1755 | ++len; |
| 1756 | } |
| 1757 | } |
| 1758 | STRMOVE(newval + (strval - origval), strval + len); |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | /* |
| 1763 | * Remove flags that appear twice in the string option value 'newval'. |
| 1764 | */ |
| 1765 | static void |
| 1766 | stropt_remove_dupflags(char_u *newval, int flags) |
| 1767 | { |
| 1768 | char_u *s = newval; |
| 1769 | |
| 1770 | // Remove flags that appear twice. |
| 1771 | while (*s) |
| 1772 | { |
| 1773 | // if options have P_FLAGLIST and P_ONECOMMA such as 'whichwrap' |
| 1774 | if (flags & P_ONECOMMA) |
| 1775 | { |
| 1776 | if (*s != ',' && *(s + 1) == ',' && vim_strchr(s + 2, *s) != NULL) |
| 1777 | { |
| 1778 | // Remove the duplicated value and the next comma. |
| 1779 | STRMOVE(s, s + 2); |
| 1780 | continue; |
| 1781 | } |
| 1782 | } |
| 1783 | else |
| 1784 | { |
| 1785 | if ((!(flags & P_COMMA) || *s != ',') |
| 1786 | && vim_strchr(s + 1, *s) != NULL) |
| 1787 | { |
| 1788 | STRMOVE(s, s + 1); |
| 1789 | continue; |
| 1790 | } |
| 1791 | } |
| 1792 | ++s; |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | /* |
| 1797 | * Get the string value specified for a ":set" command. The following set |
| 1798 | * options are supported: |
| 1799 | * set {opt}& |
| 1800 | * set {opt}< |
| 1801 | * set {opt}={val} |
| 1802 | * set {opt}:{val} |
| 1803 | */ |
| 1804 | static char_u * |
| 1805 | stropt_get_newval( |
| 1806 | int nextchar, |
| 1807 | int opt_idx, |
| 1808 | char_u **argp, |
| 1809 | char_u *varp, |
| 1810 | char_u **origval_arg, |
| 1811 | char_u **origval_l_arg, |
| 1812 | char_u **origval_g_arg, |
| 1813 | char_u **oldval_arg, |
| 1814 | set_op_T *op_arg, |
| 1815 | int flags, |
| 1816 | int cp_val) |
| 1817 | { |
| 1818 | char_u *arg = *argp; |
| 1819 | char_u *origval = *origval_arg; |
| 1820 | char_u *origval_l = *origval_l_arg; |
| 1821 | char_u *origval_g = *origval_g_arg; |
| 1822 | char_u *oldval = *oldval_arg; |
| 1823 | set_op_T op = *op_arg; |
| 1824 | char_u *save_arg = NULL; |
| 1825 | char_u *newval; |
| 1826 | char_u *s = NULL; |
| 1827 | char_u whichwrap[80]; |
| 1828 | |
| 1829 | if (nextchar == '&') // set to default val |
| 1830 | newval = stropt_get_default_val(opt_idx, varp, flags, cp_val); |
| 1831 | else if (nextchar == '<') // set to global val |
| 1832 | newval = vim_strsave(*(char_u **)get_varp_scope( |
| 1833 | &(options[opt_idx]), OPT_GLOBAL)); |
| 1834 | else |
| 1835 | { |
| 1836 | ++arg; // jump to after the '=' or ':' |
| 1837 | |
| 1838 | // Set 'keywordprg' to ":help" if an empty |
| 1839 | // value was passed to :set by the user. |
| 1840 | if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' ')) |
| 1841 | { |
| 1842 | save_arg = arg; |
| 1843 | arg = (char_u *)":help"; |
| 1844 | } |
| 1845 | // Convert 'backspace' number to string |
| 1846 | else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) |
| 1847 | opt_backspace_nr2str(varp, &origval, &origval_l, &origval_g, |
| 1848 | &oldval); |
| 1849 | else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) |
| 1850 | { |
| 1851 | // Convert 'whichwrap' number to string, for backwards |
| 1852 | // compatibility with Vim 3.0. |
| 1853 | char_u *t = opt_whichwrap_nr2str(&arg, whichwrap); |
| 1854 | save_arg = arg; |
| 1855 | arg = t; |
| 1856 | } |
| 1857 | // Remove '>' before 'dir' and 'bdir', for backwards compatibility with |
| 1858 | // version 3.0 |
| 1859 | else if (*arg == '>' && (varp == (char_u *)&p_dir |
| 1860 | || varp == (char_u *)&p_bdir)) |
| 1861 | ++arg; |
| 1862 | |
| 1863 | // Copy the new string into allocated memory. |
| 1864 | newval = stropt_copy_value(origval, &arg, op, flags); |
| 1865 | if (newval == NULL) |
| 1866 | goto done; |
| 1867 | |
| 1868 | // Expand environment variables and ~. |
| 1869 | // Don't do it when adding without inserting a comma. |
| 1870 | if (op == OP_NONE || (flags & P_COMMA)) |
| 1871 | { |
| 1872 | newval = stropt_expand_envvar(opt_idx, origval, newval, op); |
| 1873 | if (newval == NULL) |
| 1874 | goto done; |
| 1875 | } |
| 1876 | |
| 1877 | // locate newval[] in origval[] when removing it and when adding to |
| 1878 | // avoid duplicates |
| 1879 | int len = 0; |
| 1880 | if (op == OP_REMOVING || (flags & P_NODUP)) |
| 1881 | { |
| 1882 | len = (int)STRLEN(newval); |
| 1883 | s = find_dup_item(origval, newval, flags); |
| 1884 | |
| 1885 | // do not add if already there |
| 1886 | if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) |
| 1887 | { |
| 1888 | op = OP_NONE; |
| 1889 | STRCPY(newval, origval); |
| 1890 | } |
| 1891 | |
| 1892 | // if no duplicate, move pointer to end of original value |
| 1893 | if (s == NULL) |
| 1894 | s = origval + (int)STRLEN(origval); |
| 1895 | } |
| 1896 | |
| 1897 | // concatenate the two strings; add a ',' if needed |
| 1898 | if (op == OP_ADDING || op == OP_PREPENDING) |
| 1899 | stropt_concat_with_comma(origval, newval, op, flags); |
| 1900 | else if (op == OP_REMOVING) |
| 1901 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1902 | // and is used here). |
| 1903 | stropt_remove_val(origval, newval, flags, s, len); |
| 1904 | |
| 1905 | if (flags & P_FLAGLIST) |
| 1906 | // Remove flags that appear twice. |
| 1907 | stropt_remove_dupflags(newval, flags); |
| 1908 | } |
| 1909 | |
| 1910 | done: |
| 1911 | if (save_arg != NULL) |
| 1912 | arg = save_arg; // arg was temporarily changed, restore it |
| 1913 | *argp = arg; |
| 1914 | *origval_arg = origval; |
| 1915 | *origval_l_arg = origval_l; |
| 1916 | *origval_g_arg = origval_g; |
| 1917 | *oldval_arg = oldval; |
| 1918 | *op_arg = op; |
| 1919 | |
| 1920 | return newval; |
| 1921 | } |
| 1922 | |
| 1923 | /* |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1924 | * Part of do_set() for string options. |
| 1925 | * Returns FAIL on failure, do not process further options. |
| 1926 | */ |
| 1927 | static int |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1928 | do_set_option_string( |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1929 | int opt_idx, |
| 1930 | int opt_flags, |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1931 | char_u **argp, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1932 | int nextchar, |
| 1933 | set_op_T op_arg, |
| 1934 | int flags, |
| 1935 | int cp_val, |
| 1936 | char_u *varp_arg, |
| 1937 | char *errbuf, |
| 1938 | int *value_checked, |
| 1939 | char **errmsg) |
| 1940 | { |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1941 | char_u *arg = *argp; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1942 | set_op_T op = op_arg; |
| 1943 | char_u *varp = varp_arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1944 | char_u *oldval = NULL; // previous value if *varp |
| 1945 | char_u *newval; |
| 1946 | char_u *origval = NULL; |
| 1947 | char_u *origval_l = NULL; |
| 1948 | char_u *origval_g = NULL; |
| 1949 | #if defined(FEAT_EVAL) |
| 1950 | char_u *saved_origval = NULL; |
| 1951 | char_u *saved_origval_l = NULL; |
| 1952 | char_u *saved_origval_g = NULL; |
| 1953 | char_u *saved_newval = NULL; |
| 1954 | #endif |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1955 | |
| 1956 | // When using ":set opt=val" for a global option |
| 1957 | // with a local value the local value will be |
| 1958 | // reset, use the global value here. |
| 1959 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
| 1960 | && ((int)options[opt_idx].indir & PV_BOTH)) |
| 1961 | varp = options[opt_idx].var; |
| 1962 | |
| 1963 | // The old value is kept until we are sure that the new value is valid. |
| 1964 | oldval = *(char_u **)varp; |
| 1965 | |
| 1966 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 1967 | { |
| 1968 | origval_l = *(char_u **)get_varp_scope( |
| 1969 | &(options[opt_idx]), OPT_LOCAL); |
| 1970 | origval_g = *(char_u **)get_varp_scope( |
| 1971 | &(options[opt_idx]), OPT_GLOBAL); |
| 1972 | |
| 1973 | // A global-local string option might have an empty option as value to |
| 1974 | // indicate that the global value should be used. |
| 1975 | if (((int)options[opt_idx].indir & PV_BOTH) |
| 1976 | && origval_l == empty_option) |
| 1977 | origval_l = origval_g; |
| 1978 | } |
| 1979 | |
| 1980 | // When setting the local value of a global option, the old value may be |
| 1981 | // the global value. |
| 1982 | if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) |
| 1983 | origval = *(char_u **)get_varp(&options[opt_idx]); |
| 1984 | else |
| 1985 | origval = oldval; |
| 1986 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1987 | // Get the new value for the option |
| 1988 | newval = stropt_get_newval(nextchar, opt_idx, &arg, varp, &origval, |
| 1989 | &origval_l, &origval_g, &oldval, &op, flags, |
| 1990 | cp_val); |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1991 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1992 | // Set the new value. |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1993 | *(char_u **)(varp) = newval; |
Bram Moolenaar | 339e114 | 2023-02-15 14:26:25 +0000 | [diff] [blame] | 1994 | if (newval == NULL) |
| 1995 | *(char_u **)(varp) = empty_option; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1996 | |
| 1997 | #if defined(FEAT_EVAL) |
| 1998 | if (!starting |
| 1999 | # ifdef FEAT_CRYPT |
| 2000 | && options[opt_idx].indir != PV_KEY |
| 2001 | # endif |
| 2002 | && origval != NULL && newval != NULL) |
| 2003 | { |
| 2004 | // origval may be freed by did_set_string_option(), make a copy. |
| 2005 | saved_origval = vim_strsave(origval); |
| 2006 | // newval (and varp) may become invalid if the buffer is closed by |
| 2007 | // autocommands. |
| 2008 | saved_newval = vim_strsave(newval); |
| 2009 | if (origval_l != NULL) |
| 2010 | saved_origval_l = vim_strsave(origval_l); |
| 2011 | if (origval_g != NULL) |
| 2012 | saved_origval_g = vim_strsave(origval_g); |
| 2013 | } |
| 2014 | #endif |
| 2015 | |
| 2016 | { |
| 2017 | long_u *p = insecure_flag(opt_idx, opt_flags); |
| 2018 | int secure_saved = secure; |
| 2019 | |
| 2020 | // When an option is set in the sandbox, from a modeline or in secure |
| 2021 | // mode, then deal with side effects in secure mode. Also when the |
| 2022 | // value was set with the P_INSECURE flag and is not completely |
| 2023 | // replaced. |
| 2024 | if ((opt_flags & OPT_MODELINE) |
| 2025 | #ifdef HAVE_SANDBOX |
| 2026 | || sandbox != 0 |
| 2027 | #endif |
| 2028 | || (op != OP_NONE && (*p & P_INSECURE))) |
| 2029 | secure = 1; |
| 2030 | |
| 2031 | // Handle side effects, and set the global value for ":set" on local |
| 2032 | // options. Note: when setting 'syntax' or 'filetype' autocommands may |
| 2033 | // be triggered that can cause havoc. |
| 2034 | *errmsg = did_set_string_option( |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2035 | opt_idx, (char_u **)varp, oldval, newval, errbuf, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2036 | opt_flags, value_checked); |
| 2037 | |
| 2038 | secure = secure_saved; |
| 2039 | } |
| 2040 | |
| 2041 | #if defined(FEAT_EVAL) |
| 2042 | if (*errmsg == NULL) |
zeertzjq | 269aa2b | 2022-11-28 11:36:50 +0000 | [diff] [blame] | 2043 | trigger_optionset_string(opt_idx, opt_flags, saved_origval, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2044 | saved_origval_l, saved_origval_g, saved_newval); |
| 2045 | vim_free(saved_origval); |
| 2046 | vim_free(saved_origval_l); |
| 2047 | vim_free(saved_origval_g); |
| 2048 | vim_free(saved_newval); |
| 2049 | #endif |
| 2050 | |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 2051 | *argp = arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2052 | return *errmsg == NULL ? OK : FAIL; |
| 2053 | } |
| 2054 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2055 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2056 | * Set a boolean option. |
| 2057 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2058 | */ |
| 2059 | static char * |
| 2060 | do_set_option_bool( |
| 2061 | int opt_idx, |
| 2062 | int opt_flags, |
| 2063 | set_prefix_T prefix, |
| 2064 | long_u flags, |
| 2065 | char_u *varp, |
| 2066 | int nextchar, |
| 2067 | int afterchar, |
| 2068 | int cp_val) |
| 2069 | |
| 2070 | { |
| 2071 | varnumber_T value; |
| 2072 | |
| 2073 | if (nextchar == '=' || nextchar == ':') |
| 2074 | return e_invalid_argument; |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2075 | if (opt_idx < 0 || varp == NULL) |
| 2076 | return NULL; // "cannot happen" |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2077 | |
| 2078 | /* |
| 2079 | * ":set opt!": invert |
| 2080 | * ":set opt&": reset to default value |
| 2081 | * ":set opt<": reset to global value |
| 2082 | */ |
| 2083 | if (nextchar == '!') |
| 2084 | value = *(int *)(varp) ^ 1; |
| 2085 | else if (nextchar == '&') |
| 2086 | value = (int)(long)(long_i)options[opt_idx].def_val[ |
| 2087 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2088 | else if (nextchar == '<') |
| 2089 | { |
| 2090 | // For 'autoread' -1 means to use global value. |
| 2091 | if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL) |
| 2092 | value = -1; |
| 2093 | else |
| 2094 | value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2095 | } |
| 2096 | else |
| 2097 | { |
| 2098 | /* |
| 2099 | * ":set invopt": invert |
| 2100 | * ":set opt" or ":set noopt": set or reset |
| 2101 | */ |
| 2102 | if (nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2103 | return e_trailing_characters; |
| 2104 | if (prefix == PREFIX_INV) |
| 2105 | value = *(int *)(varp) ^ 1; |
| 2106 | else |
| 2107 | value = prefix == PREFIX_NO ? 0 : 1; |
| 2108 | } |
| 2109 | |
| 2110 | return set_bool_option(opt_idx, varp, (int)value, opt_flags); |
| 2111 | } |
| 2112 | |
| 2113 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2114 | * Set a numeric option. |
| 2115 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2116 | */ |
| 2117 | static char * |
| 2118 | do_set_option_numeric( |
| 2119 | int opt_idx, |
| 2120 | int opt_flags, |
| 2121 | char_u **argp, |
| 2122 | int nextchar, |
| 2123 | set_op_T op, |
| 2124 | long_u flags, |
| 2125 | int cp_val, |
| 2126 | char_u *varp, |
| 2127 | char *errbuf, |
| 2128 | size_t errbuflen) |
| 2129 | { |
| 2130 | char_u *arg = *argp; |
| 2131 | varnumber_T value; |
| 2132 | int i; |
| 2133 | char *errmsg = NULL; |
| 2134 | |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2135 | if (opt_idx < 0 || varp == NULL) |
| 2136 | return NULL; // "cannot happen" |
| 2137 | // |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2138 | /* |
| 2139 | * Different ways to set a number option: |
| 2140 | * & set to default value |
| 2141 | * < set to global value |
| 2142 | * <xx> accept special key codes for 'wildchar' |
| 2143 | * c accept any non-digit for 'wildchar' |
| 2144 | * [-]0-9 set number |
| 2145 | * other error |
| 2146 | */ |
| 2147 | ++arg; |
| 2148 | if (nextchar == '&') |
| 2149 | value = (long)(long_i)options[opt_idx].def_val[ |
| 2150 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2151 | else if (nextchar == '<') |
| 2152 | { |
| 2153 | // For 'undolevels' NO_LOCAL_UNDOLEVEL means to |
| 2154 | // use the global value. |
| 2155 | if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) |
| 2156 | value = NO_LOCAL_UNDOLEVEL; |
| 2157 | else |
| 2158 | value = *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2159 | } |
| 2160 | else if (((long *)varp == &p_wc || (long *)varp == &p_wcm) |
| 2161 | && (*arg == '<' |
| 2162 | || *arg == '^' |
| 2163 | || (*arg != NUL |
| 2164 | && (!arg[1] || VIM_ISWHITE(arg[1])) |
| 2165 | && !VIM_ISDIGIT(*arg)))) |
| 2166 | { |
| 2167 | value = string_to_key(arg, FALSE); |
| 2168 | if (value == 0 && (long *)varp != &p_wcm) |
| 2169 | { |
| 2170 | errmsg = e_invalid_argument; |
| 2171 | goto skip; |
| 2172 | } |
| 2173 | } |
| 2174 | else if (*arg == '-' || VIM_ISDIGIT(*arg)) |
| 2175 | { |
| 2176 | // Allow negative (for 'undolevels'), octal and hex numbers. |
| 2177 | vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, TRUE); |
| 2178 | if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i]))) |
| 2179 | { |
| 2180 | errmsg = e_number_required_after_equal; |
| 2181 | goto skip; |
| 2182 | } |
| 2183 | } |
| 2184 | else |
| 2185 | { |
| 2186 | errmsg = e_number_required_after_equal; |
| 2187 | goto skip; |
| 2188 | } |
| 2189 | |
| 2190 | if (op == OP_ADDING) |
| 2191 | value = *(long *)varp + value; |
| 2192 | else if (op == OP_PREPENDING) |
| 2193 | value = *(long *)varp * value; |
| 2194 | else if (op == OP_REMOVING) |
| 2195 | value = *(long *)varp - value; |
| 2196 | |
| 2197 | errmsg = set_num_option(opt_idx, varp, value, errbuf, errbuflen, |
| 2198 | opt_flags); |
| 2199 | |
| 2200 | skip: |
| 2201 | *argp = arg; |
| 2202 | return errmsg; |
| 2203 | } |
| 2204 | |
| 2205 | /* |
| 2206 | * Set a key code (t_xx) option |
| 2207 | */ |
| 2208 | static char * |
| 2209 | do_set_option_keycode(char_u **argp, char_u *key_name, int nextchar) |
| 2210 | { |
| 2211 | char_u *arg = *argp; |
| 2212 | char_u *p; |
| 2213 | |
| 2214 | if (nextchar == '&') |
| 2215 | { |
| 2216 | if (add_termcap_entry(key_name, TRUE) == FAIL) |
| 2217 | return e_not_found_in_termcap; |
| 2218 | } |
| 2219 | else |
| 2220 | { |
| 2221 | ++arg; // jump to after the '=' or ':' |
| 2222 | for (p = arg; *p && !VIM_ISWHITE(*p); ++p) |
| 2223 | if (*p == '\\' && p[1] != NUL) |
| 2224 | ++p; |
| 2225 | nextchar = *p; |
| 2226 | *p = NUL; |
| 2227 | add_termcode(key_name, arg, FALSE); |
| 2228 | *p = nextchar; |
| 2229 | } |
| 2230 | if (full_screen) |
| 2231 | ttest(FALSE); |
| 2232 | redraw_all_later(UPD_CLEAR); |
| 2233 | |
| 2234 | *argp = arg; |
| 2235 | return NULL; |
| 2236 | } |
| 2237 | |
| 2238 | /* |
| 2239 | * Set an option to a new value. |
| 2240 | */ |
| 2241 | static char * |
| 2242 | do_set_option_value( |
| 2243 | int opt_idx, |
| 2244 | int opt_flags, |
| 2245 | char_u **argp, |
| 2246 | set_prefix_T prefix, |
| 2247 | set_op_T op, |
| 2248 | long_u flags, |
| 2249 | char_u *varp, |
| 2250 | char_u *key_name, |
| 2251 | int nextchar, |
| 2252 | int afterchar, |
| 2253 | int cp_val, |
| 2254 | int *stopopteval, |
| 2255 | char *errbuf, |
| 2256 | size_t errbuflen) |
| 2257 | { |
| 2258 | int value_checked = FALSE; |
| 2259 | char *errmsg = NULL; |
| 2260 | char_u *arg = *argp; |
| 2261 | |
| 2262 | if (flags & P_BOOL) |
| 2263 | { |
| 2264 | // boolean option |
| 2265 | errmsg = do_set_option_bool(opt_idx, opt_flags, prefix, flags, varp, |
| 2266 | nextchar, afterchar, cp_val); |
| 2267 | if (errmsg != NULL) |
| 2268 | goto skip; |
| 2269 | } |
| 2270 | else |
| 2271 | { |
| 2272 | // numeric or string option |
| 2273 | if (vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2274 | || prefix != PREFIX_NONE) |
| 2275 | { |
| 2276 | errmsg = e_invalid_argument; |
| 2277 | goto skip; |
| 2278 | } |
| 2279 | |
| 2280 | if (flags & P_NUM) |
| 2281 | { |
| 2282 | // numeric option |
| 2283 | errmsg = do_set_option_numeric(opt_idx, opt_flags, &arg, nextchar, |
| 2284 | op, flags, cp_val, varp, |
| 2285 | errbuf, errbuflen); |
| 2286 | if (errmsg != NULL) |
| 2287 | goto skip; |
| 2288 | } |
| 2289 | else if (opt_idx >= 0) |
| 2290 | { |
| 2291 | // string option |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 2292 | if (do_set_option_string(opt_idx, opt_flags, &arg, nextchar, op, |
| 2293 | flags, cp_val, varp, errbuf, |
| 2294 | &value_checked, &errmsg) == FAIL) |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2295 | { |
| 2296 | if (errmsg != NULL) |
| 2297 | goto skip; |
| 2298 | *stopopteval = TRUE; |
| 2299 | goto skip; |
| 2300 | } |
| 2301 | } |
| 2302 | else |
| 2303 | { |
| 2304 | // key code option |
| 2305 | errmsg = do_set_option_keycode(&arg, key_name, nextchar); |
| 2306 | if (errmsg != NULL) |
| 2307 | goto skip; |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | if (opt_idx >= 0) |
| 2312 | did_set_option(opt_idx, opt_flags, op == OP_NONE, value_checked); |
| 2313 | |
| 2314 | skip: |
| 2315 | *argp = arg; |
| 2316 | return errmsg; |
| 2317 | } |
| 2318 | |
| 2319 | /* |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2320 | * Set an option to a new value. |
| 2321 | * Return NULL if OK, return an untranslated error message when something is |
| 2322 | * wrong. "errbuf[errbuflen]" can be used to create the error message. |
| 2323 | */ |
| 2324 | static char * |
| 2325 | do_set_option( |
| 2326 | int opt_flags, |
| 2327 | char_u **argp, |
| 2328 | char_u *arg_start, |
| 2329 | char_u **startarg, |
| 2330 | int *did_show, |
| 2331 | int *stopopteval, |
| 2332 | char *errbuf, |
| 2333 | size_t errbuflen) |
| 2334 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2335 | int opt_idx; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2336 | char_u *arg; |
| 2337 | set_prefix_T prefix; // no prefix, "no" prefix or "inv" prefix |
| 2338 | set_op_T op; |
| 2339 | long_u flags; // flags for current option |
| 2340 | char_u *varp; // pointer to variable for current option |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2341 | char_u key_name[2]; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2342 | int nextchar; // next non-white char after option name |
| 2343 | int afterchar; // character just after option name |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2344 | char *errmsg = NULL; |
| 2345 | int key; |
| 2346 | int len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2347 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2348 | prefix = get_option_prefix(argp); |
| 2349 | arg = *argp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2350 | |
| 2351 | // find end of name |
| 2352 | key = 0; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2353 | if (parse_option_name(arg, &opt_idx, &len, &key) == FAIL) |
| 2354 | return e_invalid_argument; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2355 | |
| 2356 | // remember character after option name |
| 2357 | afterchar = arg[len]; |
| 2358 | |
| 2359 | if (in_vim9script()) |
| 2360 | { |
| 2361 | char_u *p = skipwhite(arg + len); |
| 2362 | |
| 2363 | // disallow white space before =val, +=val, -=val, ^=val |
| 2364 | if (p > arg + len && (p[0] == '=' |
| 2365 | || (vim_strchr((char_u *)"+-^", p[0]) != NULL |
| 2366 | && p[1] == '='))) |
| 2367 | { |
| 2368 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2369 | arg = p; |
| 2370 | *startarg = p; |
| 2371 | goto skip; |
| 2372 | } |
| 2373 | } |
| 2374 | else |
| 2375 | // skip white space, allow ":set ai ?", ":set hlsearch !" |
| 2376 | while (VIM_ISWHITE(arg[len])) |
| 2377 | ++len; |
| 2378 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2379 | op = get_opt_op(arg + len); |
| 2380 | if (op != OP_NONE) |
| 2381 | len++; |
| 2382 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2383 | nextchar = arg[len]; |
| 2384 | |
| 2385 | if (opt_idx == -1 && key == 0) // found a mismatch: skip |
| 2386 | { |
| 2387 | if (in_vim9script() && arg > arg_start |
| 2388 | && vim_strchr((char_u *)"!&<", *arg) != NULL) |
| 2389 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2390 | else |
| 2391 | errmsg = e_unknown_option; |
| 2392 | goto skip; |
| 2393 | } |
| 2394 | |
| 2395 | if (opt_idx >= 0) |
| 2396 | { |
| 2397 | if (options[opt_idx].var == NULL) // hidden option: skip |
| 2398 | { |
| 2399 | // Only give an error message when requesting the value of |
| 2400 | // a hidden option, ignore setting it. |
| 2401 | if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL |
| 2402 | && (!(options[opt_idx].flags & P_BOOL) |
| 2403 | || nextchar == '?')) |
| 2404 | errmsg = e_option_not_supported; |
| 2405 | goto skip; |
| 2406 | } |
| 2407 | |
| 2408 | flags = options[opt_idx].flags; |
| 2409 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 2410 | } |
| 2411 | else |
| 2412 | { |
| 2413 | flags = P_STRING; |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2414 | varp = NULL; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2415 | if (key < 0) |
| 2416 | { |
| 2417 | key_name[0] = KEY2TERMCAP0(key); |
| 2418 | key_name[1] = KEY2TERMCAP1(key); |
| 2419 | } |
| 2420 | else |
| 2421 | { |
| 2422 | key_name[0] = KS_KEY; |
| 2423 | key_name[1] = (key & 0xff); |
| 2424 | } |
| 2425 | } |
| 2426 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2427 | // Make sure the option value can be changed. |
| 2428 | if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg) == FAIL) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2429 | goto skip; |
| 2430 | |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2431 | int cp_val = p_cp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2432 | if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) |
| 2433 | { |
| 2434 | arg += len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2435 | if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') |
| 2436 | { |
| 2437 | if (arg[3] == 'm') // "opt&vim": set to Vim default |
| 2438 | { |
| 2439 | cp_val = FALSE; |
| 2440 | arg += 3; |
| 2441 | } |
| 2442 | else // "opt&vi": set to Vi default |
| 2443 | { |
| 2444 | cp_val = TRUE; |
| 2445 | arg += 2; |
| 2446 | } |
| 2447 | } |
| 2448 | if (vim_strchr((char_u *)"?!&<", nextchar) != NULL |
| 2449 | && arg[1] != NUL && !VIM_ISWHITE(arg[1])) |
| 2450 | { |
| 2451 | errmsg = e_trailing_characters; |
| 2452 | goto skip; |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2457 | * Allow '=' and ':' for historical reasons (MSDOS command.com). |
| 2458 | * Allows only one '=' character per "set" command line. grrr. (jw) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2459 | */ |
| 2460 | if (nextchar == '?' |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2461 | || (prefix == PREFIX_NONE |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2462 | && vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2463 | && !(flags & P_BOOL))) |
| 2464 | { |
| 2465 | /* |
| 2466 | * print value |
| 2467 | */ |
| 2468 | if (*did_show) |
| 2469 | msg_putchar('\n'); // cursor below last one |
| 2470 | else |
| 2471 | { |
| 2472 | gotocmdline(TRUE); // cursor at status line |
| 2473 | *did_show = TRUE; // remember that we did a line |
| 2474 | } |
| 2475 | if (opt_idx >= 0) |
| 2476 | { |
| 2477 | showoneopt(&options[opt_idx], opt_flags); |
| 2478 | #ifdef FEAT_EVAL |
| 2479 | if (p_verbose > 0) |
| 2480 | { |
| 2481 | // Mention where the option was last set. |
| 2482 | if (varp == options[opt_idx].var) |
| 2483 | last_set_msg(options[opt_idx].script_ctx); |
| 2484 | else if ((int)options[opt_idx].indir & PV_WIN) |
| 2485 | last_set_msg(curwin->w_p_script_ctx[ |
| 2486 | (int)options[opt_idx].indir & PV_MASK]); |
| 2487 | else if ((int)options[opt_idx].indir & PV_BUF) |
| 2488 | last_set_msg(curbuf->b_p_script_ctx[ |
| 2489 | (int)options[opt_idx].indir & PV_MASK]); |
| 2490 | } |
| 2491 | #endif |
| 2492 | } |
| 2493 | else |
| 2494 | { |
| 2495 | char_u *p; |
| 2496 | |
| 2497 | p = find_termcode(key_name); |
| 2498 | if (p == NULL) |
| 2499 | { |
| 2500 | errmsg = e_key_code_not_set; |
| 2501 | goto skip; |
| 2502 | } |
| 2503 | else |
| 2504 | (void)show_one_termcode(key_name, p, TRUE); |
| 2505 | } |
| 2506 | if (nextchar != '?' |
| 2507 | && nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2508 | errmsg = e_trailing_characters; |
| 2509 | } |
| 2510 | else |
| 2511 | { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2512 | errmsg = do_set_option_value(opt_idx, opt_flags, &arg, prefix, op, |
| 2513 | flags, varp, key_name, nextchar, |
| 2514 | afterchar, cp_val, stopopteval, errbuf, |
| 2515 | errbuflen); |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | skip: |
| 2519 | *argp = arg; |
| 2520 | return errmsg; |
| 2521 | } |
| 2522 | |
| 2523 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2524 | * Parse 'arg' for option settings. |
| 2525 | * |
| 2526 | * 'arg' may be IObuff, but only when no errors can be present and option |
| 2527 | * does not need to be expanded with option_expand(). |
| 2528 | * "opt_flags": |
| 2529 | * 0 for ":set" |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2530 | * OPT_GLOBAL for ":setglobal" |
| 2531 | * OPT_LOCAL for ":setlocal" and a modeline |
| 2532 | * OPT_MODELINE for a modeline |
| 2533 | * OPT_WINONLY to only set window-local options |
| 2534 | * OPT_NOWIN to skip setting window-local options |
| 2535 | * OPT_ONECOLUMN do not use multiple columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2536 | * |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2537 | * Returns FAIL if an error is detected, OK otherwise. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2538 | */ |
| 2539 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2540 | do_set( |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2541 | char_u *arg_start, // option string (may be written to!) |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2542 | int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2543 | { |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2544 | char_u *arg = arg_start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2545 | int i; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2546 | int did_show = FALSE; // already showed one value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2547 | |
| 2548 | if (*arg == NUL) |
| 2549 | { |
| 2550 | showoptions(0, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2551 | did_show = TRUE; |
| 2552 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2555 | while (*arg != NUL) // loop to process all options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2556 | { |
zeertzjq | 0ef9a5c | 2023-01-17 21:38:25 +0000 | [diff] [blame] | 2557 | if (STRNCMP(arg, "all", 3) == 0 && !ASCII_ISALPHA(arg[3]) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2558 | && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2559 | { |
| 2560 | /* |
| 2561 | * ":set all" show all options. |
| 2562 | * ":set all&" set all options to their default value. |
| 2563 | */ |
| 2564 | arg += 3; |
| 2565 | if (*arg == '&') |
| 2566 | { |
| 2567 | ++arg; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2568 | // Only for :set command set global value of local options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2569 | set_options_default(OPT_FREE | opt_flags); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2570 | didset_options(); |
| 2571 | didset_options2(); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 2572 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2573 | } |
| 2574 | else |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2575 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2576 | showoptions(1, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2577 | did_show = TRUE; |
| 2578 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2579 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2580 | else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2581 | { |
| 2582 | showoptions(2, opt_flags); |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2583 | show_termcodes(opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2584 | did_show = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2585 | arg += 7; |
| 2586 | } |
| 2587 | else |
| 2588 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2589 | int stopopteval = FALSE; |
| 2590 | char *errmsg = NULL; |
| 2591 | char errbuf[80]; |
| 2592 | char_u *startarg = arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2593 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2594 | errmsg = do_set_option(opt_flags, &arg, arg_start, &startarg, |
| 2595 | &did_show, &stopopteval, errbuf, |
| 2596 | sizeof(errbuf)); |
| 2597 | if (stopopteval) |
| 2598 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2599 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2600 | /* |
| 2601 | * Advance to next argument. |
| 2602 | * - skip until a blank found, taking care of backslashes |
| 2603 | * - skip blanks |
| 2604 | * - skip one "=val" argument (for hidden options ":set gfn =xx") |
| 2605 | */ |
| 2606 | for (i = 0; i < 2 ; ++i) |
| 2607 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 2608 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2609 | if (*arg++ == '\\' && *arg != NUL) |
| 2610 | ++arg; |
| 2611 | arg = skipwhite(arg); |
| 2612 | if (*arg != '=') |
| 2613 | break; |
| 2614 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2615 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2616 | if (errmsg != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2617 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2618 | vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1); |
| 2619 | i = (int)STRLEN(IObuff) + 2; |
| 2620 | if (i + (arg - startarg) < IOSIZE) |
| 2621 | { |
| 2622 | // append the argument with the error |
| 2623 | STRCAT(IObuff, ": "); |
| 2624 | mch_memmove(IObuff + i, startarg, (arg - startarg)); |
| 2625 | IObuff[i + (arg - startarg)] = NUL; |
| 2626 | } |
| 2627 | // make sure all characters are printable |
| 2628 | trans_characters(IObuff, IOSIZE); |
| 2629 | |
| 2630 | ++no_wait_return; // wait_return() done later |
| 2631 | emsg((char *)IObuff); // show error highlighted |
| 2632 | --no_wait_return; |
| 2633 | |
| 2634 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2635 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | arg = skipwhite(arg); |
| 2639 | } |
| 2640 | |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2641 | theend: |
| 2642 | if (silent_mode && did_show) |
| 2643 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2644 | // After displaying option values in silent mode. |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2645 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2646 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2647 | msg_putchar('\n'); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2648 | cursor_on(); // msg_start() switches it off |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2649 | out_flush(); |
| 2650 | silent_mode = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2651 | info_message = FALSE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2654 | return OK; |
| 2655 | } |
| 2656 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2657 | /* |
| 2658 | * Call this when an option has been given a new value through a user command. |
| 2659 | * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. |
| 2660 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2661 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2662 | did_set_option( |
| 2663 | int opt_idx, |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2664 | int opt_flags, // possibly with OPT_MODELINE |
| 2665 | int new_value, // value was replaced completely |
| 2666 | int value_checked) // value was checked to be safe, no need to set the |
| 2667 | // P_INSECURE flag. |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2668 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2669 | long_u *p; |
| 2670 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2671 | options[opt_idx].flags |= P_WAS_SET; |
| 2672 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2673 | // When an option is set in the sandbox, from a modeline or in secure mode |
| 2674 | // set the P_INSECURE flag. Otherwise, if a new value is stored reset the |
| 2675 | // flag. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2676 | p = insecure_flag(opt_idx, opt_flags); |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2677 | if (!value_checked && (secure |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2678 | #ifdef HAVE_SANDBOX |
| 2679 | || sandbox != 0 |
| 2680 | #endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2681 | || (opt_flags & OPT_MODELINE))) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2682 | *p = *p | P_INSECURE; |
| 2683 | else if (new_value) |
| 2684 | *p = *p & ~P_INSECURE; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2687 | /* |
| 2688 | * Convert a key name or string into a key value. |
| 2689 | * Used for 'wildchar' and 'cedit' options. |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2690 | * When "multi_byte" is TRUE allow for multi-byte characters. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2691 | */ |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2692 | int |
| 2693 | string_to_key(char_u *arg, int multi_byte) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2694 | { |
| 2695 | if (*arg == '<') |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 2696 | return find_key_option(arg + 1, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2697 | if (*arg == '^') |
| 2698 | return Ctrl_chr(arg[1]); |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2699 | if (multi_byte) |
| 2700 | return PTR2CHAR(arg); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2701 | return *arg; |
| 2702 | } |
| 2703 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2704 | /* |
| 2705 | * When changing 'title', 'titlestring', 'icon' or 'iconstring', call |
| 2706 | * maketitle() to create and display it. |
| 2707 | * When switching the title or icon off, call mch_restore_title() to get |
| 2708 | * the old value back. |
| 2709 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2710 | void |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 2711 | did_set_title(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2712 | { |
| 2713 | if (starting != NO_SCREEN |
| 2714 | #ifdef FEAT_GUI |
| 2715 | && !gui.starting |
| 2716 | #endif |
| 2717 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2718 | maketitle(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2719 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2720 | |
| 2721 | /* |
| 2722 | * set_options_bin - called when 'bin' changes value. |
| 2723 | */ |
| 2724 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2725 | set_options_bin( |
| 2726 | int oldval, |
| 2727 | int newval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2728 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2729 | { |
| 2730 | /* |
| 2731 | * The option values that are changed when 'bin' changes are |
| 2732 | * copied when 'bin is set and restored when 'bin' is reset. |
| 2733 | */ |
| 2734 | if (newval) |
| 2735 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2736 | if (!oldval) // switched on |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2737 | { |
| 2738 | if (!(opt_flags & OPT_GLOBAL)) |
| 2739 | { |
| 2740 | curbuf->b_p_tw_nobin = curbuf->b_p_tw; |
| 2741 | curbuf->b_p_wm_nobin = curbuf->b_p_wm; |
| 2742 | curbuf->b_p_ml_nobin = curbuf->b_p_ml; |
| 2743 | curbuf->b_p_et_nobin = curbuf->b_p_et; |
| 2744 | } |
| 2745 | if (!(opt_flags & OPT_LOCAL)) |
| 2746 | { |
| 2747 | p_tw_nobin = p_tw; |
| 2748 | p_wm_nobin = p_wm; |
| 2749 | p_ml_nobin = p_ml; |
| 2750 | p_et_nobin = p_et; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | if (!(opt_flags & OPT_GLOBAL)) |
| 2755 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2756 | curbuf->b_p_tw = 0; // no automatic line wrap |
| 2757 | curbuf->b_p_wm = 0; // no automatic line wrap |
| 2758 | curbuf->b_p_ml = 0; // no modelines |
| 2759 | curbuf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2760 | } |
| 2761 | if (!(opt_flags & OPT_LOCAL)) |
| 2762 | { |
| 2763 | p_tw = 0; |
| 2764 | p_wm = 0; |
| 2765 | p_ml = FALSE; |
| 2766 | p_et = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2767 | p_bin = TRUE; // needed when called for the "-b" argument |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2768 | } |
| 2769 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2770 | else if (oldval) // switched off |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2771 | { |
| 2772 | if (!(opt_flags & OPT_GLOBAL)) |
| 2773 | { |
| 2774 | curbuf->b_p_tw = curbuf->b_p_tw_nobin; |
| 2775 | curbuf->b_p_wm = curbuf->b_p_wm_nobin; |
| 2776 | curbuf->b_p_ml = curbuf->b_p_ml_nobin; |
| 2777 | curbuf->b_p_et = curbuf->b_p_et_nobin; |
| 2778 | } |
| 2779 | if (!(opt_flags & OPT_LOCAL)) |
| 2780 | { |
| 2781 | p_tw = p_tw_nobin; |
| 2782 | p_wm = p_wm_nobin; |
| 2783 | p_ml = p_ml_nobin; |
| 2784 | p_et = p_et_nobin; |
| 2785 | } |
| 2786 | } |
| 2787 | } |
| 2788 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2789 | /* |
| 2790 | * Expand environment variables for some string options. |
| 2791 | * These string options cannot be indirect! |
| 2792 | * If "val" is NULL expand the current value of the option. |
| 2793 | * Return pointer to NameBuff, or NULL when not expanded. |
| 2794 | */ |
| 2795 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2796 | option_expand(int opt_idx, char_u *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2797 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2798 | // if option doesn't need expansion nothing to do |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2799 | if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) |
| 2800 | return NULL; |
| 2801 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2802 | // If val is longer than MAXPATHL no meaningful expansion can be done, |
| 2803 | // expand_env() would truncate the string. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2804 | if (val != NULL && STRLEN(val) > MAXPATHL) |
| 2805 | return NULL; |
| 2806 | |
| 2807 | if (val == NULL) |
| 2808 | val = *(char_u **)options[opt_idx].var; |
| 2809 | |
| 2810 | /* |
| 2811 | * Expanding this with NameBuff, expand_env() must not be passed IObuff. |
| 2812 | * Escape spaces when expanding 'tags', they are used to separate file |
| 2813 | * names. |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2814 | * For 'spellsuggest' expand after "file:". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2815 | */ |
| 2816 | expand_env_esc(val, NameBuff, MAXPATHL, |
Bram Moolenaar | 9f0545d | 2007-09-26 20:36:32 +0000 | [diff] [blame] | 2817 | (char_u **)options[opt_idx].var == &p_tags, FALSE, |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2818 | #ifdef FEAT_SPELL |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2819 | (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : |
| 2820 | #endif |
| 2821 | NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2822 | if (STRCMP(NameBuff, val) == 0) // they are the same |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2823 | return NULL; |
| 2824 | |
| 2825 | return NameBuff; |
| 2826 | } |
| 2827 | |
| 2828 | /* |
| 2829 | * After setting various option values: recompute variables that depend on |
| 2830 | * option values. |
| 2831 | */ |
| 2832 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2833 | didset_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2834 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2835 | // initialize the table for 'iskeyword' et.al. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2836 | (void)init_chartab(); |
| 2837 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2838 | didset_string_options(); |
| 2839 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2840 | #ifdef FEAT_SPELL |
Bram Moolenaar | 8aff23a | 2005-08-19 20:40:30 +0000 | [diff] [blame] | 2841 | (void)spell_check_msm(); |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2842 | (void)spell_check_sps(); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2843 | (void)compile_cap_prog(curwin->w_s); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2844 | (void)did_set_spell_option(TRUE); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 2845 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2846 | // set cedit_key |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2847 | (void)did_set_cedit(NULL); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 2848 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2849 | // initialize the table for 'breakat'. |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2850 | did_set_breakat(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2851 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2852 | after_copy_winopt(curwin); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | /* |
| 2856 | * More side effects of setting options. |
| 2857 | */ |
| 2858 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2859 | didset_options2(void) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2860 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2861 | // Initialize the highlight_attr[] table. |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2862 | (void)highlight_changed(); |
| 2863 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2864 | // Parse default for 'wildmode' |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2865 | check_opt_wim(); |
| 2866 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2867 | // Parse default for 'listchars'. |
Bram Moolenaar | b67f0c8 | 2022-07-04 21:03:36 +0100 | [diff] [blame] | 2868 | (void)set_chars_option(curwin, &curwin->w_p_lcs, TRUE); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2869 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2870 | // Parse default for 'fillchars'. |
Bram Moolenaar | b67f0c8 | 2022-07-04 21:03:36 +0100 | [diff] [blame] | 2871 | (void)set_chars_option(curwin, &curwin->w_p_fcs, TRUE); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2872 | |
| 2873 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2874 | // Parse default for 'clipboard' |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2875 | (void)did_set_clipboard(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2876 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2877 | #ifdef FEAT_VARTABS |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2878 | vim_free(curbuf->b_p_vsts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2879 | (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2880 | vim_free(curbuf->b_p_vts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2881 | (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2882 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | /* |
| 2886 | * Check for string options that are NULL (normally only termcap options). |
| 2887 | */ |
| 2888 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2889 | check_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2890 | { |
| 2891 | int opt_idx; |
| 2892 | |
| 2893 | for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) |
| 2894 | if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) |
| 2895 | check_string_option((char_u **)get_varp(&(options[opt_idx]))); |
| 2896 | } |
| 2897 | |
| 2898 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2899 | * Return the option index found by a pointer into term_strings[]. |
| 2900 | * Return -1 if not found. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2901 | */ |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2902 | int |
| 2903 | get_term_opt_idx(char_u **p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2904 | { |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2905 | int opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2906 | |
| 2907 | for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) |
| 2908 | if (options[opt_idx].var == (char_u *)p) |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2909 | return opt_idx; |
| 2910 | return -1; // cannot happen: didn't find it! |
| 2911 | } |
| 2912 | |
| 2913 | /* |
| 2914 | * Mark a terminal option as allocated, found by a pointer into term_strings[]. |
| 2915 | * Return the option index or -1 if not found. |
| 2916 | */ |
| 2917 | int |
| 2918 | set_term_option_alloced(char_u **p) |
| 2919 | { |
| 2920 | int opt_idx = get_term_opt_idx(p); |
| 2921 | |
| 2922 | if (opt_idx >= 0) |
| 2923 | options[opt_idx].flags |= P_ALLOCED; |
| 2924 | return opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2927 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2928 | /* |
| 2929 | * Return TRUE when option "opt" was set from a modeline or in secure mode. |
| 2930 | * Return FALSE when it wasn't. |
| 2931 | * Return -1 for an unknown option. |
| 2932 | */ |
| 2933 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2934 | was_set_insecurely(char_u *opt, int opt_flags) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2935 | { |
| 2936 | int idx = findoption(opt); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2937 | long_u *flagp; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2938 | |
| 2939 | if (idx >= 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2940 | { |
| 2941 | flagp = insecure_flag(idx, opt_flags); |
| 2942 | return (*flagp & P_INSECURE) != 0; |
| 2943 | } |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 2944 | internal_error("was_set_insecurely()"); |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2945 | return -1; |
| 2946 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2947 | |
| 2948 | /* |
| 2949 | * Get a pointer to the flags used for the P_INSECURE flag of option |
| 2950 | * "opt_idx". For some local options a local flags field is used. |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 2951 | * NOTE: Caller must make sure that "curwin" is set to the window from which |
| 2952 | * the option is used. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2953 | */ |
| 2954 | static long_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2955 | insecure_flag(int opt_idx, int opt_flags) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2956 | { |
| 2957 | if (opt_flags & OPT_LOCAL) |
| 2958 | switch ((int)options[opt_idx].indir) |
| 2959 | { |
| 2960 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2961 | case PV_STL: return &curwin->w_p_stl_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2962 | #endif |
| 2963 | #ifdef FEAT_EVAL |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2964 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2965 | case PV_FDE: return &curwin->w_p_fde_flags; |
| 2966 | case PV_FDT: return &curwin->w_p_fdt_flags; |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2967 | # endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 2968 | # ifdef FEAT_BEVAL |
| 2969 | case PV_BEXPR: return &curbuf->b_p_bexpr_flags; |
| 2970 | # endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2971 | case PV_INDE: return &curbuf->b_p_inde_flags; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2972 | case PV_FEX: return &curbuf->b_p_fex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2973 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2974 | case PV_INEX: return &curbuf->b_p_inex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2975 | # endif |
| 2976 | #endif |
| 2977 | } |
| 2978 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2979 | // Nothing special, return global flags field. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2980 | return &options[opt_idx].flags; |
| 2981 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2982 | #endif |
| 2983 | |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2984 | /* |
| 2985 | * Redraw the window title and/or tab page text later. |
| 2986 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2987 | void redraw_titles(void) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2988 | { |
| 2989 | need_maketitle = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2990 | redraw_tabline = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2991 | } |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2992 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2993 | /* |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2994 | * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII |
| 2995 | * characters or characters in "allowed". |
| 2996 | */ |
Bram Moolenaar | e677df8 | 2019-09-02 22:31:11 +0200 | [diff] [blame] | 2997 | int |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2998 | valid_name(char_u *val, char *allowed) |
| 2999 | { |
| 3000 | char_u *s; |
| 3001 | |
| 3002 | for (s = val; *s != NUL; ++s) |
| 3003 | if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL) |
| 3004 | return FALSE; |
| 3005 | return TRUE; |
| 3006 | } |
| 3007 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3008 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 3009 | /* |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3010 | * 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] | 3011 | * window-local value. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3012 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 3013 | void |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3014 | 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] | 3015 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3016 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 3017 | int indir = (int)options[opt_idx].indir; |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3018 | sctx_T new_script_ctx = script_ctx; |
| 3019 | |
Bram Moolenaar | 5125874 | 2020-05-03 17:19:33 +0200 | [diff] [blame] | 3020 | // Modeline already has the line number set. |
| 3021 | if (!(opt_flags & OPT_MODELINE)) |
| 3022 | new_script_ctx.sc_lnum += SOURCING_LNUM; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3023 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3024 | // Remember where the option was set. For local options need to do that |
| 3025 | // in the buffer or window structure. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3026 | if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3027 | options[opt_idx].script_ctx = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3028 | if (both || (opt_flags & OPT_LOCAL)) |
| 3029 | { |
| 3030 | if (indir & PV_BUF) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3031 | curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3032 | else if (indir & PV_WIN) |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3033 | { |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3034 | curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3035 | if (both) |
| 3036 | // also setting the "all buffers" value |
| 3037 | curwin->w_allbuf_opt.wo_script_ctx[indir & PV_MASK] = |
| 3038 | new_script_ctx; |
| 3039 | } |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3040 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3041 | } |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3042 | |
| 3043 | /* |
Bram Moolenaar | 5600a70 | 2022-01-22 15:09:36 +0000 | [diff] [blame] | 3044 | * Get the script context of global option "name". |
| 3045 | * |
| 3046 | */ |
| 3047 | sctx_T * |
| 3048 | get_option_sctx(char *name) |
| 3049 | { |
| 3050 | int idx = findoption((char_u *)name); |
| 3051 | |
| 3052 | if (idx >= 0) |
| 3053 | return &options[idx].script_ctx; |
| 3054 | siemsg("no such option: %s", name); |
| 3055 | return NULL; |
| 3056 | } |
| 3057 | |
| 3058 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3059 | * Set the script_ctx for a termcap option. |
| 3060 | * "name" must be the two character code, e.g. "RV". |
| 3061 | * When "name" is NULL use "opt_idx". |
| 3062 | */ |
| 3063 | void |
| 3064 | set_term_option_sctx_idx(char *name, int opt_idx) |
| 3065 | { |
| 3066 | char_u buf[5]; |
| 3067 | int idx; |
| 3068 | |
| 3069 | if (name == NULL) |
| 3070 | idx = opt_idx; |
| 3071 | else |
| 3072 | { |
| 3073 | buf[0] = 't'; |
| 3074 | buf[1] = '_'; |
| 3075 | buf[2] = name[0]; |
| 3076 | buf[3] = name[1]; |
| 3077 | buf[4] = 0; |
| 3078 | idx = findoption(buf); |
| 3079 | } |
| 3080 | if (idx >= 0) |
| 3081 | set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx); |
| 3082 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3083 | #endif |
| 3084 | |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3085 | #if defined(FEAT_EVAL) |
| 3086 | /* |
| 3087 | * Apply the OptionSet autocommand. |
| 3088 | */ |
| 3089 | static void |
| 3090 | apply_optionset_autocmd( |
| 3091 | int opt_idx, |
| 3092 | long opt_flags, |
| 3093 | long oldval, |
| 3094 | long oldval_g, |
| 3095 | long newval, |
| 3096 | char *errmsg) |
| 3097 | { |
| 3098 | char_u buf_old[12], buf_old_global[12], buf_new[12], buf_type[12]; |
| 3099 | |
| 3100 | // Don't do this while starting up, failure or recursively. |
| 3101 | if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL) |
| 3102 | return; |
| 3103 | |
| 3104 | vim_snprintf((char *)buf_old, sizeof(buf_old), "%ld", oldval); |
| 3105 | vim_snprintf((char *)buf_old_global, sizeof(buf_old_global), "%ld", |
| 3106 | oldval_g); |
| 3107 | vim_snprintf((char *)buf_new, sizeof(buf_new), "%ld", newval); |
| 3108 | vim_snprintf((char *)buf_type, sizeof(buf_type), "%s", |
| 3109 | (opt_flags & OPT_LOCAL) ? "local" : "global"); |
| 3110 | set_vim_var_string(VV_OPTION_NEW, buf_new, -1); |
| 3111 | set_vim_var_string(VV_OPTION_OLD, buf_old, -1); |
| 3112 | set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
| 3113 | if (opt_flags & OPT_LOCAL) |
| 3114 | { |
| 3115 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
| 3116 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3117 | } |
| 3118 | if (opt_flags & OPT_GLOBAL) |
| 3119 | { |
| 3120 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
| 3121 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); |
| 3122 | } |
| 3123 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3124 | { |
| 3125 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
| 3126 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3127 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); |
| 3128 | } |
| 3129 | if (opt_flags & OPT_MODELINE) |
| 3130 | { |
| 3131 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
| 3132 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3133 | } |
| 3134 | apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, |
| 3135 | NULL, FALSE, NULL); |
| 3136 | reset_v_option_vars(); |
| 3137 | } |
| 3138 | #endif |
| 3139 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3140 | /* |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3141 | * Process the updated 'compatible' option value. |
| 3142 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3143 | char * |
| 3144 | did_set_compatible(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3145 | { |
| 3146 | compatible_set(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3147 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3150 | #if defined(FEAT_LANGMAP) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3151 | /* |
| 3152 | * Process the updated 'langremap' option value. |
| 3153 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3154 | char * |
| 3155 | did_set_langremap(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3156 | { |
| 3157 | // 'langremap' -> !'langnoremap' |
| 3158 | p_lnr = !p_lrm; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3159 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | /* |
| 3163 | * Process the updated 'langnoremap' option value. |
| 3164 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3165 | char * |
| 3166 | did_set_langnoremap(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3167 | { |
| 3168 | // 'langnoremap' -> !'langremap' |
| 3169 | p_lrm = !p_lnr; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3170 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3171 | } |
| 3172 | #endif |
| 3173 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3174 | #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3175 | /* |
| 3176 | * Process the updated 'undofile' option value. |
| 3177 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3178 | char * |
| 3179 | did_set_undofile(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3180 | { |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3181 | // Only take action when the option was set. |
| 3182 | if (!curbuf->b_p_udf && !p_udf) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3183 | return NULL; |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3184 | |
| 3185 | // When reset we do not delete the undo file, the option may be set again |
| 3186 | // without making any changes in between. |
| 3187 | char_u hash[UNDO_HASH_SIZE]; |
| 3188 | buf_T *save_curbuf = curbuf; |
| 3189 | |
| 3190 | FOR_ALL_BUFFERS(curbuf) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3191 | { |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3192 | // When 'undofile' is set globally: for every buffer, otherwise |
| 3193 | // only for the current buffer: Try to read in the undofile, |
| 3194 | // if one exists, the buffer wasn't changed and the buffer was |
| 3195 | // loaded |
| 3196 | if ((curbuf == save_curbuf |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3197 | || (args->os_flags & OPT_GLOBAL) |
| 3198 | || args->os_flags == 0) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3199 | && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3200 | { |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3201 | #ifdef FEAT_CRYPT |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3202 | if (crypt_get_method_nr(curbuf) == CRYPT_M_SOD) |
| 3203 | continue; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3204 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3205 | u_compute_hash(hash); |
| 3206 | u_read_undo(NULL, hash, curbuf->b_fname); |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3207 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3208 | } |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3209 | curbuf = save_curbuf; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3210 | |
| 3211 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3212 | } |
| 3213 | #endif |
| 3214 | |
| 3215 | /* |
| 3216 | * Process the updated 'readonly' option value. |
| 3217 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3218 | char * |
| 3219 | did_set_readonly(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3220 | { |
| 3221 | // when 'readonly' is reset globally, also reset readonlymode |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3222 | if (!curbuf->b_p_ro && (args->os_flags & OPT_LOCAL) == 0) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3223 | readonlymode = FALSE; |
| 3224 | |
| 3225 | // when 'readonly' is set may give W10 again |
| 3226 | if (curbuf->b_p_ro) |
| 3227 | curbuf->b_did_warn = FALSE; |
| 3228 | |
| 3229 | redraw_titles(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3230 | |
| 3231 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3234 | #if defined(FEAT_GUI) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3235 | /* |
| 3236 | * Process the updated 'mousehide' option value. |
| 3237 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3238 | char * |
| 3239 | did_set_mousehide(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3240 | { |
| 3241 | if (!p_mh) |
| 3242 | gui_mch_mousehide(FALSE); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3243 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3244 | } |
| 3245 | #endif |
| 3246 | |
| 3247 | /* |
| 3248 | * Process the updated 'modifiable' option value. |
| 3249 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3250 | char * |
| 3251 | did_set_modifiable(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3252 | { |
| 3253 | // when 'modifiable' is changed, redraw the window title |
| 3254 | |
| 3255 | # ifdef FEAT_TERMINAL |
| 3256 | // Cannot set 'modifiable' when in Terminal mode. |
| 3257 | if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) |
| 3258 | && curbuf->b_term != NULL && !term_is_finished(curbuf)))) |
| 3259 | { |
| 3260 | curbuf->b_p_ma = FALSE; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3261 | args->os_doskip = TRUE; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3262 | return e_cannot_make_terminal_with_running_job_modifiable; |
| 3263 | } |
| 3264 | # endif |
| 3265 | redraw_titles(); |
| 3266 | |
| 3267 | return NULL; |
| 3268 | } |
| 3269 | |
| 3270 | /* |
| 3271 | * Process the updated 'endoffile' or 'endofline' or 'fixendofline' or 'bomb' |
| 3272 | * option value. |
| 3273 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3274 | char * |
| 3275 | did_set_eof_eol_fixeol_bomb(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3276 | { |
| 3277 | // redraw the window title and tab page text |
| 3278 | redraw_titles(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3279 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /* |
| 3283 | * Process the updated 'binary' option value. |
| 3284 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3285 | char * |
| 3286 | did_set_binary(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3287 | { |
| 3288 | // when 'bin' is set also set some other options |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3289 | set_options_bin(args->os_oldval.boolean, curbuf->b_p_bin, args->os_flags); |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3290 | redraw_titles(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3291 | |
| 3292 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | /* |
| 3296 | * Process the updated 'buflisted' option value. |
| 3297 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3298 | char * |
| 3299 | did_set_buflisted(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3300 | { |
| 3301 | // when 'buflisted' changes, trigger autocommands |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3302 | if (args->os_oldval.boolean != curbuf->b_p_bl) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3303 | apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, |
| 3304 | NULL, NULL, TRUE, curbuf); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3305 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | /* |
| 3309 | * Process the updated 'swapfile' option value. |
| 3310 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3311 | char * |
| 3312 | did_set_swapfile(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3313 | { |
| 3314 | // when 'swf' is set, create swapfile, when reset remove swapfile |
| 3315 | if (curbuf->b_p_swf && p_uc) |
| 3316 | ml_open_file(curbuf); // create the swap file |
| 3317 | else |
| 3318 | // no need to reset curbuf->b_may_swap, ml_open_file() will check |
| 3319 | // buf->b_p_swf |
| 3320 | mf_close_file(curbuf, TRUE); // remove the swap file |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3321 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | /* |
| 3325 | * Process the updated 'terse' option value. |
| 3326 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3327 | char * |
| 3328 | did_set_terse(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3329 | { |
| 3330 | char_u *p; |
| 3331 | |
| 3332 | // when 'terse' is set change 'shortmess' |
| 3333 | p = vim_strchr(p_shm, SHM_SEARCH); |
| 3334 | |
| 3335 | // insert 's' in p_shm |
| 3336 | if (p_terse && p == NULL) |
| 3337 | { |
| 3338 | STRCPY(IObuff, p_shm); |
| 3339 | STRCAT(IObuff, "s"); |
| 3340 | set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); |
| 3341 | } |
| 3342 | // remove 's' from p_shm |
| 3343 | else if (!p_terse && p != NULL) |
| 3344 | STRMOVE(p, p + 1); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3345 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | /* |
| 3349 | * Process the updated 'paste' option value. |
| 3350 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3351 | char * |
| 3352 | did_set_paste(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3353 | { |
| 3354 | // when 'paste' is set or reset also change other options |
| 3355 | paste_option_changed(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3356 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | /* |
| 3360 | * Process the updated 'insertmode' option value. |
| 3361 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3362 | char * |
| 3363 | did_set_insertmode(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3364 | { |
| 3365 | // when 'insertmode' is set from an autocommand need to do work here |
| 3366 | if (p_im) |
| 3367 | { |
| 3368 | if ((State & MODE_INSERT) == 0) |
| 3369 | need_start_insertmode = TRUE; |
| 3370 | stop_insert_mode = FALSE; |
| 3371 | } |
| 3372 | // only reset if it was set previously |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3373 | else if (args->os_oldval.boolean) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3374 | { |
| 3375 | need_start_insertmode = FALSE; |
| 3376 | stop_insert_mode = TRUE; |
| 3377 | if (restart_edit != 0 && mode_displayed) |
| 3378 | clear_cmdline = TRUE; // remove "(insert)" |
| 3379 | restart_edit = 0; |
| 3380 | } |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3381 | |
| 3382 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | /* |
| 3386 | * Process the updated 'ignorecase' option value. |
| 3387 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3388 | char * |
| 3389 | did_set_ignorecase(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3390 | { |
| 3391 | // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw |
| 3392 | if (p_hls) |
| 3393 | redraw_all_later(UPD_SOME_VALID); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3394 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3397 | #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3398 | /* |
| 3399 | * Process the updated 'hlsearch' option value. |
| 3400 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3401 | char * |
| 3402 | did_set_hlsearch(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3403 | { |
| 3404 | // when 'hlsearch' is set or reset: reset no_hlsearch |
| 3405 | set_no_hlsearch(FALSE); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3406 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3407 | } |
| 3408 | #endif |
| 3409 | |
| 3410 | /* |
| 3411 | * Process the updated 'scrollbind' option value. |
| 3412 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3413 | char * |
| 3414 | did_set_scrollbind(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3415 | { |
| 3416 | // when 'scrollbind' is set: snapshot the current position to avoid a jump |
| 3417 | // at the end of normal_cmd() |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3418 | if (!curwin->w_p_scb) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3419 | return NULL; |
| 3420 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3421 | do_check_scrollbind(FALSE); |
| 3422 | curwin->w_scbind_pos = curwin->w_topline; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3423 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | #ifdef FEAT_QUICKFIX |
| 3427 | /* |
| 3428 | * Process the updated 'previewwindow' option value. |
| 3429 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3430 | char * |
| 3431 | did_set_previewwindow(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3432 | { |
| 3433 | if (!curwin->w_p_pvw) |
| 3434 | return NULL; |
| 3435 | |
| 3436 | // There can be only one window with 'previewwindow' set. |
| 3437 | win_T *win; |
| 3438 | |
| 3439 | FOR_ALL_WINDOWS(win) |
| 3440 | if (win->w_p_pvw && win != curwin) |
| 3441 | { |
| 3442 | curwin->w_p_pvw = FALSE; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3443 | args->os_doskip = TRUE; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3444 | return e_preview_window_already_exists; |
| 3445 | } |
| 3446 | |
| 3447 | return NULL; |
| 3448 | } |
| 3449 | #endif |
| 3450 | |
| 3451 | /* |
| 3452 | * Process the updated 'smoothscroll' option value. |
| 3453 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3454 | char * |
| 3455 | did_set_smoothscroll(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3456 | { |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3457 | if (curwin->w_p_sms) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3458 | return NULL; |
| 3459 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3460 | curwin->w_skipcol = 0; |
| 3461 | changed_line_abv_curs(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3462 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | /* |
| 3466 | * Process the updated 'textmode' option value. |
| 3467 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3468 | char * |
| 3469 | did_set_textmode(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3470 | { |
| 3471 | // when 'textmode' is set or reset also change 'fileformat' |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3472 | set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, args->os_flags); |
| 3473 | |
| 3474 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | /* |
| 3478 | * Process the updated 'textauto' option value. |
| 3479 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3480 | char * |
| 3481 | did_set_textauto(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3482 | { |
| 3483 | // when 'textauto' is set or reset also change 'fileformats' |
| 3484 | set_string_option_direct((char_u *)"ffs", -1, |
| 3485 | p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3486 | OPT_FREE | args->os_flags, 0); |
| 3487 | |
| 3488 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | /* |
| 3492 | * Process the updated 'lisp' option value. |
| 3493 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3494 | char * |
| 3495 | did_set_lisp(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3496 | { |
| 3497 | // When 'lisp' option changes include/exclude '-' in keyword characters. |
| 3498 | (void)buf_init_chartab(curbuf, FALSE); // ignore errors |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3499 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | /* |
| 3503 | * Process the updated 'title' or the 'icon' option value. |
| 3504 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3505 | char * |
| 3506 | did_set_title_icon(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3507 | { |
| 3508 | // when 'title' changed, may need to change the title; same for 'icon' |
| 3509 | did_set_title(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3510 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | /* |
| 3514 | * Process the updated 'modified' option value. |
| 3515 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3516 | char * |
| 3517 | did_set_modified(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3518 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3519 | if (!args->os_newval.boolean) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3520 | save_file_ff(curbuf); // Buffer is unchanged |
| 3521 | redraw_titles(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3522 | modified_was_set = args->os_newval.boolean; |
| 3523 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3526 | #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3527 | /* |
| 3528 | * Process the updated 'shellslash' option value. |
| 3529 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3530 | char * |
| 3531 | did_set_shellslash(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3532 | { |
| 3533 | if (p_ssl) |
| 3534 | { |
| 3535 | psepc = '/'; |
| 3536 | psepcN = '\\'; |
| 3537 | pseps[0] = '/'; |
| 3538 | } |
| 3539 | else |
| 3540 | { |
| 3541 | psepc = '\\'; |
| 3542 | psepcN = '/'; |
| 3543 | pseps[0] = '\\'; |
| 3544 | } |
| 3545 | |
| 3546 | // need to adjust the file name arguments and buffer names. |
| 3547 | buflist_slash_adjust(); |
| 3548 | alist_slash_adjust(); |
| 3549 | # ifdef FEAT_EVAL |
| 3550 | scriptnames_slash_adjust(); |
| 3551 | # endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3552 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3553 | } |
| 3554 | #endif |
| 3555 | |
| 3556 | /* |
| 3557 | * Process the updated 'wrap' option value. |
| 3558 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3559 | char * |
| 3560 | did_set_wrap(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3561 | { |
| 3562 | // If 'wrap' is set, set w_leftcol to zero. |
| 3563 | if (curwin->w_p_wrap) |
| 3564 | curwin->w_leftcol = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3565 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | /* |
| 3569 | * Process the updated 'equalalways' option value. |
| 3570 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3571 | char * |
| 3572 | did_set_equalalways(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3573 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3574 | if (p_ea && !args->os_oldval.boolean) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3575 | win_equal(curwin, FALSE, 0); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3576 | |
| 3577 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | /* |
| 3581 | * Process the updated 'weirdinvert' option value. |
| 3582 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3583 | char * |
| 3584 | did_set_weirdinvert(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3585 | { |
| 3586 | // When 'weirdinvert' changed, set/reset 't_xs'. |
| 3587 | // Then set 'weirdinvert' according to value of 't_xs'. |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3588 | if (p_wiv && !args->os_oldval.boolean) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3589 | T_XS = (char_u *)"y"; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3590 | else if (!p_wiv && args->os_oldval.boolean) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3591 | T_XS = empty_option; |
| 3592 | p_wiv = (*T_XS != NUL); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3593 | |
| 3594 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3597 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3598 | /* |
| 3599 | * Process the updated 'ballooneval' option value. |
| 3600 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3601 | char * |
| 3602 | did_set_ballooneval(optset_T *args) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3603 | { |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3604 | if (balloonEvalForTerm) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3605 | return NULL; |
| 3606 | |
| 3607 | if (p_beval && !args->os_oldval.boolean) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3608 | gui_mch_enable_beval_area(balloonEval); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3609 | else if (!p_beval && args->os_oldval.boolean) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 3610 | gui_mch_disable_beval_area(balloonEval); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3611 | |
| 3612 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3613 | } |
| 3614 | #endif |
| 3615 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3616 | #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3617 | /* |
| 3618 | * Process the updated 'balloonevalterm' option value. |
| 3619 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3620 | char * |
| 3621 | did_set_balloonevalterm(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3622 | { |
| 3623 | mch_bevalterm_changed(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3624 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3625 | } |
| 3626 | #endif |
| 3627 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3628 | #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3629 | /* |
| 3630 | * Process the updated 'autochdir' option value. |
| 3631 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3632 | char * |
| 3633 | did_set_autochdir(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3634 | { |
| 3635 | // Change directories when the 'acd' option is set now. |
| 3636 | DO_AUTOCHDIR; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3637 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3638 | } |
| 3639 | #endif |
| 3640 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3641 | #if defined(FEAT_DIFF) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3642 | /* |
| 3643 | * Process the updated 'diff' option value. |
| 3644 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3645 | char * |
| 3646 | did_set_diff(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3647 | { |
| 3648 | // May add or remove the buffer from the list of diff buffers. |
| 3649 | diff_buf_adjust(curwin); |
| 3650 | # ifdef FEAT_FOLDING |
| 3651 | if (foldmethodIsDiff(curwin)) |
| 3652 | foldUpdateAll(curwin); |
| 3653 | # endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3654 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3655 | } |
| 3656 | #endif |
| 3657 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3658 | #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3659 | /* |
| 3660 | * Process the updated 'imdisable' option value. |
| 3661 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3662 | char * |
| 3663 | did_set_imdisable(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3664 | { |
| 3665 | // Only de-activate it here, it will be enabled when changing mode. |
| 3666 | if (p_imdisable) |
| 3667 | im_set_active(FALSE); |
| 3668 | else if (State & MODE_INSERT) |
| 3669 | // When the option is set from an autocommand, it may need to take |
| 3670 | // effect right away. |
| 3671 | im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3672 | return NULL; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3673 | } |
| 3674 | #endif |
| 3675 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3676 | #if defined(FEAT_SPELL) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3677 | /* |
| 3678 | * Process the updated 'spell' option value. |
| 3679 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3680 | char * |
| 3681 | did_set_spell(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3682 | { |
| 3683 | if (curwin->w_p_spell) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3684 | return parse_spelllang(curwin); |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3685 | |
| 3686 | return NULL; |
| 3687 | } |
| 3688 | #endif |
| 3689 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3690 | #if defined(FEAT_ARABIC) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3691 | /* |
| 3692 | * Process the updated 'arabic' option value. |
| 3693 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3694 | char * |
| 3695 | did_set_arabic(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3696 | { |
| 3697 | char *errmsg = NULL; |
| 3698 | |
| 3699 | if (curwin->w_p_arab) |
| 3700 | { |
| 3701 | /* |
| 3702 | * 'arabic' is set, handle various sub-settings. |
| 3703 | */ |
| 3704 | if (!p_tbidi) |
| 3705 | { |
| 3706 | // set rightleft mode |
| 3707 | if (!curwin->w_p_rl) |
| 3708 | { |
| 3709 | curwin->w_p_rl = TRUE; |
| 3710 | changed_window_setting(); |
| 3711 | } |
| 3712 | |
| 3713 | // Enable Arabic shaping (major part of what Arabic requires) |
| 3714 | if (!p_arshape) |
| 3715 | { |
| 3716 | p_arshape = TRUE; |
| 3717 | redraw_later_clear(); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | // Arabic requires a utf-8 encoding, inform the user if it's not |
| 3722 | // set. |
| 3723 | if (STRCMP(p_enc, "utf-8") != 0) |
| 3724 | { |
| 3725 | static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); |
| 3726 | |
| 3727 | msg_source(HL_ATTR(HLF_W)); |
| 3728 | msg_attr(_(w_arabic), HL_ATTR(HLF_W)); |
| 3729 | #ifdef FEAT_EVAL |
| 3730 | set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); |
| 3731 | #endif |
| 3732 | } |
| 3733 | |
| 3734 | // set 'delcombine' |
| 3735 | p_deco = TRUE; |
| 3736 | |
| 3737 | # ifdef FEAT_KEYMAP |
| 3738 | // Force-set the necessary keymap for arabic |
| 3739 | errmsg = set_option_value((char_u *)"keymap", |
| 3740 | 0L, (char_u *)"arabic", OPT_LOCAL); |
| 3741 | # endif |
| 3742 | } |
| 3743 | else |
| 3744 | { |
| 3745 | /* |
| 3746 | * 'arabic' is reset, handle various sub-settings. |
| 3747 | */ |
| 3748 | if (!p_tbidi) |
| 3749 | { |
| 3750 | // reset rightleft mode |
| 3751 | if (curwin->w_p_rl) |
| 3752 | { |
| 3753 | curwin->w_p_rl = FALSE; |
| 3754 | changed_window_setting(); |
| 3755 | } |
| 3756 | |
| 3757 | // 'arabicshape' isn't reset, it is a global option and |
| 3758 | // another window may still need it "on". |
| 3759 | } |
| 3760 | |
| 3761 | // 'delcombine' isn't reset, it is a global option and another |
| 3762 | // window may still want it "on". |
| 3763 | |
| 3764 | # ifdef FEAT_KEYMAP |
| 3765 | // Revert to the default keymap |
| 3766 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3767 | curbuf->b_p_imsearch = B_IMODE_USE_INSERT; |
| 3768 | # endif |
| 3769 | } |
| 3770 | |
| 3771 | return errmsg; |
| 3772 | } |
| 3773 | #endif |
| 3774 | |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3775 | /* |
| 3776 | * Process the updated 'number' or 'relativenumber' option value. |
| 3777 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3778 | char * |
| 3779 | did_set_number_relativenumber(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3780 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3781 | #if (defined(FEAT_SIGNS) && defined(FEAT_GUI)) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3782 | if (gui.in_use |
| 3783 | && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u') |
| 3784 | && curbuf->b_signlist != NULL) |
| 3785 | { |
| 3786 | // If the 'number' or 'relativenumber' options are modified and |
| 3787 | // 'signcolumn' is set to 'number', then clear the screen for a full |
| 3788 | // refresh. Otherwise the sign icons are not displayed properly in the |
| 3789 | // number column. If the 'number' option is set and only the |
| 3790 | // 'relativenumber' option is toggled, then don't refresh the screen |
| 3791 | // (optimization). |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3792 | if (!(curwin->w_p_nu && ((int *)args->os_varp == &curwin->w_p_rnu))) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3793 | redraw_all_later(UPD_CLEAR); |
| 3794 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3795 | #endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3796 | return NULL; |
| 3797 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3798 | |
| 3799 | #ifdef FEAT_TERMGUICOLORS |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3800 | char * |
| 3801 | did_set_termguicolors(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3802 | { |
| 3803 | # ifdef FEAT_VTP |
| 3804 | // Do not turn on 'tgc' when 24-bit colors are not supported. |
| 3805 | if ( |
| 3806 | # ifdef VIMDLL |
| 3807 | !gui.in_use && !gui.starting && |
| 3808 | # endif |
| 3809 | !has_vtp_working()) |
| 3810 | { |
| 3811 | p_tgc = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3812 | args->os_doskip = TRUE; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3813 | return e_24_bit_colors_are_not_supported_on_this_environment; |
| 3814 | } |
| 3815 | if (is_term_win32()) |
| 3816 | swap_tcap(); |
| 3817 | # endif |
| 3818 | # ifdef FEAT_GUI |
| 3819 | if (!gui.in_use && !gui.starting) |
| 3820 | # endif |
| 3821 | highlight_gui_started(); |
| 3822 | # ifdef FEAT_VTP |
| 3823 | // reset t_Co |
| 3824 | if (is_term_win32()) |
| 3825 | { |
| 3826 | control_console_color_rgb(); |
| 3827 | set_termname(T_NAME); |
| 3828 | init_highlight(TRUE, FALSE); |
| 3829 | } |
| 3830 | # endif |
| 3831 | # ifdef FEAT_TERMINAL |
| 3832 | term_update_colors_all(); |
| 3833 | term_update_palette_all(); |
| 3834 | term_update_wincolor_all(); |
| 3835 | # endif |
| 3836 | |
| 3837 | return NULL; |
| 3838 | } |
| 3839 | #endif |
| 3840 | |
| 3841 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3842 | * Set the value of a boolean option, and take care of side effects. |
| 3843 | * Returns NULL for success, or an error message for an error. |
| 3844 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 3845 | static char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 3846 | set_bool_option( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3847 | int opt_idx, // index in options[] table |
| 3848 | char_u *varp, // pointer to the option variable |
| 3849 | int value, // new value |
| 3850 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3851 | { |
| 3852 | int old_value = *(int *)varp; |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3853 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3854 | int old_global_value = 0; |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3855 | #endif |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 3856 | char *errmsg = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3857 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3858 | // Disallow changing some options from secure mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3859 | if ((secure |
| 3860 | #ifdef HAVE_SANDBOX |
| 3861 | || sandbox != 0 |
| 3862 | #endif |
| 3863 | ) && (options[opt_idx].flags & P_SECURE)) |
Bram Moolenaar | 74409f6 | 2022-01-01 15:58:22 +0000 | [diff] [blame] | 3864 | return e_not_allowed_here; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3865 | |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3866 | #if defined(FEAT_EVAL) |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3867 | // Save the global value before changing anything. This is needed as for |
| 3868 | // a global-only option setting the "local value" in fact sets the global |
| 3869 | // value (since there is only one value). |
| 3870 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3871 | old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), |
| 3872 | OPT_GLOBAL); |
Bram Moolenaar | 983f2f1 | 2019-06-16 16:41:41 +0200 | [diff] [blame] | 3873 | #endif |
Bram Moolenaar | d7c9687 | 2019-06-15 17:12:48 +0200 | [diff] [blame] | 3874 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3875 | *(int *)varp = value; // set the new value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3876 | #ifdef FEAT_EVAL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3877 | // Remember where the option was set. |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3878 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3879 | #endif |
| 3880 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 3881 | #ifdef FEAT_GUI |
| 3882 | need_mouse_correct = TRUE; |
| 3883 | #endif |
| 3884 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3885 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3886 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3887 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; |
| 3888 | |
| 3889 | /* |
| 3890 | * Handle side effects of changing a bool option. |
| 3891 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3892 | if (options[opt_idx].opt_did_set_cb != NULL) |
| 3893 | { |
| 3894 | optset_T args; |
| 3895 | |
| 3896 | args.os_varp = varp; |
| 3897 | args.os_flags = opt_flags; |
| 3898 | args.os_oldval.boolean = old_value; |
| 3899 | args.os_newval.boolean = value; |
| 3900 | args.os_doskip = FALSE; |
Yegappan Lakshmanan | 6d611de | 2023-02-25 11:59:33 +0000 | [diff] [blame] | 3901 | args.os_errbuf = NULL; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3902 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
| 3903 | if (args.os_doskip) |
| 3904 | return errmsg; |
| 3905 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3906 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3907 | // after handling side effects, call autocommand |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 3908 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | options[opt_idx].flags |= P_WAS_SET; |
| 3910 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 3911 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3912 | apply_optionset_autocmd(opt_idx, opt_flags, |
| 3913 | (long)(old_value ? TRUE : FALSE), |
| 3914 | (long)(old_global_value ? TRUE : FALSE), |
| 3915 | (long)(value ? TRUE : FALSE), NULL); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 3916 | #endif |
| 3917 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3918 | comp_col(); // in case 'ruler' or 'showcmd' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3919 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 3920 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 3921 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 3922 | |
| 3923 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 3924 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3925 | |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 3926 | return errmsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | /* |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3930 | * Process the new 'winheight' or the 'helpheight' option value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3931 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3932 | char * |
| 3933 | did_set_winheight_helpheight(optset_T *args) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3934 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3935 | long *pp = (long *)args->os_varp; |
| 3936 | char *errmsg = NULL; |
| 3937 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3938 | if (p_wh < 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3939 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 3940 | errmsg = e_argument_must_be_positive; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3941 | p_wh = 1; |
| 3942 | } |
| 3943 | if (p_wmh > p_wh) |
| 3944 | { |
| 3945 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 3946 | p_wh = p_wmh; |
| 3947 | } |
| 3948 | if (p_hh < 0) |
| 3949 | { |
| 3950 | errmsg = e_argument_must_be_positive; |
| 3951 | p_hh = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3954 | // Change window height NOW |
| 3955 | if (!ONE_WINDOW) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3956 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3957 | if (pp == &p_wh && curwin->w_height < p_wh) |
| 3958 | win_setheight((int)p_wh); |
| 3959 | if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) |
| 3960 | win_setheight((int)p_hh); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3961 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3962 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3963 | return errmsg; |
| 3964 | } |
| 3965 | |
| 3966 | /* |
| 3967 | * Process the new 'winminheight' option value. |
| 3968 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3969 | char * |
| 3970 | did_set_winminheight(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3971 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3972 | char *errmsg = NULL; |
| 3973 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3974 | if (p_wmh < 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3975 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3976 | errmsg = e_argument_must_be_positive; |
| 3977 | p_wmh = 0; |
| 3978 | } |
| 3979 | if (p_wmh > p_wh) |
| 3980 | { |
| 3981 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 3982 | p_wmh = p_wh; |
| 3983 | } |
| 3984 | win_setminheight(); |
| 3985 | |
| 3986 | return errmsg; |
| 3987 | } |
| 3988 | |
| 3989 | /* |
| 3990 | * Process the new 'winwidth' option value. |
| 3991 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3992 | char * |
| 3993 | did_set_winwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3994 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3995 | char *errmsg = NULL; |
| 3996 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 3997 | if (p_wiw < 1) |
| 3998 | { |
| 3999 | errmsg = e_argument_must_be_positive; |
| 4000 | p_wiw = 1; |
| 4001 | } |
| 4002 | if (p_wmw > p_wiw) |
| 4003 | { |
| 4004 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4005 | p_wiw = p_wmw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4006 | } |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 4007 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4008 | // Change window width NOW |
| 4009 | if (!ONE_WINDOW && curwin->w_width < p_wiw) |
| 4010 | win_setwidth((int)p_wiw); |
| 4011 | |
| 4012 | return errmsg; |
| 4013 | } |
| 4014 | |
| 4015 | /* |
| 4016 | * Process the new 'winminwidth' option value. |
| 4017 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4018 | char * |
| 4019 | did_set_winminwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4020 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4021 | char *errmsg = NULL; |
| 4022 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4023 | if (p_wmw < 0) |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 4024 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4025 | errmsg = e_argument_must_be_positive; |
| 4026 | p_wmw = 0; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 4027 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4028 | if (p_wmw > p_wiw) |
| 4029 | { |
| 4030 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4031 | p_wmw = p_wiw; |
| 4032 | } |
| 4033 | win_setminwidth(); |
| 4034 | |
| 4035 | return errmsg; |
| 4036 | } |
| 4037 | |
| 4038 | /* |
| 4039 | * Process the new 'laststatus' option value. |
| 4040 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4041 | char * |
| 4042 | did_set_laststatus(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4043 | { |
| 4044 | last_status(FALSE); // (re)set last window status line |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4045 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | /* |
| 4049 | * Process the new 'showtabline' option value. |
| 4050 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4051 | char * |
| 4052 | did_set_showtabline(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4053 | { |
| 4054 | shell_new_rows(); // recompute window positions and heights |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4055 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4056 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4057 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4058 | #if defined(FEAT_GUI) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4059 | /* |
| 4060 | * Process the new 'linespace' option value. |
| 4061 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4062 | char * |
| 4063 | did_set_linespace(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4064 | { |
| 4065 | // Recompute gui.char_height and resize the Vim window to keep the |
| 4066 | // same number of lines. |
| 4067 | if (gui.in_use && gui_mch_adjust_charheight() == OK) |
| 4068 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4069 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4070 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4071 | #endif |
| 4072 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4073 | #if defined(FEAT_FOLDING) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4074 | /* |
| 4075 | * Process the new 'foldlevel' option value. |
| 4076 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4077 | char * |
| 4078 | did_set_foldlevel(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4079 | { |
| 4080 | if (curwin->w_p_fdl < 0) |
| 4081 | curwin->w_p_fdl = 0; |
| 4082 | newFoldLevel(); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4083 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4084 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4085 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4086 | /* |
| 4087 | * Process the new 'foldminlines' option value. |
| 4088 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4089 | char * |
| 4090 | did_set_foldminlines(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4091 | { |
| 4092 | foldUpdateAll(curwin); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4093 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /* |
| 4097 | * Process the new 'foldnestmax' option value. |
| 4098 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4099 | char * |
| 4100 | did_set_foldnestmax(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4101 | { |
| 4102 | if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4103 | foldUpdateAll(curwin); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4104 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | /* |
| 4108 | * Process the new 'foldcolumn' option value. |
| 4109 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4110 | char * |
| 4111 | did_set_foldcolumn(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4112 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4113 | char *errmsg = NULL; |
| 4114 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4115 | if (curwin->w_p_fdc < 0) |
| 4116 | { |
| 4117 | errmsg = e_argument_must_be_positive; |
| 4118 | curwin->w_p_fdc = 0; |
| 4119 | } |
| 4120 | else if (curwin->w_p_fdc > 12) |
| 4121 | { |
| 4122 | errmsg = e_invalid_argument; |
| 4123 | curwin->w_p_fdc = 12; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4126 | return errmsg; |
| 4127 | } |
| 4128 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4129 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4130 | /* |
| 4131 | * Process the new 'shiftwidth' or the 'tabstop' option value. |
| 4132 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4133 | char * |
| 4134 | did_set_shiftwidth_tabstop(optset_T *args) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4135 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4136 | long *pp = (long *)args->os_varp; |
| 4137 | char *errmsg = NULL; |
| 4138 | |
| 4139 | if (curbuf->b_p_sw < 0) |
| 4140 | { |
| 4141 | errmsg = e_argument_must_be_positive; |
| 4142 | #ifdef FEAT_VARTABS |
| 4143 | // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. |
| 4144 | curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0 |
| 4145 | ? tabstop_first(curbuf->b_p_vts_array) |
| 4146 | : curbuf->b_p_ts; |
| 4147 | #else |
| 4148 | curbuf->b_p_sw = curbuf->b_p_ts; |
| 4149 | #endif |
| 4150 | } |
| 4151 | |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 4152 | #ifdef FEAT_FOLDING |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4153 | if (foldmethodIsIndent(curwin)) |
| 4154 | foldUpdateAll(curwin); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 4155 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4156 | // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: |
| 4157 | // parse 'cinoptions'. |
| 4158 | if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) |
| 4159 | parse_cino(curbuf); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4160 | |
| 4161 | return errmsg; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4162 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4163 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4164 | /* |
| 4165 | * Process the new 'maxcombine' option value. |
| 4166 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4167 | char * |
| 4168 | did_set_maxcombine(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4169 | { |
| 4170 | if (p_mco > MAX_MCO) |
| 4171 | p_mco = MAX_MCO; |
| 4172 | else if (p_mco < 0) |
| 4173 | p_mco = 0; |
| 4174 | screenclear(); // will re-allocate the screen |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4175 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4176 | } |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4177 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4178 | /* |
| 4179 | * Process the new 'iminsert' option value. |
| 4180 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4181 | char * |
| 4182 | did_set_iminsert(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4183 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4184 | char *errmsg = NULL; |
| 4185 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4186 | if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4187 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4188 | errmsg = e_invalid_argument; |
| 4189 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 4190 | } |
| 4191 | p_iminsert = curbuf->b_p_iminsert; |
| 4192 | if (termcap_active) // don't do this in the alternate screen |
| 4193 | showmode(); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 4194 | #if defined(FEAT_KEYMAP) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4195 | // Show/unshow value of 'keymap' in status lines. |
| 4196 | status_redraw_curbuf(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4197 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4198 | |
| 4199 | return errmsg; |
| 4200 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4201 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4202 | #if (defined(FEAT_XIM) && defined(FEAT_GUI_GTK)) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4203 | /* |
| 4204 | * Process the new 'imstyle' option value. |
| 4205 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4206 | char * |
| 4207 | did_set_imstyle(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4208 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4209 | char *errmsg = NULL; |
| 4210 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4211 | if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) |
| 4212 | errmsg = e_invalid_argument; |
| 4213 | |
| 4214 | return errmsg; |
| 4215 | } |
Bram Moolenaar | 5c6dbcb | 2017-08-30 22:00:20 +0200 | [diff] [blame] | 4216 | #endif |
| 4217 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4218 | /* |
| 4219 | * Process the new 'window' option value. |
| 4220 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4221 | char * |
| 4222 | did_set_window(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4223 | { |
| 4224 | if (p_window < 1) |
| 4225 | p_window = 1; |
| 4226 | else if (p_window >= Rows) |
| 4227 | p_window = Rows - 1; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4228 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4229 | } |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 4230 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4231 | /* |
| 4232 | * Process the new 'imsearch' option value. |
| 4233 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4234 | char * |
| 4235 | did_set_imsearch(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4236 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4237 | char *errmsg = NULL; |
| 4238 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4239 | if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4240 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4241 | errmsg = e_invalid_argument; |
| 4242 | curbuf->b_p_imsearch = B_IMODE_NONE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4243 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4244 | p_imsearch = curbuf->b_p_imsearch; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4245 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4246 | return errmsg; |
| 4247 | } |
| 4248 | |
| 4249 | /* |
| 4250 | * Process the new 'titlelen' option value. |
| 4251 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4252 | char * |
| 4253 | did_set_titlelen(optset_T *args) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4254 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4255 | long old_value = args->os_oldval.number; |
| 4256 | char *errmsg = NULL; |
| 4257 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4258 | // if 'titlelen' has changed, redraw the title |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4259 | if (p_titlelen < 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4260 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4261 | errmsg = e_argument_must_be_positive; |
| 4262 | p_titlelen = 85; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4263 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4264 | if (starting != NO_SCREEN && old_value != p_titlelen) |
| 4265 | need_maketitle = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4266 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4267 | return errmsg; |
| 4268 | } |
| 4269 | |
| 4270 | /* |
| 4271 | * Process the new 'cmdheight' option value. |
| 4272 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4273 | char * |
| 4274 | did_set_cmdheight(optset_T *args) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4275 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4276 | long old_value = args->os_oldval.number; |
| 4277 | char *errmsg = NULL; |
| 4278 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4279 | // if p_ch changed value, change the command line height |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4280 | if (p_ch < 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4281 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4282 | errmsg = e_argument_must_be_positive; |
| 4283 | p_ch = 1; |
| 4284 | } |
| 4285 | if (p_ch > Rows - min_rows() + 1) |
| 4286 | p_ch = Rows - min_rows() + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4287 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4288 | // Only compute the new window layout when startup has been |
| 4289 | // completed. Otherwise the frame sizes may be wrong. |
| 4290 | if ((p_ch != old_value |
| 4291 | || tabline_height() + topframe->fr_height != Rows - p_ch) |
| 4292 | && full_screen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4293 | #ifdef FEAT_GUI |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4294 | && !gui.starting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4295 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4296 | ) |
| 4297 | command_height(); |
| 4298 | |
| 4299 | return errmsg; |
| 4300 | } |
| 4301 | |
| 4302 | /* |
| 4303 | * Process the new 'updatecount' option value. |
| 4304 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4305 | char * |
| 4306 | did_set_updatecount(optset_T *args) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4307 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4308 | long old_value = args->os_oldval.number; |
| 4309 | char *errmsg = NULL; |
| 4310 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4311 | // when 'updatecount' changes from zero to non-zero, open swap files |
| 4312 | if (p_uc < 0) |
| 4313 | { |
| 4314 | errmsg = e_argument_must_be_positive; |
| 4315 | p_uc = 100; |
| 4316 | } |
| 4317 | if (p_uc && !old_value) |
| 4318 | ml_open_files(); |
| 4319 | |
| 4320 | return errmsg; |
| 4321 | } |
| 4322 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4323 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4324 | /* |
| 4325 | * Process the new 'conceallevel' option value. |
| 4326 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4327 | char * |
| 4328 | did_set_conceallevel(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4329 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4330 | char *errmsg = NULL; |
| 4331 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4332 | if (curwin->w_p_cole < 0) |
| 4333 | { |
| 4334 | errmsg = e_argument_must_be_positive; |
| 4335 | curwin->w_p_cole = 0; |
| 4336 | } |
| 4337 | else if (curwin->w_p_cole > 3) |
| 4338 | { |
| 4339 | errmsg = e_invalid_argument; |
| 4340 | curwin->w_p_cole = 3; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4341 | } |
| 4342 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4343 | return errmsg; |
| 4344 | } |
Bram Moolenaar | 325b7a2 | 2004-07-05 15:58:32 +0000 | [diff] [blame] | 4345 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4346 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4347 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4348 | /* |
| 4349 | * Process the new 'pyxversion' option value. |
| 4350 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4351 | char * |
| 4352 | did_set_pyxversion(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4353 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4354 | char *errmsg = NULL; |
| 4355 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4356 | if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) |
| 4357 | errmsg = e_invalid_argument; |
| 4358 | |
| 4359 | return errmsg; |
| 4360 | } |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 4361 | #endif |
| 4362 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4363 | /* |
| 4364 | * Process the new global 'undolevels' option value. |
| 4365 | */ |
| 4366 | static void |
| 4367 | did_set_global_undolevels(long value, long old_value) |
| 4368 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4369 | // sync undo before 'undolevels' changes |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4370 | |
| 4371 | // use the old value, otherwise u_sync() may not work properly |
| 4372 | p_ul = old_value; |
| 4373 | u_sync(TRUE); |
| 4374 | p_ul = value; |
| 4375 | } |
| 4376 | |
| 4377 | /* |
| 4378 | * Process the new buffer local 'undolevels' option value. |
| 4379 | */ |
| 4380 | static void |
| 4381 | did_set_buflocal_undolevels(long value, long old_value) |
| 4382 | { |
| 4383 | // use the old value, otherwise u_sync() may not work properly |
| 4384 | curbuf->b_p_ul = old_value; |
| 4385 | u_sync(TRUE); |
| 4386 | curbuf->b_p_ul = value; |
| 4387 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4388 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4389 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4390 | /* |
| 4391 | * Process the new 'numberwidth' option value. |
| 4392 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4393 | char * |
| 4394 | did_set_numberwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4395 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4396 | char *errmsg = NULL; |
| 4397 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4398 | // 'numberwidth' must be positive |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4399 | if (curwin->w_p_nuw < 1) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 4400 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4401 | errmsg = e_argument_must_be_positive; |
| 4402 | curwin->w_p_nuw = 1; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 4403 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4404 | if (curwin->w_p_nuw > 20) |
| 4405 | { |
| 4406 | errmsg = e_invalid_argument; |
| 4407 | curwin->w_p_nuw = 20; |
| 4408 | } |
| 4409 | curwin->w_nrwidth_line_count = 0; // trigger a redraw |
| 4410 | |
| 4411 | return errmsg; |
| 4412 | } |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 4413 | #endif |
| 4414 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4415 | /* |
| 4416 | * Process the new 'textwidth' option value. |
| 4417 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4418 | char * |
| 4419 | did_set_textwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4420 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4421 | char *errmsg = NULL; |
| 4422 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4423 | if (curbuf->b_p_tw < 0) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4424 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4425 | errmsg = e_argument_must_be_positive; |
| 4426 | curbuf->b_p_tw = 0; |
| 4427 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4428 | #ifdef FEAT_SYN_HL |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4429 | { |
| 4430 | win_T *wp; |
| 4431 | tabpage_T *tp; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4432 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4433 | FOR_ALL_TAB_WINDOWS(tp, wp) |
| 4434 | check_colorcolumn(wp); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4435 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4436 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4437 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4438 | return errmsg; |
| 4439 | } |
| 4440 | |
| 4441 | /* |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4442 | * Process the new 'undolevels' option value. |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4443 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4444 | char * |
| 4445 | did_set_undolevels(optset_T *args) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4446 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4447 | long *pp = (long *)args->os_varp; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4448 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4449 | if (pp == &p_ul) // global 'undolevels' |
| 4450 | did_set_global_undolevels(args->os_newval.number, |
| 4451 | args->os_oldval.number); |
| 4452 | else if (pp == &curbuf->b_p_ul) // buffer local 'undolevels' |
| 4453 | did_set_buflocal_undolevels(args->os_newval.number, |
| 4454 | args->os_oldval.number); |
| 4455 | |
| 4456 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | /* |
| 4460 | * Check the bounds of numeric options. |
| 4461 | */ |
| 4462 | static char * |
| 4463 | check_num_option_bounds( |
| 4464 | long *pp, |
| 4465 | long old_value, |
| 4466 | long old_Rows, |
| 4467 | long old_Columns, |
| 4468 | char *errbuf, |
| 4469 | size_t errbuflen, |
| 4470 | char *errmsg) |
| 4471 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4472 | if (Rows < min_rows() && full_screen) |
| 4473 | { |
| 4474 | if (errbuf != NULL) |
| 4475 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4476 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4477 | _(e_need_at_least_nr_lines), min_rows()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4478 | errmsg = errbuf; |
| 4479 | } |
| 4480 | Rows = min_rows(); |
| 4481 | } |
| 4482 | if (Columns < MIN_COLUMNS && full_screen) |
| 4483 | { |
| 4484 | if (errbuf != NULL) |
| 4485 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4486 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4487 | _(e_need_at_least_nr_columns), MIN_COLUMNS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4488 | errmsg = errbuf; |
| 4489 | } |
| 4490 | Columns = MIN_COLUMNS; |
| 4491 | } |
Bram Moolenaar | e057d40 | 2013-06-30 17:51:51 +0200 | [diff] [blame] | 4492 | limit_screen_size(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4493 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4494 | /* |
| 4495 | * If the screen (shell) height has been changed, assume it is the |
| 4496 | * physical screenheight. |
| 4497 | */ |
| 4498 | if (old_Rows != Rows || old_Columns != Columns) |
| 4499 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4500 | // Changing the screen size is not allowed while updating the screen. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4501 | if (updating_screen) |
| 4502 | *pp = old_value; |
| 4503 | else if (full_screen |
| 4504 | #ifdef FEAT_GUI |
| 4505 | && !gui.starting |
| 4506 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4507 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4508 | set_shellsize((int)Columns, (int)Rows, TRUE); |
| 4509 | else |
| 4510 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4511 | // Postpone the resizing; check the size and cmdline position for |
| 4512 | // messages. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4513 | check_shellsize(); |
| 4514 | if (cmdline_row > Rows - p_ch && Rows > p_ch) |
| 4515 | cmdline_row = Rows - p_ch; |
| 4516 | } |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4517 | if (p_window >= Rows || !option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 4518 | p_window = Rows - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4521 | if (curbuf->b_p_ts <= 0) |
| 4522 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4523 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4524 | curbuf->b_p_ts = 8; |
| 4525 | } |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 4526 | else if (curbuf->b_p_ts > TABSTOP_MAX) |
| 4527 | { |
| 4528 | errmsg = e_invalid_argument; |
| 4529 | curbuf->b_p_ts = 8; |
| 4530 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4531 | if (p_tm < 0) |
| 4532 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4533 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4534 | p_tm = 0; |
| 4535 | } |
| 4536 | if ((curwin->w_p_scr <= 0 |
| 4537 | || (curwin->w_p_scr > curwin->w_height |
| 4538 | && curwin->w_height > 0)) |
| 4539 | && full_screen) |
| 4540 | { |
| 4541 | if (pp == &(curwin->w_p_scr)) |
| 4542 | { |
| 4543 | if (curwin->w_p_scr != 0) |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4544 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4545 | win_comp_scroll(curwin); |
| 4546 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4547 | // If 'scroll' became invalid because of a side effect silently adjust |
| 4548 | // it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4549 | else if (curwin->w_p_scr <= 0) |
| 4550 | curwin->w_p_scr = 1; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4551 | else // curwin->w_p_scr > curwin->w_height |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4552 | curwin->w_p_scr = curwin->w_height; |
| 4553 | } |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4554 | if (p_hi < 0) |
| 4555 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4556 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4557 | p_hi = 0; |
| 4558 | } |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4559 | else if (p_hi > 10000) |
| 4560 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4561 | errmsg = e_invalid_argument; |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4562 | p_hi = 10000; |
| 4563 | } |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4564 | if (p_re < 0 || p_re > 2) |
| 4565 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4566 | errmsg = e_invalid_argument; |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4567 | p_re = 0; |
| 4568 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4569 | if (p_report < 0) |
| 4570 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4571 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4572 | p_report = 1; |
| 4573 | } |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 4574 | if ((p_sj < -100 || p_sj >= Rows) && full_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4575 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4576 | if (Rows != old_Rows) // Rows changed, just adjust p_sj |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4577 | p_sj = Rows / 2; |
| 4578 | else |
| 4579 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4580 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4581 | p_sj = 1; |
| 4582 | } |
| 4583 | } |
| 4584 | if (p_so < 0 && full_screen) |
| 4585 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4586 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4587 | p_so = 0; |
| 4588 | } |
| 4589 | if (p_siso < 0 && full_screen) |
| 4590 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4591 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4592 | p_siso = 0; |
| 4593 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4594 | if (p_cwh < 1) |
| 4595 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4596 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4597 | p_cwh = 1; |
| 4598 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4599 | if (p_ut < 0) |
| 4600 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4601 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4602 | p_ut = 2000; |
| 4603 | } |
| 4604 | if (p_ss < 0) |
| 4605 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4606 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4607 | p_ss = 0; |
| 4608 | } |
| 4609 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4610 | return errmsg; |
| 4611 | } |
| 4612 | |
| 4613 | /* |
| 4614 | * Set the value of a number option, and take care of side effects. |
| 4615 | * Returns NULL for success, or an error message for an error. |
| 4616 | */ |
| 4617 | static char * |
| 4618 | set_num_option( |
| 4619 | int opt_idx, // index in options[] table |
| 4620 | char_u *varp, // pointer to the option variable |
| 4621 | long value, // new value |
| 4622 | char *errbuf, // buffer for error messages |
| 4623 | size_t errbuflen, // length of "errbuf" |
| 4624 | int opt_flags) // OPT_LOCAL, OPT_GLOBAL, |
| 4625 | // OPT_MODELINE, etc. |
| 4626 | { |
| 4627 | char *errmsg = NULL; |
| 4628 | long old_value = *(long *)varp; |
| 4629 | #if defined(FEAT_EVAL) |
| 4630 | long old_global_value = 0; // only used when setting a local and |
| 4631 | // global option |
| 4632 | #endif |
| 4633 | long old_Rows = Rows; // remember old Rows |
| 4634 | long old_Columns = Columns; // remember old Columns |
| 4635 | long *pp = (long *)varp; |
| 4636 | |
| 4637 | // Disallow changing some options from secure mode. |
| 4638 | if ((secure |
| 4639 | #ifdef HAVE_SANDBOX |
| 4640 | || sandbox != 0 |
| 4641 | #endif |
| 4642 | ) && (options[opt_idx].flags & P_SECURE)) |
| 4643 | return e_not_allowed_here; |
| 4644 | |
| 4645 | #if defined(FEAT_EVAL) |
| 4646 | // Save the global value before changing anything. This is needed as for |
| 4647 | // a global-only option setting the "local value" in fact sets the global |
| 4648 | // value (since there is only one value). |
| 4649 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4650 | old_global_value = *(long *)get_varp_scope(&(options[opt_idx]), |
| 4651 | OPT_GLOBAL); |
| 4652 | #endif |
| 4653 | |
| 4654 | *pp = value; |
| 4655 | #ifdef FEAT_EVAL |
| 4656 | // Remember where the option was set. |
| 4657 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
| 4658 | #endif |
| 4659 | #ifdef FEAT_GUI |
| 4660 | need_mouse_correct = TRUE; |
| 4661 | #endif |
| 4662 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4663 | // Invoke the option specific callback function to validate and apply the |
| 4664 | // new value. |
| 4665 | if (options[opt_idx].opt_did_set_cb != NULL) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4666 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4667 | optset_T args; |
| 4668 | |
| 4669 | args.os_varp = varp; |
| 4670 | args.os_flags = opt_flags; |
| 4671 | args.os_oldval.number = old_value; |
| 4672 | args.os_newval.number = value; |
Yegappan Lakshmanan | 6d611de | 2023-02-25 11:59:33 +0000 | [diff] [blame] | 4673 | args.os_errbuf = NULL; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4674 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4677 | // Check the bounds for numeric options here |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4678 | errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns, |
| 4679 | errbuf, errbuflen, errmsg); |
| 4680 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4681 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4682 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4683 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; |
| 4684 | |
| 4685 | options[opt_idx].flags |= P_WAS_SET; |
| 4686 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 4687 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 4688 | apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value, |
| 4689 | value, errmsg); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4690 | #endif |
| 4691 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4692 | comp_col(); // in case 'columns' or 'ls' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4693 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 4694 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4695 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 4696 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 4697 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4698 | |
| 4699 | return errmsg; |
| 4700 | } |
| 4701 | |
| 4702 | /* |
| 4703 | * Called after an option changed: check if something needs to be redrawn. |
| 4704 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4705 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4706 | check_redraw(long_u flags) |
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 | // 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] | 4709 | int doclear = (flags & P_RCLR) == P_RCLR; |
| 4710 | int all = ((flags & P_RALL) == P_RALL || doclear); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4711 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4712 | if ((flags & P_RSTAT) || all) // mark all status lines dirty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4713 | status_redraw_all(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4714 | |
| 4715 | if ((flags & P_RBUF) || (flags & P_RWIN) || all) |
| 4716 | changed_window_setting(); |
| 4717 | if (flags & P_RBUF) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4718 | redraw_curbuf_later(UPD_NOT_VALID); |
Bram Moolenaar | a2477fd | 2016-12-03 15:13:20 +0100 | [diff] [blame] | 4719 | if (flags & P_RWINONLY) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4720 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 4721 | if (doclear) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4722 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4723 | else if (all) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4724 | redraw_all_later(UPD_NOT_VALID); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | /* |
| 4728 | * Find index for option 'arg'. |
| 4729 | * Return -1 if not found. |
| 4730 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4731 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4732 | findoption(char_u *arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4733 | { |
| 4734 | int opt_idx; |
| 4735 | char *s, *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4736 | static short quick_tab[27] = {0, 0}; // quick access table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4737 | int is_term_opt; |
| 4738 | |
| 4739 | /* |
| 4740 | * For first call: Initialize the quick-access table. |
| 4741 | * It contains the index for the first option that starts with a certain |
| 4742 | * letter. There are 26 letters, plus the first "t_" option. |
| 4743 | */ |
| 4744 | if (quick_tab[1] == 0) |
| 4745 | { |
| 4746 | p = options[0].fullname; |
| 4747 | for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4748 | { |
| 4749 | if (s[0] != p[0]) |
| 4750 | { |
| 4751 | if (s[0] == 't' && s[1] == '_') |
| 4752 | quick_tab[26] = opt_idx; |
| 4753 | else |
| 4754 | quick_tab[CharOrdLow(s[0])] = opt_idx; |
| 4755 | } |
| 4756 | p = s; |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | /* |
| 4761 | * Check for name starting with an illegal character. |
| 4762 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4763 | if (arg[0] < 'a' || arg[0] > 'z') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4764 | return -1; |
| 4765 | |
| 4766 | is_term_opt = (arg[0] == 't' && arg[1] == '_'); |
| 4767 | if (is_term_opt) |
| 4768 | opt_idx = quick_tab[26]; |
| 4769 | else |
| 4770 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4771 | for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4772 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4773 | if (STRCMP(arg, s) == 0) // match full name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4774 | break; |
| 4775 | } |
| 4776 | if (s == NULL && !is_term_opt) |
| 4777 | { |
| 4778 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4779 | for ( ; options[opt_idx].fullname != NULL; opt_idx++) |
| 4780 | { |
| 4781 | s = options[opt_idx].shortname; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4782 | if (s != NULL && STRCMP(arg, s) == 0) // match short name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4783 | break; |
| 4784 | s = NULL; |
| 4785 | } |
| 4786 | } |
| 4787 | if (s == NULL) |
| 4788 | opt_idx = -1; |
| 4789 | return opt_idx; |
| 4790 | } |
| 4791 | |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 4792 | #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME) \ |
| 4793 | || defined(FEAT_SPELL) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4794 | /* |
| 4795 | * Get the value for an option. |
| 4796 | * |
| 4797 | * Returns: |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4798 | * Number option: gov_number, *numval gets value. |
Bram Moolenaar | a725149 | 2021-01-02 16:53:13 +0100 | [diff] [blame] | 4799 | * Toggle option: gov_bool, *numval gets value. |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4800 | * String option: gov_string, *stringval gets allocated string. |
| 4801 | * Hidden Number option: gov_hidden_number. |
| 4802 | * Hidden Toggle option: gov_hidden_bool. |
| 4803 | * Hidden String option: gov_hidden_string. |
| 4804 | * Unknown option: gov_unknown. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4805 | * |
| 4806 | * "flagsp" (if not NULL) is set to the option flags (P_xxxx). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4807 | */ |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4808 | getoption_T |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4809 | get_option_value( |
| 4810 | char_u *name, |
| 4811 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4812 | char_u **stringval, // NULL when only checking existence |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4813 | int *flagsp, |
| 4814 | int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4815 | { |
| 4816 | int opt_idx; |
| 4817 | char_u *varp; |
| 4818 | |
| 4819 | opt_idx = findoption(name); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4820 | if (opt_idx < 0) // option not in the table |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4821 | { |
| 4822 | int key; |
| 4823 | |
| 4824 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4825 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4826 | { |
| 4827 | char_u key_name[2]; |
| 4828 | char_u *p; |
| 4829 | |
Bram Moolenaar | 10c75c4 | 2021-12-28 20:53:30 +0000 | [diff] [blame] | 4830 | if (flagsp != NULL) |
| 4831 | *flagsp = 0; // terminal option has no flags |
| 4832 | |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4833 | // check for a terminal option |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4834 | if (key < 0) |
| 4835 | { |
| 4836 | key_name[0] = KEY2TERMCAP0(key); |
| 4837 | key_name[1] = KEY2TERMCAP1(key); |
| 4838 | } |
| 4839 | else |
| 4840 | { |
| 4841 | key_name[0] = KS_KEY; |
| 4842 | key_name[1] = (key & 0xff); |
| 4843 | } |
| 4844 | p = find_termcode(key_name); |
| 4845 | if (p != NULL) |
| 4846 | { |
| 4847 | if (stringval != NULL) |
| 4848 | *stringval = vim_strsave(p); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4849 | return gov_string; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4850 | } |
| 4851 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4852 | return gov_unknown; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4853 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4854 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4855 | varp = get_varp_scope(&(options[opt_idx]), scope); |
| 4856 | |
| 4857 | if (flagsp != NULL) |
| 4858 | // Return the P_xxxx option flags. |
| 4859 | *flagsp = options[opt_idx].flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4860 | |
| 4861 | if (options[opt_idx].flags & P_STRING) |
| 4862 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4863 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4864 | return gov_hidden_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4865 | if (stringval != NULL) |
| 4866 | { |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 4867 | if ((char_u **)varp == &p_pt) // 'pastetoggle' |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 4868 | *stringval = str2special_save(*(char_u **)(varp), FALSE, |
| 4869 | FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4870 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4871 | // never return the value of the crypt key |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 4872 | else if ((char_u **)varp == &curbuf->b_p_key |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 4873 | && **(char_u **)(varp) != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4874 | *stringval = vim_strsave((char_u *)"*****"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4875 | #endif |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 4876 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4877 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 4878 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4879 | return gov_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4882 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4883 | return (options[opt_idx].flags & P_NUM) |
| 4884 | ? gov_hidden_number : gov_hidden_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4885 | if (options[opt_idx].flags & P_NUM) |
| 4886 | *numval = *(long *)varp; |
| 4887 | else |
| 4888 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4889 | // Special case: 'modified' is b_changed, but we also want to consider |
| 4890 | // it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4891 | if ((int *)varp == &curbuf->b_changed) |
| 4892 | *numval = curbufIsChanged(); |
| 4893 | else |
Bram Moolenaar | 2acfbed | 2016-07-01 23:14:02 +0200 | [diff] [blame] | 4894 | *numval = (long) *(int *)varp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4895 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4896 | return (options[opt_idx].flags & P_NUM) ? gov_number : gov_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4897 | } |
| 4898 | #endif |
| 4899 | |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 4900 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4901 | /* |
| 4902 | * Returns the option attributes and its value. Unlike the above function it |
| 4903 | * will return either global value or local value of the option depending on |
| 4904 | * what was requested, but it will never return global value if it was |
| 4905 | * requested to return local one and vice versa. Neither it will return |
| 4906 | * buffer-local value if it was requested to return window-local one. |
| 4907 | * |
| 4908 | * Pretends that option is absent if it is not present in the requested scope |
| 4909 | * (i.e. has no global, window-local or buffer-local value depending on |
| 4910 | * opt_type). Uses |
| 4911 | * |
| 4912 | * Returned flags: |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 4913 | * 0 hidden or unknown option, also option that does not have requested |
| 4914 | * type (see SREQ_* in vim.h) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4915 | * see SOPT_* in vim.h for other flags |
| 4916 | * |
| 4917 | * Possible opt_type values: see SREQ_* in vim.h |
| 4918 | */ |
| 4919 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4920 | get_option_value_strict( |
| 4921 | char_u *name, |
| 4922 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4923 | char_u **stringval, // NULL when only obtaining attributes |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4924 | int opt_type, |
| 4925 | void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4926 | { |
| 4927 | int opt_idx; |
Bram Moolenaar | 6800186 | 2013-05-11 13:45:05 +0200 | [diff] [blame] | 4928 | char_u *varp = NULL; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4929 | struct vimoption *p; |
| 4930 | int r = 0; |
| 4931 | |
| 4932 | opt_idx = findoption(name); |
| 4933 | if (opt_idx < 0) |
| 4934 | return 0; |
| 4935 | |
| 4936 | p = &(options[opt_idx]); |
| 4937 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4938 | // Hidden option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4939 | if (p->var == NULL) |
| 4940 | return 0; |
| 4941 | |
| 4942 | if (p->flags & P_BOOL) |
| 4943 | r |= SOPT_BOOL; |
| 4944 | else if (p->flags & P_NUM) |
| 4945 | r |= SOPT_NUM; |
| 4946 | else if (p->flags & P_STRING) |
| 4947 | r |= SOPT_STRING; |
| 4948 | |
| 4949 | if (p->indir == PV_NONE) |
| 4950 | { |
| 4951 | if (opt_type == SREQ_GLOBAL) |
| 4952 | r |= SOPT_GLOBAL; |
| 4953 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4954 | return 0; // Did not request global-only option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4955 | } |
| 4956 | else |
| 4957 | { |
| 4958 | if (p->indir & PV_BOTH) |
| 4959 | r |= SOPT_GLOBAL; |
| 4960 | else if (opt_type == SREQ_GLOBAL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4961 | return 0; // Requested global option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4962 | |
| 4963 | if (p->indir & PV_WIN) |
| 4964 | { |
| 4965 | if (opt_type == SREQ_BUF) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4966 | return 0; // Did not request window-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4967 | else |
| 4968 | r |= SOPT_WIN; |
| 4969 | } |
| 4970 | else if (p->indir & PV_BUF) |
| 4971 | { |
| 4972 | if (opt_type == SREQ_WIN) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4973 | return 0; // Did not request buffer-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4974 | else |
| 4975 | r |= SOPT_BUF; |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | if (stringval == NULL) |
| 4980 | return r; |
| 4981 | |
| 4982 | if (opt_type == SREQ_GLOBAL) |
| 4983 | varp = p->var; |
| 4984 | else |
| 4985 | { |
| 4986 | if (opt_type == SREQ_BUF) |
| 4987 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4988 | // Special case: 'modified' is b_changed, but we also want to |
| 4989 | // consider it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4990 | if (p->indir == PV_MOD) |
| 4991 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 4992 | *numval = bufIsChanged((buf_T *)from); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4993 | varp = NULL; |
| 4994 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 4995 | # ifdef FEAT_CRYPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4996 | else if (p->indir == PV_KEY) |
| 4997 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4998 | // never return the value of the crypt key |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 4999 | *stringval = NULL; |
| 5000 | varp = NULL; |
| 5001 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 5002 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5003 | else |
| 5004 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5005 | buf_T *save_curbuf = curbuf; |
| 5006 | |
| 5007 | // only getting a pointer, no need to use aucmd_prepbuf() |
| 5008 | curbuf = (buf_T *)from; |
| 5009 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5010 | varp = get_varp(p); |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5011 | curbuf = save_curbuf; |
| 5012 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | else if (opt_type == SREQ_WIN) |
| 5016 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5017 | win_T *save_curwin = curwin; |
| 5018 | |
| 5019 | curwin = (win_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5020 | curbuf = curwin->w_buffer; |
| 5021 | varp = get_varp(p); |
| 5022 | curwin = save_curwin; |
| 5023 | curbuf = curwin->w_buffer; |
| 5024 | } |
| 5025 | if (varp == p->var) |
| 5026 | return (r | SOPT_UNSET); |
| 5027 | } |
| 5028 | |
| 5029 | if (varp != NULL) |
| 5030 | { |
| 5031 | if (p->flags & P_STRING) |
| 5032 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 5033 | else if (p->flags & P_NUM) |
| 5034 | *numval = *(long *) varp; |
| 5035 | else |
| 5036 | *numval = *(int *)varp; |
| 5037 | } |
| 5038 | |
| 5039 | return r; |
| 5040 | } |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5041 | |
| 5042 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5043 | * Iterate over options. First argument is a pointer to a pointer to a |
| 5044 | * structure inside options[] array, second is option type like in the above |
| 5045 | * function. |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5046 | * |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5047 | * 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] | 5048 | * and caller needs the very first value. |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5049 | * 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] | 5050 | * first argument to NULL. |
| 5051 | * |
| 5052 | * Returns full option name for current option on each call. |
| 5053 | */ |
| 5054 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5055 | option_iter_next(void **option, int opt_type) |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5056 | { |
| 5057 | struct vimoption *ret = NULL; |
| 5058 | do |
| 5059 | { |
| 5060 | if (*option == NULL) |
| 5061 | *option = (void *) options; |
| 5062 | else if (((struct vimoption *) (*option))->fullname == NULL) |
| 5063 | { |
| 5064 | *option = NULL; |
| 5065 | return NULL; |
| 5066 | } |
| 5067 | else |
| 5068 | *option = (void *) (((struct vimoption *) (*option)) + 1); |
| 5069 | |
| 5070 | ret = ((struct vimoption *) (*option)); |
| 5071 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5072 | // Hidden option |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5073 | if (ret->var == NULL) |
| 5074 | { |
| 5075 | ret = NULL; |
| 5076 | continue; |
| 5077 | } |
| 5078 | |
| 5079 | switch (opt_type) |
| 5080 | { |
| 5081 | case SREQ_GLOBAL: |
| 5082 | if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH)) |
| 5083 | ret = NULL; |
| 5084 | break; |
| 5085 | case SREQ_BUF: |
| 5086 | if (!(ret->indir & PV_BUF)) |
| 5087 | ret = NULL; |
| 5088 | break; |
| 5089 | case SREQ_WIN: |
| 5090 | if (!(ret->indir & PV_WIN)) |
| 5091 | ret = NULL; |
| 5092 | break; |
| 5093 | default: |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 5094 | internal_error("option_iter_next()"); |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5095 | return NULL; |
| 5096 | } |
| 5097 | } |
| 5098 | while (ret == NULL); |
| 5099 | |
| 5100 | return (char_u *)ret->fullname; |
| 5101 | } |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5102 | #endif |
| 5103 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5104 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5105 | * Return the flags for the option at 'opt_idx'. |
| 5106 | */ |
| 5107 | long_u |
| 5108 | get_option_flags(int opt_idx) |
| 5109 | { |
| 5110 | return options[opt_idx].flags; |
| 5111 | } |
| 5112 | |
| 5113 | /* |
| 5114 | * Set a flag for the option at 'opt_idx'. |
| 5115 | */ |
| 5116 | void |
| 5117 | set_option_flag(int opt_idx, long_u flag) |
| 5118 | { |
| 5119 | options[opt_idx].flags |= flag; |
| 5120 | } |
| 5121 | |
| 5122 | /* |
| 5123 | * Clear a flag for the option at 'opt_idx'. |
| 5124 | */ |
| 5125 | void |
| 5126 | clear_option_flag(int opt_idx, long_u flag) |
| 5127 | { |
| 5128 | options[opt_idx].flags &= ~flag; |
| 5129 | } |
| 5130 | |
| 5131 | /* |
| 5132 | * Returns TRUE if the option at 'opt_idx' is a global option |
| 5133 | */ |
| 5134 | int |
| 5135 | is_global_option(int opt_idx) |
| 5136 | { |
| 5137 | return options[opt_idx].indir == PV_NONE; |
| 5138 | } |
| 5139 | |
| 5140 | /* |
| 5141 | * Returns TRUE if the option at 'opt_idx' is a global option which also has a |
| 5142 | * local value. |
| 5143 | */ |
| 5144 | int |
| 5145 | is_global_local_option(int opt_idx) |
| 5146 | { |
| 5147 | return options[opt_idx].indir & PV_BOTH; |
| 5148 | } |
| 5149 | |
| 5150 | /* |
| 5151 | * Returns TRUE if the option at 'opt_idx' is a window-local option |
| 5152 | */ |
| 5153 | int |
| 5154 | is_window_local_option(int opt_idx) |
| 5155 | { |
| 5156 | return options[opt_idx].var == VAR_WIN; |
| 5157 | } |
| 5158 | |
| 5159 | /* |
| 5160 | * Returns TRUE if the option at 'opt_idx' is a hidden option |
| 5161 | */ |
| 5162 | int |
| 5163 | is_hidden_option(int opt_idx) |
| 5164 | { |
| 5165 | return options[opt_idx].var == NULL; |
| 5166 | } |
| 5167 | |
| 5168 | #if defined(FEAT_CRYPT) || defined(PROTO) |
| 5169 | /* |
| 5170 | * Returns TRUE if the option at 'opt_idx' is a crypt key option |
| 5171 | */ |
| 5172 | int |
| 5173 | is_crypt_key_option(int opt_idx) |
| 5174 | { |
| 5175 | return options[opt_idx].indir == PV_KEY; |
| 5176 | } |
| 5177 | #endif |
| 5178 | |
| 5179 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5180 | * Set the value of option "name". |
| 5181 | * Use "string" for string options, use "number" for other options. |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5182 | * |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5183 | * Returns NULL on success or an untranslated error message on error. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5184 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 5185 | char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5186 | set_option_value( |
| 5187 | char_u *name, |
| 5188 | long number, |
| 5189 | char_u *string, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5190 | int opt_flags) // OPT_LOCAL or 0 (both) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5191 | { |
| 5192 | int opt_idx; |
| 5193 | char_u *varp; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 5194 | long_u flags; |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5195 | static char errbuf[80]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5196 | |
| 5197 | opt_idx = findoption(name); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 5198 | if (opt_idx < 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5199 | { |
| 5200 | int key; |
| 5201 | |
| 5202 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5203 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5204 | { |
| 5205 | char_u key_name[2]; |
| 5206 | |
| 5207 | if (key < 0) |
| 5208 | { |
| 5209 | key_name[0] = KEY2TERMCAP0(key); |
| 5210 | key_name[1] = KEY2TERMCAP1(key); |
| 5211 | } |
| 5212 | else |
| 5213 | { |
| 5214 | key_name[0] = KS_KEY; |
| 5215 | key_name[1] = (key & 0xff); |
| 5216 | } |
| 5217 | add_termcode(key_name, string, FALSE); |
| 5218 | if (full_screen) |
| 5219 | ttest(FALSE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 5220 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5221 | return NULL; |
| 5222 | } |
| 5223 | |
Bram Moolenaar | ac78dd4 | 2022-01-02 19:25:26 +0000 | [diff] [blame] | 5224 | semsg(_(e_unknown_option_str_2), name); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5225 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5226 | else |
| 5227 | { |
| 5228 | flags = options[opt_idx].flags; |
| 5229 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5230 | // Disallow changing some options in the sandbox |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5231 | if (sandbox > 0 && (flags & P_SECURE)) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5232 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 5233 | emsg(_(e_not_allowed_in_sandbox)); |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5234 | return NULL; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5235 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5236 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5237 | if (flags & P_STRING) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5238 | return set_string_option(opt_idx, string, opt_flags, errbuf); |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5239 | |
| 5240 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 5241 | if (varp != NULL) // hidden option is not changed |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5242 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5243 | if (number == 0 && string != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5244 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5245 | int idx; |
| 5246 | |
| 5247 | // Either we are given a string or we are setting option |
| 5248 | // to zero. |
| 5249 | for (idx = 0; string[idx] == '0'; ++idx) |
| 5250 | ; |
| 5251 | if (string[idx] != NUL || idx == 0) |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5252 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5253 | // There's another character after zeros or the string |
| 5254 | // is empty. In both cases, we are trying to set a |
| 5255 | // num option using a string. |
| 5256 | semsg(_(e_number_required_after_str_equal_str), |
| 5257 | name, string); |
| 5258 | return NULL; // do nothing as we hit an error |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5259 | |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5260 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5261 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5262 | if (flags & P_NUM) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5263 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5264 | return set_num_option(opt_idx, varp, number, |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5265 | errbuf, sizeof(errbuf), opt_flags); |
| 5266 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5267 | else |
| 5268 | return set_bool_option(opt_idx, varp, (int)number, opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5269 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5270 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5271 | } |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5272 | return NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | /* |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5276 | * Call set_option_value() and when an error is returned report it. |
| 5277 | */ |
| 5278 | void |
| 5279 | set_option_value_give_err( |
| 5280 | char_u *name, |
| 5281 | long number, |
| 5282 | char_u *string, |
| 5283 | int opt_flags) // OPT_LOCAL or 0 (both) |
| 5284 | { |
| 5285 | char *errmsg = set_option_value(name, number, string, opt_flags); |
| 5286 | |
| 5287 | if (errmsg != NULL) |
| 5288 | emsg(_(errmsg)); |
| 5289 | } |
| 5290 | |
| 5291 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5292 | * Get the terminal code for a terminal option. |
| 5293 | * Returns NULL when not found. |
| 5294 | */ |
| 5295 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5296 | get_term_code(char_u *tname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5297 | { |
| 5298 | int opt_idx; |
| 5299 | char_u *varp; |
| 5300 | |
| 5301 | if (tname[0] != 't' || tname[1] != '_' || |
| 5302 | tname[2] == NUL || tname[3] == NUL) |
| 5303 | return NULL; |
| 5304 | if ((opt_idx = findoption(tname)) >= 0) |
| 5305 | { |
| 5306 | varp = get_varp(&(options[opt_idx])); |
| 5307 | if (varp != NULL) |
| 5308 | varp = *(char_u **)(varp); |
| 5309 | return varp; |
| 5310 | } |
| 5311 | return find_termcode(tname + 2); |
| 5312 | } |
| 5313 | |
| 5314 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5315 | get_highlight_default(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5316 | { |
| 5317 | int i; |
| 5318 | |
| 5319 | i = findoption((char_u *)"hl"); |
| 5320 | if (i >= 0) |
| 5321 | return options[i].def_val[VI_DEFAULT]; |
| 5322 | return (char_u *)NULL; |
| 5323 | } |
| 5324 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5325 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5326 | get_encoding_default(void) |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5327 | { |
| 5328 | int i; |
| 5329 | |
| 5330 | i = findoption((char_u *)"enc"); |
| 5331 | if (i >= 0) |
| 5332 | return options[i].def_val[VI_DEFAULT]; |
| 5333 | return (char_u *)NULL; |
| 5334 | } |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5335 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5336 | #if defined(FEAT_QUICKFIX) || defined(PROTO) |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5337 | int |
| 5338 | is_option_allocated(char *name) |
| 5339 | { |
| 5340 | int idx = findoption((char_u *)name); |
| 5341 | |
| 5342 | return idx >= 0 && (options[idx].flags & P_ALLOCED); |
| 5343 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5344 | #endif |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5345 | |
Bram Moolenaar | 28f84e1 | 2022-07-27 12:30:13 +0100 | [diff] [blame] | 5346 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 5347 | /* |
| 5348 | * Return TRUE if "name" is a string option. |
| 5349 | * Returns FALSE if option "name" does not exist. |
| 5350 | */ |
| 5351 | int |
| 5352 | is_string_option(char_u *name) |
| 5353 | { |
| 5354 | int idx = findoption(name); |
| 5355 | |
| 5356 | return idx >= 0 && (options[idx].flags & P_STRING); |
| 5357 | } |
| 5358 | #endif |
| 5359 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5360 | /* |
| 5361 | * 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] | 5362 | * When "has_lt" is true there is a '<' before "*arg_arg". |
| 5363 | * Returns 0 when the key is not recognized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5364 | */ |
| 5365 | static int |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5366 | find_key_option(char_u *arg_arg, int has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5367 | { |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5368 | int key = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5369 | int modifiers; |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5370 | char_u *arg = arg_arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5371 | |
| 5372 | /* |
| 5373 | * Don't use get_special_key_code() for t_xx, we don't want it to call |
| 5374 | * add_termcap_entry(). |
| 5375 | */ |
| 5376 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 5377 | key = TERMCAP2KEY(arg[2], arg[3]); |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5378 | else if (has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5379 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5380 | --arg; // put arg at the '<' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5381 | modifiers = 0; |
Bram Moolenaar | ebe9d34 | 2020-05-30 21:52:54 +0200 | [diff] [blame] | 5382 | key = find_special_key(&arg, &modifiers, |
| 5383 | FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5384 | if (modifiers) // can't handle modifiers here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5385 | key = 0; |
| 5386 | } |
| 5387 | return key; |
| 5388 | } |
| 5389 | |
| 5390 | /* |
| 5391 | * if 'all' == 0: show changed options |
| 5392 | * if 'all' == 1: show all normal options |
| 5393 | * if 'all' == 2: show all terminal options |
| 5394 | */ |
| 5395 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5396 | showoptions( |
| 5397 | int all, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5398 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5399 | { |
| 5400 | struct vimoption *p; |
| 5401 | int col; |
| 5402 | int isterm; |
| 5403 | char_u *varp; |
| 5404 | struct vimoption **items; |
| 5405 | int item_count; |
| 5406 | int run; |
| 5407 | int row, rows; |
| 5408 | int cols; |
| 5409 | int i; |
| 5410 | int len; |
| 5411 | |
| 5412 | #define INC 20 |
| 5413 | #define GAP 3 |
| 5414 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5415 | items = ALLOC_MULT(struct vimoption *, OPTION_COUNT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5416 | if (items == NULL) |
| 5417 | return; |
| 5418 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5419 | // Highlight title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5420 | if (all == 2) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5421 | msg_puts_title(_("\n--- Terminal codes ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5422 | else if (opt_flags & OPT_GLOBAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5423 | msg_puts_title(_("\n--- Global option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5424 | else if (opt_flags & OPT_LOCAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5425 | msg_puts_title(_("\n--- Local option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5426 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5427 | msg_puts_title(_("\n--- Options ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5428 | |
| 5429 | /* |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5430 | * Do the loop two times: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5431 | * 1. display the short items |
| 5432 | * 2. display the long items (only strings and numbers) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5433 | * When "opt_flags" has OPT_ONECOLUMN do everything in run 2. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5434 | */ |
| 5435 | for (run = 1; run <= 2 && !got_int; ++run) |
| 5436 | { |
| 5437 | /* |
| 5438 | * collect the items in items[] |
| 5439 | */ |
| 5440 | item_count = 0; |
| 5441 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5442 | { |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5443 | // apply :filter /pat/ |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5444 | if (message_filtered((char_u *)p->fullname)) |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5445 | continue; |
| 5446 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5447 | varp = NULL; |
| 5448 | isterm = istermoption(p); |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5449 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5450 | { |
| 5451 | if (p->indir != PV_NONE && !isterm) |
| 5452 | varp = get_varp_scope(p, opt_flags); |
| 5453 | } |
| 5454 | else |
| 5455 | varp = get_varp(p); |
| 5456 | if (varp != NULL |
| 5457 | && ((all == 2 && isterm) |
| 5458 | || (all == 1 && !isterm) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5459 | || (all == 0 && !optval_default(p, varp, p_cp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5460 | { |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5461 | if (opt_flags & OPT_ONECOLUMN) |
| 5462 | len = Columns; |
| 5463 | else if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5464 | len = 1; // a toggle option fits always |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5465 | else |
| 5466 | { |
| 5467 | option_value2string(p, opt_flags); |
| 5468 | len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; |
| 5469 | } |
| 5470 | if ((len <= INC - GAP && run == 1) || |
| 5471 | (len > INC - GAP && run == 2)) |
| 5472 | items[item_count++] = p; |
| 5473 | } |
| 5474 | } |
| 5475 | |
| 5476 | /* |
| 5477 | * display the items |
| 5478 | */ |
| 5479 | if (run == 1) |
| 5480 | { |
| 5481 | cols = (Columns + GAP - 3) / INC; |
| 5482 | if (cols == 0) |
| 5483 | cols = 1; |
| 5484 | rows = (item_count + cols - 1) / cols; |
| 5485 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5486 | else // run == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5487 | rows = item_count; |
| 5488 | for (row = 0; row < rows && !got_int; ++row) |
| 5489 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5490 | msg_putchar('\n'); // go to next line |
| 5491 | if (got_int) // 'q' typed in more |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5492 | break; |
| 5493 | col = 0; |
| 5494 | for (i = row; i < item_count; i += rows) |
| 5495 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5496 | msg_col = col; // make columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5497 | showoneopt(items[i], opt_flags); |
| 5498 | col += INC; |
| 5499 | } |
| 5500 | out_flush(); |
| 5501 | ui_breakcheck(); |
| 5502 | } |
| 5503 | } |
| 5504 | vim_free(items); |
| 5505 | } |
| 5506 | |
| 5507 | /* |
| 5508 | * Return TRUE if option "p" has its default value. |
| 5509 | */ |
| 5510 | static int |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5511 | optval_default(struct vimoption *p, char_u *varp, int compatible) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5512 | { |
| 5513 | int dvi; |
| 5514 | |
| 5515 | if (varp == NULL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5516 | return TRUE; // hidden option is always at default |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5517 | dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5518 | if (p->flags & P_NUM) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5519 | return (*(long *)varp == (long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5520 | if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5521 | // the cast to long is required for Manx C, long_i is |
| 5522 | // needed for MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5523 | return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5524 | // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5525 | return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); |
| 5526 | } |
| 5527 | |
| 5528 | /* |
| 5529 | * showoneopt: show the value of one option |
| 5530 | * must not be called with a hidden option! |
| 5531 | */ |
| 5532 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5533 | showoneopt( |
| 5534 | struct vimoption *p, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5535 | int opt_flags) // OPT_LOCAL or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5536 | { |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5537 | char_u *varp; |
| 5538 | int save_silent = silent_mode; |
| 5539 | |
| 5540 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5541 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5542 | |
| 5543 | varp = get_varp_scope(p, opt_flags); |
| 5544 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5545 | // for 'modified' we also need to check if 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5546 | if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed |
| 5547 | ? !curbufIsChanged() : !*(int *)varp)) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5548 | msg_puts("no"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5549 | else if ((p->flags & P_BOOL) && *(int *)varp < 0) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5550 | msg_puts("--"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5551 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5552 | msg_puts(" "); |
| 5553 | msg_puts(p->fullname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5554 | if (!(p->flags & P_BOOL)) |
| 5555 | { |
| 5556 | msg_putchar('='); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5557 | // put value string in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5558 | option_value2string(p, opt_flags); |
| 5559 | msg_outtrans(NameBuff); |
| 5560 | } |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5561 | |
| 5562 | silent_mode = save_silent; |
| 5563 | info_message = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | /* |
| 5567 | * Write modified options as ":set" commands to a file. |
| 5568 | * |
| 5569 | * There are three values for "opt_flags": |
| 5570 | * OPT_GLOBAL: Write global option values and fresh values of |
| 5571 | * buffer-local options (used for start of a session |
| 5572 | * file). |
| 5573 | * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for |
| 5574 | * curwin (used for a vimrc file). |
| 5575 | * OPT_LOCAL: Write buffer-local option values for curbuf, fresh |
| 5576 | * and local values for window-local options of |
| 5577 | * curwin. Local values are also written when at the |
| 5578 | * default value, because a modeline or autocommand |
| 5579 | * may have set them when doing ":edit file" and the |
| 5580 | * user has set them back at the default or fresh |
| 5581 | * value. |
| 5582 | * When "local_only" is TRUE, don't write fresh |
| 5583 | * values, only local values (for ":mkview"). |
| 5584 | * (fresh value = value used for a new buffer or window for a local option). |
| 5585 | * |
| 5586 | * Return FAIL on error, OK otherwise. |
| 5587 | */ |
| 5588 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5589 | makeset(FILE *fd, int opt_flags, int local_only) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5590 | { |
| 5591 | struct vimoption *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5592 | char_u *varp; // currently used value |
| 5593 | char_u *varp_fresh; // local value |
| 5594 | char_u *varp_local = NULL; // fresh value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5595 | char *cmd; |
| 5596 | int round; |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5597 | int pri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5598 | |
| 5599 | /* |
| 5600 | * The options that don't have a default (terminal name, columns, lines) |
| 5601 | * are never written. Terminal options are also not written. |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5602 | * Do the loop over "options[]" twice: once for options with the |
| 5603 | * P_PRI_MKRC flag and once without. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5604 | */ |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5605 | for (pri = 1; pri >= 0; --pri) |
| 5606 | { |
| 5607 | for (p = &options[0]; !istermoption(p); p++) |
| 5608 | if (!(p->flags & P_NO_MKRC) |
| 5609 | && !istermoption(p) |
| 5610 | && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5611 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5612 | // skip global option when only doing locals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5613 | if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) |
| 5614 | continue; |
| 5615 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5616 | // Do not store options like 'bufhidden' and 'syntax' in a vimrc |
| 5617 | // file, they are always buffer-specific. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5618 | if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) |
| 5619 | continue; |
| 5620 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5621 | // Global values are only written when not at the default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5622 | varp = get_varp_scope(p, opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5623 | if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5624 | continue; |
| 5625 | |
Bram Moolenaar | d23b714 | 2021-04-17 21:04:34 +0200 | [diff] [blame] | 5626 | if ((opt_flags & OPT_SKIPRTP) && (p->var == (char_u *)&p_rtp |
| 5627 | || p->var == (char_u *)&p_pp)) |
Bram Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 5628 | continue; |
| 5629 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5630 | round = 2; |
| 5631 | if (p->indir != PV_NONE) |
| 5632 | { |
| 5633 | if (p->var == VAR_WIN) |
| 5634 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5635 | // skip window-local option when only doing globals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5636 | if (!(opt_flags & OPT_LOCAL)) |
| 5637 | continue; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5638 | // When fresh value of window-local option is not at the |
| 5639 | // default, need to write it too. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5640 | if (!(opt_flags & OPT_GLOBAL) && !local_only) |
| 5641 | { |
| 5642 | varp_fresh = get_varp_scope(p, OPT_GLOBAL); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5643 | if (!optval_default(p, varp_fresh, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5644 | { |
| 5645 | round = 1; |
| 5646 | varp_local = varp; |
| 5647 | varp = varp_fresh; |
| 5648 | } |
| 5649 | } |
| 5650 | } |
| 5651 | } |
| 5652 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5653 | // Round 1: fresh value for window-local options. |
| 5654 | // Round 2: other values |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5655 | for ( ; round <= 2; varp = varp_local, ++round) |
| 5656 | { |
| 5657 | if (round == 1 || (opt_flags & OPT_GLOBAL)) |
| 5658 | cmd = "set"; |
| 5659 | else |
| 5660 | cmd = "setlocal"; |
| 5661 | |
| 5662 | if (p->flags & P_BOOL) |
| 5663 | { |
| 5664 | if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) |
| 5665 | return FAIL; |
| 5666 | } |
| 5667 | else if (p->flags & P_NUM) |
| 5668 | { |
| 5669 | if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) |
| 5670 | return FAIL; |
| 5671 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5672 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5673 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5674 | int do_endif = FALSE; |
| 5675 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5676 | // Don't set 'syntax' and 'filetype' again if the value is |
| 5677 | // already right, avoids reloading the syntax file. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5678 | if ( |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 5679 | #if defined(FEAT_SYN_HL) |
| 5680 | p->indir == PV_SYN || |
| 5681 | #endif |
| 5682 | p->indir == PV_FT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5683 | { |
| 5684 | if (fprintf(fd, "if &%s != '%s'", p->fullname, |
| 5685 | *(char_u **)(varp)) < 0 |
| 5686 | || put_eol(fd) < 0) |
| 5687 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5688 | do_endif = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5689 | } |
| 5690 | if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5691 | p->flags) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5692 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5693 | if (do_endif) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5694 | { |
| 5695 | if (put_line(fd, "endif") == FAIL) |
| 5696 | return FAIL; |
| 5697 | } |
| 5698 | } |
| 5699 | } |
| 5700 | } |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5701 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5702 | return OK; |
| 5703 | } |
| 5704 | |
| 5705 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 5706 | /* |
| 5707 | * Generate set commands for the local fold options only. Used when |
| 5708 | * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". |
| 5709 | */ |
| 5710 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5711 | makefoldset(FILE *fd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5712 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5713 | if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5714 | # ifdef FEAT_EVAL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5715 | || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5716 | == FAIL |
| 5717 | # endif |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5718 | || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5719 | == FAIL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5720 | || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5721 | == FAIL |
| 5722 | || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL |
| 5723 | || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL |
| 5724 | || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL |
| 5725 | || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL |
| 5726 | ) |
| 5727 | return FAIL; |
| 5728 | |
| 5729 | return OK; |
| 5730 | } |
| 5731 | #endif |
| 5732 | |
| 5733 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5734 | put_setstring( |
| 5735 | FILE *fd, |
| 5736 | char *cmd, |
| 5737 | char *name, |
| 5738 | char_u **valuep, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5739 | long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5740 | { |
| 5741 | char_u *s; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5742 | char_u *buf = NULL; |
| 5743 | char_u *part = NULL; |
| 5744 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5745 | |
| 5746 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5747 | return FAIL; |
| 5748 | if (*valuep != NULL) |
| 5749 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5750 | // Output 'pastetoggle' as key names. For other |
| 5751 | // options some characters have to be escaped with |
| 5752 | // CTRL-V or backslash |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5753 | if (valuep == &p_pt) |
| 5754 | { |
| 5755 | s = *valuep; |
| 5756 | while (*s != NUL) |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 5757 | if (put_escstr(fd, str2special(&s, FALSE, FALSE), 2) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5758 | return FAIL; |
| 5759 | } |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5760 | // expand the option value, replace $HOME by ~ |
| 5761 | else if ((flags & P_EXPAND) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5762 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5763 | int size = (int)STRLEN(*valuep) + 1; |
| 5764 | |
| 5765 | // replace home directory in the whole option value into "buf" |
| 5766 | buf = alloc(size); |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5767 | if (buf == NULL) |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5768 | goto fail; |
| 5769 | home_replace(NULL, *valuep, buf, size, FALSE); |
| 5770 | |
| 5771 | // If the option value is longer than MAXPATHL, we need to append |
Bram Moolenaar | 32aa102 | 2019-11-02 22:54:41 +0100 | [diff] [blame] | 5772 | // each comma separated part of the option separately, so that it |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5773 | // can be expanded when read back. |
| 5774 | if (size >= MAXPATHL && (flags & P_COMMA) != 0 |
| 5775 | && vim_strchr(*valuep, ',') != NULL) |
| 5776 | { |
| 5777 | part = alloc(size); |
| 5778 | if (part == NULL) |
| 5779 | goto fail; |
| 5780 | |
| 5781 | // write line break to clear the option, e.g. ':set rtp=' |
| 5782 | if (put_eol(fd) == FAIL) |
| 5783 | goto fail; |
| 5784 | |
| 5785 | p = buf; |
| 5786 | while (*p != NUL) |
| 5787 | { |
| 5788 | // for each comma separated option part, append value to |
| 5789 | // the option, :set rtp+=value |
| 5790 | if (fprintf(fd, "%s %s+=", cmd, name) < 0) |
| 5791 | goto fail; |
| 5792 | (void)copy_option_part(&p, part, size, ","); |
| 5793 | if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) |
| 5794 | goto fail; |
| 5795 | } |
| 5796 | vim_free(buf); |
| 5797 | vim_free(part); |
| 5798 | return OK; |
| 5799 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5800 | if (put_escstr(fd, buf, 2) == FAIL) |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5801 | { |
| 5802 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5803 | return FAIL; |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5804 | } |
| 5805 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5806 | } |
| 5807 | else if (put_escstr(fd, *valuep, 2) == FAIL) |
| 5808 | return FAIL; |
| 5809 | } |
| 5810 | if (put_eol(fd) < 0) |
| 5811 | return FAIL; |
| 5812 | return OK; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5813 | fail: |
| 5814 | vim_free(buf); |
| 5815 | vim_free(part); |
| 5816 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5820 | put_setnum( |
| 5821 | FILE *fd, |
| 5822 | char *cmd, |
| 5823 | char *name, |
| 5824 | long *valuep) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5825 | { |
| 5826 | long wc; |
| 5827 | |
| 5828 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5829 | return FAIL; |
| 5830 | if (wc_use_keyname((char_u *)valuep, &wc)) |
| 5831 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5832 | // print 'wildchar' and 'wildcharm' as a key name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5833 | if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) |
| 5834 | return FAIL; |
| 5835 | } |
| 5836 | else if (fprintf(fd, "%ld", *valuep) < 0) |
| 5837 | return FAIL; |
| 5838 | if (put_eol(fd) < 0) |
| 5839 | return FAIL; |
| 5840 | return OK; |
| 5841 | } |
| 5842 | |
| 5843 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5844 | put_setbool( |
| 5845 | FILE *fd, |
| 5846 | char *cmd, |
| 5847 | char *name, |
| 5848 | int value) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5849 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5850 | if (value < 0) // global/local option using global value |
Bram Moolenaar | 893de92 | 2007-10-02 18:40:57 +0000 | [diff] [blame] | 5851 | return OK; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5852 | if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 |
| 5853 | || put_eol(fd) < 0) |
| 5854 | return FAIL; |
| 5855 | return OK; |
| 5856 | } |
| 5857 | |
| 5858 | /* |
| 5859 | * Clear all the terminal options. |
| 5860 | * If the option has been allocated, free the memory. |
| 5861 | * Terminal options are never hidden or indirect. |
| 5862 | */ |
| 5863 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5864 | clear_termoptions(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5865 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5866 | /* |
| 5867 | * Reset a few things before clearing the old options. This may cause |
| 5868 | * outputting a few things that the terminal doesn't understand, but the |
| 5869 | * screen will be cleared later, so this is OK. |
| 5870 | */ |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 5871 | mch_setmouse(FALSE); // switch mouse off |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5872 | mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5873 | #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5874 | // When starting the GUI close the display opened for the clipboard. |
| 5875 | // After restoring the title, because that will need the display. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5876 | if (gui.starting) |
| 5877 | clear_xterm_clip(); |
| 5878 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5879 | stoptermcap(); // stop termcap mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5880 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 5881 | free_termoptions(); |
| 5882 | } |
| 5883 | |
| 5884 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5885 | free_termoptions(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 5886 | { |
| 5887 | struct vimoption *p; |
| 5888 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 5889 | for (p = options; p->fullname != NULL; p++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5890 | if (istermoption(p)) |
| 5891 | { |
| 5892 | if (p->flags & P_ALLOCED) |
| 5893 | free_string_option(*(char_u **)(p->var)); |
| 5894 | if (p->flags & P_DEF_ALLOCED) |
| 5895 | free_string_option(p->def_val[VI_DEFAULT]); |
| 5896 | *(char_u **)(p->var) = empty_option; |
| 5897 | p->def_val[VI_DEFAULT] = empty_option; |
| 5898 | p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 5899 | #ifdef FEAT_EVAL |
| 5900 | // remember where the option was cleared |
| 5901 | set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx); |
| 5902 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5903 | } |
| 5904 | clear_termcodes(); |
| 5905 | } |
| 5906 | |
| 5907 | /* |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 5908 | * Free the string for one term option, if it was allocated. |
| 5909 | * Set the string to empty_option and clear allocated flag. |
| 5910 | * "var" points to the option value. |
| 5911 | */ |
| 5912 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5913 | free_one_termoption(char_u *var) |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 5914 | { |
| 5915 | struct vimoption *p; |
| 5916 | |
| 5917 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5918 | if (p->var == var) |
| 5919 | { |
| 5920 | if (p->flags & P_ALLOCED) |
| 5921 | free_string_option(*(char_u **)(p->var)); |
| 5922 | *(char_u **)(p->var) = empty_option; |
| 5923 | p->flags &= ~P_ALLOCED; |
| 5924 | break; |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5929 | * Set the terminal option defaults to the current value. |
| 5930 | * Used after setting the terminal name. |
| 5931 | */ |
| 5932 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5933 | set_term_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5934 | { |
| 5935 | struct vimoption *p; |
| 5936 | |
| 5937 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5938 | { |
| 5939 | if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) |
| 5940 | { |
| 5941 | if (p->flags & P_DEF_ALLOCED) |
| 5942 | { |
| 5943 | free_string_option(p->def_val[VI_DEFAULT]); |
| 5944 | p->flags &= ~P_DEF_ALLOCED; |
| 5945 | } |
| 5946 | p->def_val[VI_DEFAULT] = *(char_u **)(p->var); |
| 5947 | if (p->flags & P_ALLOCED) |
| 5948 | { |
| 5949 | p->flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5950 | p->flags &= ~P_ALLOCED; // don't free the value now |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5951 | } |
| 5952 | } |
| 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | /* |
| 5957 | * return TRUE if 'p' starts with 't_' |
| 5958 | */ |
| 5959 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5960 | istermoption(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5961 | { |
| 5962 | return (p->fullname[0] == 't' && p->fullname[1] == '_'); |
| 5963 | } |
| 5964 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5965 | /* |
| 5966 | * Returns TRUE if the option at 'opt_idx' starts with 't_' |
| 5967 | */ |
| 5968 | int |
| 5969 | istermoption_idx(int opt_idx) |
| 5970 | { |
| 5971 | return istermoption(&options[opt_idx]); |
| 5972 | } |
| 5973 | |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 5974 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5975 | /* |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5976 | * Unset local option value, similar to ":set opt<". |
| 5977 | */ |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5978 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5979 | unset_global_local_option(char_u *name, void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5980 | { |
| 5981 | struct vimoption *p; |
| 5982 | int opt_idx; |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5983 | buf_T *buf = (buf_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5984 | |
| 5985 | opt_idx = findoption(name); |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 5986 | if (opt_idx < 0) |
| 5987 | return; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5988 | p = &(options[opt_idx]); |
| 5989 | |
| 5990 | switch ((int)p->indir) |
| 5991 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5992 | // 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] | 5993 | case PV_EP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5994 | clear_string_option(&buf->b_p_ep); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5995 | break; |
| 5996 | case PV_KP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 5997 | clear_string_option(&buf->b_p_kp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5998 | break; |
| 5999 | case PV_PATH: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6000 | clear_string_option(&buf->b_p_path); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6001 | break; |
| 6002 | case PV_AR: |
| 6003 | buf->b_p_ar = -1; |
| 6004 | break; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6005 | case PV_BKC: |
| 6006 | clear_string_option(&buf->b_p_bkc); |
| 6007 | buf->b_bkc_flags = 0; |
| 6008 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6009 | case PV_TAGS: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6010 | clear_string_option(&buf->b_p_tags); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6011 | break; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6012 | case PV_TC: |
| 6013 | clear_string_option(&buf->b_p_tc); |
| 6014 | buf->b_tc_flags = 0; |
| 6015 | break; |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6016 | case PV_SISO: |
| 6017 | curwin->w_p_siso = -1; |
| 6018 | break; |
| 6019 | case PV_SO: |
| 6020 | curwin->w_p_so = -1; |
| 6021 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6022 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6023 | case PV_DEF: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6024 | clear_string_option(&buf->b_p_def); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6025 | break; |
| 6026 | case PV_INC: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6027 | clear_string_option(&buf->b_p_inc); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6028 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6029 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6030 | case PV_DICT: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6031 | clear_string_option(&buf->b_p_dict); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6032 | break; |
| 6033 | case PV_TSR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6034 | clear_string_option(&buf->b_p_tsr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6035 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6036 | # ifdef FEAT_COMPL_FUNC |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6037 | case PV_TSRFU: |
| 6038 | clear_string_option(&buf->b_p_tsrfu); |
| 6039 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6040 | # endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6041 | case PV_FP: |
| 6042 | clear_string_option(&buf->b_p_fp); |
| 6043 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6044 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6045 | case PV_EFM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6046 | clear_string_option(&buf->b_p_efm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6047 | break; |
| 6048 | case PV_GP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6049 | clear_string_option(&buf->b_p_gp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6050 | break; |
| 6051 | case PV_MP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6052 | clear_string_option(&buf->b_p_mp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6053 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6054 | # endif |
| 6055 | # if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6056 | case PV_BEXPR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6057 | clear_string_option(&buf->b_p_bexpr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6058 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6059 | # endif |
| 6060 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6061 | case PV_CM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6062 | clear_string_option(&buf->b_p_cm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6063 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6064 | # endif |
| 6065 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6066 | case PV_SBR: |
| 6067 | clear_string_option(&((win_T *)from)->w_p_sbr); |
| 6068 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6069 | # endif |
| 6070 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6071 | case PV_STL: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6072 | clear_string_option(&((win_T *)from)->w_p_stl); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6073 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6074 | # endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6075 | case PV_UL: |
| 6076 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
| 6077 | break; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6078 | case PV_LW: |
| 6079 | clear_string_option(&buf->b_p_lw); |
| 6080 | break; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6081 | case PV_MENC: |
| 6082 | clear_string_option(&buf->b_p_menc); |
| 6083 | break; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6084 | case PV_LCS: |
| 6085 | clear_string_option(&((win_T *)from)->w_p_lcs); |
Bram Moolenaar | b67f0c8 | 2022-07-04 21:03:36 +0100 | [diff] [blame] | 6086 | set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, TRUE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 6087 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6088 | break; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6089 | case PV_FCS: |
| 6090 | clear_string_option(&((win_T *)from)->w_p_fcs); |
Bram Moolenaar | b67f0c8 | 2022-07-04 21:03:36 +0100 | [diff] [blame] | 6091 | set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, TRUE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 6092 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6093 | break; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6094 | case PV_VE: |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6095 | clear_string_option(&((win_T *)from)->w_p_ve); |
| 6096 | ((win_T *)from)->w_ve_flags = 0; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6097 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6098 | } |
| 6099 | } |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 6100 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6101 | |
| 6102 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6103 | * Get pointer to option variable, depending on local or global scope. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6104 | * "scope" can be OPT_LOCAL, OPT_GLOBAL or a combination. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6105 | */ |
| 6106 | static char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6107 | get_varp_scope(struct vimoption *p, int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6108 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6109 | if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6110 | { |
| 6111 | if (p->var == VAR_WIN) |
| 6112 | return (char_u *)GLOBAL_WO(get_varp(p)); |
| 6113 | return p->var; |
| 6114 | } |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6115 | if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6116 | { |
| 6117 | switch ((int)p->indir) |
| 6118 | { |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6119 | case PV_FP: return (char_u *)&(curbuf->b_p_fp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6120 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6121 | case PV_EFM: return (char_u *)&(curbuf->b_p_efm); |
| 6122 | case PV_GP: return (char_u *)&(curbuf->b_p_gp); |
| 6123 | case PV_MP: return (char_u *)&(curbuf->b_p_mp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6124 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6125 | case PV_EP: return (char_u *)&(curbuf->b_p_ep); |
| 6126 | case PV_KP: return (char_u *)&(curbuf->b_p_kp); |
| 6127 | case PV_PATH: return (char_u *)&(curbuf->b_p_path); |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6128 | case PV_AR: return (char_u *)&(curbuf->b_p_ar); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6129 | case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6130 | case PV_TC: return (char_u *)&(curbuf->b_p_tc); |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6131 | case PV_SISO: return (char_u *)&(curwin->w_p_siso); |
| 6132 | case PV_SO: return (char_u *)&(curwin->w_p_so); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6133 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6134 | case PV_DEF: return (char_u *)&(curbuf->b_p_def); |
| 6135 | case PV_INC: return (char_u *)&(curbuf->b_p_inc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6136 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6137 | case PV_DICT: return (char_u *)&(curbuf->b_p_dict); |
| 6138 | case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6139 | #ifdef FEAT_COMPL_FUNC |
| 6140 | case PV_TSRFU: return (char_u *)&(curbuf->b_p_tsrfu); |
| 6141 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6142 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6143 | case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr); |
| 6144 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6145 | #if defined(FEAT_CRYPT) |
| 6146 | case PV_CM: return (char_u *)&(curbuf->b_p_cm); |
| 6147 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6148 | #ifdef FEAT_LINEBREAK |
| 6149 | case PV_SBR: return (char_u *)&(curwin->w_p_sbr); |
| 6150 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6151 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6152 | case PV_STL: return (char_u *)&(curwin->w_p_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6153 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6154 | case PV_UL: return (char_u *)&(curbuf->b_p_ul); |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6155 | case PV_LW: return (char_u *)&(curbuf->b_p_lw); |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6156 | case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6157 | case PV_MENC: return (char_u *)&(curbuf->b_p_menc); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6158 | case PV_LCS: return (char_u *)&(curwin->w_p_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6159 | case PV_FCS: return (char_u *)&(curwin->w_p_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6160 | case PV_VE: return (char_u *)&(curwin->w_p_ve); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6161 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6162 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6163 | return NULL; // "cannot happen" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6164 | } |
| 6165 | return get_varp(p); |
| 6166 | } |
| 6167 | |
| 6168 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6169 | * Get pointer to option variable at 'opt_idx', depending on local or global |
| 6170 | * scope. |
| 6171 | */ |
| 6172 | char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6173 | get_option_varp_scope(int opt_idx, int scope) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6174 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6175 | return get_varp_scope(&(options[opt_idx]), scope); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6179 | * Get pointer to option variable. |
| 6180 | */ |
| 6181 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6182 | get_varp(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6183 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6184 | // hidden option, always return NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6185 | if (p->var == NULL) |
| 6186 | return NULL; |
| 6187 | |
| 6188 | switch ((int)p->indir) |
| 6189 | { |
| 6190 | case PV_NONE: return p->var; |
| 6191 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6192 | // 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] | 6193 | case PV_EP: return *curbuf->b_p_ep != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6194 | ? (char_u *)&curbuf->b_p_ep : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6195 | case PV_KP: return *curbuf->b_p_kp != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6196 | ? (char_u *)&curbuf->b_p_kp : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6197 | case PV_PATH: return *curbuf->b_p_path != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6198 | ? (char_u *)&(curbuf->b_p_path) : p->var; |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6199 | case PV_AR: return curbuf->b_p_ar >= 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6200 | ? (char_u *)&(curbuf->b_p_ar) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6201 | case PV_TAGS: return *curbuf->b_p_tags != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6202 | ? (char_u *)&(curbuf->b_p_tags) : p->var; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6203 | case PV_TC: return *curbuf->b_p_tc != NUL |
| 6204 | ? (char_u *)&(curbuf->b_p_tc) : p->var; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6205 | case PV_BKC: return *curbuf->b_p_bkc != NUL |
| 6206 | ? (char_u *)&(curbuf->b_p_bkc) : p->var; |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 6207 | case PV_SISO: return curwin->w_p_siso >= 0 |
| 6208 | ? (char_u *)&(curwin->w_p_siso) : p->var; |
| 6209 | case PV_SO: return curwin->w_p_so >= 0 |
| 6210 | ? (char_u *)&(curwin->w_p_so) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6211 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6212 | case PV_DEF: return *curbuf->b_p_def != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6213 | ? (char_u *)&(curbuf->b_p_def) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6214 | case PV_INC: return *curbuf->b_p_inc != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6215 | ? (char_u *)&(curbuf->b_p_inc) : p->var; |
| 6216 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6217 | case PV_DICT: return *curbuf->b_p_dict != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6218 | ? (char_u *)&(curbuf->b_p_dict) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6219 | case PV_TSR: return *curbuf->b_p_tsr != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6220 | ? (char_u *)&(curbuf->b_p_tsr) : p->var; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6221 | #ifdef FEAT_COMPL_FUNC |
| 6222 | case PV_TSRFU: return *curbuf->b_p_tsrfu != NUL |
| 6223 | ? (char_u *)&(curbuf->b_p_tsrfu) : p->var; |
| 6224 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6225 | case PV_FP: return *curbuf->b_p_fp != NUL |
| 6226 | ? (char_u *)&(curbuf->b_p_fp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6227 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6228 | case PV_EFM: return *curbuf->b_p_efm != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6229 | ? (char_u *)&(curbuf->b_p_efm) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6230 | case PV_GP: return *curbuf->b_p_gp != NUL |
| 6231 | ? (char_u *)&(curbuf->b_p_gp) : p->var; |
| 6232 | case PV_MP: return *curbuf->b_p_mp != NUL |
| 6233 | ? (char_u *)&(curbuf->b_p_mp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6234 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6235 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6236 | case PV_BEXPR: return *curbuf->b_p_bexpr != NUL |
| 6237 | ? (char_u *)&(curbuf->b_p_bexpr) : p->var; |
| 6238 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6239 | #if defined(FEAT_CRYPT) |
| 6240 | case PV_CM: return *curbuf->b_p_cm != NUL |
| 6241 | ? (char_u *)&(curbuf->b_p_cm) : p->var; |
| 6242 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6243 | #ifdef FEAT_LINEBREAK |
| 6244 | case PV_SBR: return *curwin->w_p_sbr != NUL |
| 6245 | ? (char_u *)&(curwin->w_p_sbr) : p->var; |
| 6246 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6247 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6248 | case PV_STL: return *curwin->w_p_stl != NUL |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6249 | ? (char_u *)&(curwin->w_p_stl) : p->var; |
| 6250 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6251 | case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL |
| 6252 | ? (char_u *)&(curbuf->b_p_ul) : p->var; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6253 | case PV_LW: return *curbuf->b_p_lw != NUL |
| 6254 | ? (char_u *)&(curbuf->b_p_lw) : p->var; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6255 | case PV_MENC: return *curbuf->b_p_menc != NUL |
| 6256 | ? (char_u *)&(curbuf->b_p_menc) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6257 | #ifdef FEAT_ARABIC |
| 6258 | case PV_ARAB: return (char_u *)&(curwin->w_p_arab); |
| 6259 | #endif |
| 6260 | case PV_LIST: return (char_u *)&(curwin->w_p_list); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6261 | case PV_LCS: return *curwin->w_p_lcs != NUL |
| 6262 | ? (char_u *)&(curwin->w_p_lcs) : p->var; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6263 | case PV_FCS: return *curwin->w_p_fcs != NUL |
| 6264 | ? (char_u *)&(curwin->w_p_fcs) : p->var; |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6265 | case PV_VE: return *curwin->w_p_ve != NUL |
| 6266 | ? (char_u *)&(curwin->w_p_ve) : p->var; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6267 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6268 | case PV_SPELL: return (char_u *)&(curwin->w_p_spell); |
| 6269 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6270 | #ifdef FEAT_SYN_HL |
| 6271 | case PV_CUC: return (char_u *)&(curwin->w_p_cuc); |
| 6272 | case PV_CUL: return (char_u *)&(curwin->w_p_cul); |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6273 | case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6274 | case PV_CC: return (char_u *)&(curwin->w_p_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6275 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6276 | #ifdef FEAT_DIFF |
| 6277 | case PV_DIFF: return (char_u *)&(curwin->w_p_diff); |
| 6278 | #endif |
| 6279 | #ifdef FEAT_FOLDING |
| 6280 | case PV_FDC: return (char_u *)&(curwin->w_p_fdc); |
| 6281 | case PV_FEN: return (char_u *)&(curwin->w_p_fen); |
| 6282 | case PV_FDI: return (char_u *)&(curwin->w_p_fdi); |
| 6283 | case PV_FDL: return (char_u *)&(curwin->w_p_fdl); |
| 6284 | case PV_FDM: return (char_u *)&(curwin->w_p_fdm); |
| 6285 | case PV_FML: return (char_u *)&(curwin->w_p_fml); |
| 6286 | case PV_FDN: return (char_u *)&(curwin->w_p_fdn); |
| 6287 | # ifdef FEAT_EVAL |
| 6288 | case PV_FDE: return (char_u *)&(curwin->w_p_fde); |
| 6289 | case PV_FDT: return (char_u *)&(curwin->w_p_fdt); |
| 6290 | # endif |
| 6291 | case PV_FMR: return (char_u *)&(curwin->w_p_fmr); |
| 6292 | #endif |
| 6293 | case PV_NU: return (char_u *)&(curwin->w_p_nu); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6294 | case PV_RNU: return (char_u *)&(curwin->w_p_rnu); |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6295 | #ifdef FEAT_LINEBREAK |
| 6296 | case PV_NUW: return (char_u *)&(curwin->w_p_nuw); |
| 6297 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6298 | case PV_WFH: return (char_u *)&(curwin->w_p_wfh); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 6299 | case PV_WFW: return (char_u *)&(curwin->w_p_wfw); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 6300 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | case PV_PVW: return (char_u *)&(curwin->w_p_pvw); |
| 6302 | #endif |
| 6303 | #ifdef FEAT_RIGHTLEFT |
| 6304 | case PV_RL: return (char_u *)&(curwin->w_p_rl); |
| 6305 | case PV_RLC: return (char_u *)&(curwin->w_p_rlc); |
| 6306 | #endif |
| 6307 | case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 6308 | case PV_SMS: return (char_u *)&(curwin->w_p_sms); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6309 | case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); |
| 6310 | #ifdef FEAT_LINEBREAK |
| 6311 | case PV_LBR: return (char_u *)&(curwin->w_p_lbr); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6312 | case PV_BRI: return (char_u *)&(curwin->w_p_bri); |
| 6313 | case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6314 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6315 | case PV_WCR: return (char_u *)&(curwin->w_p_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6316 | case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6317 | case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6318 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6319 | case PV_COCU: return (char_u *)&(curwin->w_p_cocu); |
| 6320 | case PV_COLE: return (char_u *)&(curwin->w_p_cole); |
| 6321 | #endif |
| 6322 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6323 | case PV_TWK: return (char_u *)&(curwin->w_p_twk); |
| 6324 | case PV_TWS: return (char_u *)&(curwin->w_p_tws); |
| 6325 | case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6326 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6327 | |
| 6328 | case PV_AI: return (char_u *)&(curbuf->b_p_ai); |
| 6329 | case PV_BIN: return (char_u *)&(curbuf->b_p_bin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6330 | case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6331 | case PV_BH: return (char_u *)&(curbuf->b_p_bh); |
| 6332 | case PV_BT: return (char_u *)&(curbuf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6333 | case PV_BL: return (char_u *)&(curbuf->b_p_bl); |
| 6334 | case PV_CI: return (char_u *)&(curbuf->b_p_ci); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6335 | case PV_CIN: return (char_u *)&(curbuf->b_p_cin); |
| 6336 | case PV_CINK: return (char_u *)&(curbuf->b_p_cink); |
| 6337 | case PV_CINO: return (char_u *)&(curbuf->b_p_cino); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 6338 | case PV_CINSD: return (char_u *)&(curbuf->b_p_cinsd); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6339 | case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6340 | case PV_COM: return (char_u *)&(curbuf->b_p_com); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6341 | #ifdef FEAT_FOLDING |
| 6342 | case PV_CMS: return (char_u *)&(curbuf->b_p_cms); |
| 6343 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6344 | case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6345 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6346 | case PV_CSL: return (char_u *)&(curbuf->b_p_csl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6347 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6348 | #ifdef FEAT_COMPL_FUNC |
| 6349 | case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6350 | case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6351 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6352 | #ifdef FEAT_EVAL |
| 6353 | case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); |
| 6354 | #endif |
Bram Moolenaar | 3f68a41 | 2022-10-28 17:04:21 +0100 | [diff] [blame] | 6355 | case PV_EOF: return (char_u *)&(curbuf->b_p_eof); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6356 | case PV_EOL: return (char_u *)&(curbuf->b_p_eol); |
Bram Moolenaar | 34d72d4 | 2015-07-17 14:18:08 +0200 | [diff] [blame] | 6357 | case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6358 | case PV_ET: return (char_u *)&(curbuf->b_p_et); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6359 | case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6360 | case PV_FF: return (char_u *)&(curbuf->b_p_ff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6361 | case PV_FT: return (char_u *)&(curbuf->b_p_ft); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6362 | case PV_FO: return (char_u *)&(curbuf->b_p_fo); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 6363 | case PV_FLP: return (char_u *)&(curbuf->b_p_flp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6364 | case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); |
| 6365 | case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); |
| 6366 | case PV_INF: return (char_u *)&(curbuf->b_p_inf); |
| 6367 | case PV_ISK: return (char_u *)&(curbuf->b_p_isk); |
| 6368 | #ifdef FEAT_FIND_ID |
| 6369 | # ifdef FEAT_EVAL |
| 6370 | case PV_INEX: return (char_u *)&(curbuf->b_p_inex); |
| 6371 | # endif |
| 6372 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6373 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6374 | case PV_INDE: return (char_u *)&(curbuf->b_p_inde); |
| 6375 | case PV_INDK: return (char_u *)&(curbuf->b_p_indk); |
| 6376 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6377 | #ifdef FEAT_EVAL |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6378 | case PV_FEX: return (char_u *)&(curbuf->b_p_fex); |
| 6379 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6380 | #ifdef FEAT_CRYPT |
| 6381 | case PV_KEY: return (char_u *)&(curbuf->b_p_key); |
| 6382 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6383 | case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 6384 | case PV_LOP: return (char_u *)&(curbuf->b_p_lop); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6385 | case PV_ML: return (char_u *)&(curbuf->b_p_ml); |
| 6386 | case PV_MPS: return (char_u *)&(curbuf->b_p_mps); |
| 6387 | case PV_MA: return (char_u *)&(curbuf->b_p_ma); |
| 6388 | case PV_MOD: return (char_u *)&(curbuf->b_changed); |
| 6389 | case PV_NF: return (char_u *)&(curbuf->b_p_nf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6390 | case PV_PI: return (char_u *)&(curbuf->b_p_pi); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6391 | case PV_QE: return (char_u *)&(curbuf->b_p_qe); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6392 | case PV_RO: return (char_u *)&(curbuf->b_p_ro); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6393 | case PV_SI: return (char_u *)&(curbuf->b_p_si); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6394 | case PV_SN: return (char_u *)&(curbuf->b_p_sn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6395 | case PV_STS: return (char_u *)&(curbuf->b_p_sts); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6396 | case PV_SUA: return (char_u *)&(curbuf->b_p_sua); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6397 | case PV_SWF: return (char_u *)&(curbuf->b_p_swf); |
| 6398 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 6399 | case PV_SMC: return (char_u *)&(curbuf->b_p_smc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6400 | case PV_SYN: return (char_u *)&(curbuf->b_p_syn); |
| 6401 | #endif |
| 6402 | #ifdef FEAT_SPELL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6403 | case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); |
| 6404 | case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); |
| 6405 | case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 6406 | case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6407 | #endif |
| 6408 | case PV_SW: return (char_u *)&(curbuf->b_p_sw); |
| 6409 | case PV_TS: return (char_u *)&(curbuf->b_p_ts); |
| 6410 | case PV_TW: return (char_u *)&(curbuf->b_p_tw); |
| 6411 | case PV_TX: return (char_u *)&(curbuf->b_p_tx); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 6412 | #ifdef FEAT_PERSISTENT_UNDO |
| 6413 | case PV_UDF: return (char_u *)&(curbuf->b_p_udf); |
| 6414 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6415 | case PV_WM: return (char_u *)&(curbuf->b_p_wm); |
| 6416 | #ifdef FEAT_KEYMAP |
| 6417 | case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); |
| 6418 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6419 | #ifdef FEAT_SIGNS |
| 6420 | case PV_SCL: return (char_u *)&(curwin->w_p_scl); |
| 6421 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6422 | #ifdef FEAT_VARTABS |
| 6423 | case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); |
| 6424 | case PV_VTS: return (char_u *)&(curbuf->b_p_vts); |
| 6425 | #endif |
Bram Moolenaar | ac78dd4 | 2022-01-02 19:25:26 +0000 | [diff] [blame] | 6426 | default: iemsg(_(e_get_varp_error)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6427 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6428 | // always return a valid pointer to avoid a crash! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6429 | return (char_u *)&(curbuf->b_p_wm); |
| 6430 | } |
| 6431 | |
| 6432 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6433 | * Return a pointer to the variable for option at 'opt_idx' |
| 6434 | */ |
| 6435 | char_u * |
| 6436 | get_option_var(int opt_idx) |
| 6437 | { |
| 6438 | return options[opt_idx].var; |
| 6439 | } |
| 6440 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6441 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6442 | /* |
| 6443 | * Return the full name of the option at 'opt_idx' |
| 6444 | */ |
| 6445 | char_u * |
| 6446 | get_option_fullname(int opt_idx) |
| 6447 | { |
| 6448 | return (char_u *)options[opt_idx].fullname; |
| 6449 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6450 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6451 | |
| 6452 | /* |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 6453 | * Return the did_set callback function for the option at 'opt_idx' |
| 6454 | */ |
| 6455 | opt_did_set_cb_T |
| 6456 | get_option_did_set_cb(int opt_idx) |
| 6457 | { |
| 6458 | return options[opt_idx].opt_did_set_cb; |
| 6459 | } |
| 6460 | |
| 6461 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6462 | * Get the value of 'equalprg', either the buffer-local one or the global one. |
| 6463 | */ |
| 6464 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6465 | get_equalprg(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6466 | { |
| 6467 | if (*curbuf->b_p_ep == NUL) |
| 6468 | return p_ep; |
| 6469 | return curbuf->b_p_ep; |
| 6470 | } |
| 6471 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6472 | /* |
| 6473 | * Copy options from one window to another. |
| 6474 | * Used when splitting a window. |
| 6475 | */ |
| 6476 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6477 | win_copy_options(win_T *wp_from, win_T *wp_to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6478 | { |
| 6479 | copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); |
| 6480 | copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6481 | after_copy_winopt(wp_to); |
| 6482 | } |
| 6483 | |
| 6484 | /* |
| 6485 | * After copying window options: update variables depending on options. |
| 6486 | */ |
| 6487 | void |
Sean Dewar | 0f7ff85 | 2022-02-12 11:51:25 +0000 | [diff] [blame] | 6488 | after_copy_winopt(win_T *wp) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6489 | { |
| 6490 | #ifdef FEAT_LINEBREAK |
| 6491 | briopt_check(wp); |
Bram Moolenaar | 285ed7e | 2014-08-24 21:39:49 +0200 | [diff] [blame] | 6492 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6493 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6494 | fill_culopt_flags(NULL, wp); |
| 6495 | check_colorcolumn(wp); |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6496 | #endif |
Bram Moolenaar | b67f0c8 | 2022-07-04 21:03:36 +0100 | [diff] [blame] | 6497 | set_chars_option(wp, &wp->w_p_lcs, TRUE); |
| 6498 | set_chars_option(wp, &wp->w_p_fcs, TRUE); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | static char_u * |
| 6502 | copy_option_val(char_u *val) |
| 6503 | { |
| 6504 | if (val == empty_option) |
| 6505 | return empty_option; // no need to allocate memory |
| 6506 | return vim_strsave(val); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6507 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6508 | |
| 6509 | /* |
| 6510 | * Copy the options from one winopt_T to another. |
| 6511 | * Doesn't free the old option values in "to", use clear_winopt() for that. |
| 6512 | * The 'scroll' option is not copied, because it depends on the window height. |
| 6513 | * The 'previewwindow' option is reset, there can be only one preview window. |
| 6514 | */ |
| 6515 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6516 | copy_winopt(winopt_T *from, winopt_T *to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6517 | { |
| 6518 | #ifdef FEAT_ARABIC |
| 6519 | to->wo_arab = from->wo_arab; |
| 6520 | #endif |
| 6521 | to->wo_list = from->wo_list; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6522 | to->wo_lcs = copy_option_val(from->wo_lcs); |
| 6523 | to->wo_fcs = copy_option_val(from->wo_fcs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6524 | to->wo_nu = from->wo_nu; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6525 | to->wo_rnu = from->wo_rnu; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6526 | to->wo_ve = copy_option_val(from->wo_ve); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6527 | to->wo_ve_flags = from->wo_ve_flags; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6528 | #ifdef FEAT_LINEBREAK |
| 6529 | to->wo_nuw = from->wo_nuw; |
| 6530 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6531 | #ifdef FEAT_RIGHTLEFT |
| 6532 | to->wo_rl = from->wo_rl; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6533 | to->wo_rlc = copy_option_val(from->wo_rlc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6534 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6535 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6536 | to->wo_sbr = copy_option_val(from->wo_sbr); |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6537 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6538 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6539 | to->wo_stl = copy_option_val(from->wo_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6540 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6541 | to->wo_wrap = from->wo_wrap; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6542 | #ifdef FEAT_DIFF |
| 6543 | to->wo_wrap_save = from->wo_wrap_save; |
| 6544 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6545 | #ifdef FEAT_LINEBREAK |
| 6546 | to->wo_lbr = from->wo_lbr; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6547 | to->wo_bri = from->wo_bri; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6548 | to->wo_briopt = copy_option_val(from->wo_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6549 | #endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6550 | to->wo_wcr = copy_option_val(from->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6551 | to->wo_scb = from->wo_scb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6552 | to->wo_scb_save = from->wo_scb_save; |
Bram Moolenaar | b1fd26d | 2022-10-03 11:23:02 +0100 | [diff] [blame] | 6553 | to->wo_sms = from->wo_sms; |
Bram Moolenaar | 4161dcc | 2010-12-02 15:33:21 +0100 | [diff] [blame] | 6554 | to->wo_crb = from->wo_crb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6555 | to->wo_crb_save = from->wo_crb_save; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6556 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6557 | to->wo_spell = from->wo_spell; |
| 6558 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6559 | #ifdef FEAT_SYN_HL |
| 6560 | to->wo_cuc = from->wo_cuc; |
| 6561 | to->wo_cul = from->wo_cul; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6562 | to->wo_culopt = copy_option_val(from->wo_culopt); |
| 6563 | to->wo_cc = copy_option_val(from->wo_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6564 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6565 | #ifdef FEAT_DIFF |
| 6566 | to->wo_diff = from->wo_diff; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6567 | to->wo_diff_saved = from->wo_diff_saved; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6568 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6569 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6570 | to->wo_cocu = copy_option_val(from->wo_cocu); |
Bram Moolenaar | d497a30 | 2010-07-23 22:27:03 +0200 | [diff] [blame] | 6571 | to->wo_cole = from->wo_cole; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6572 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6573 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6574 | to->wo_twk = copy_option_val(from->wo_twk); |
| 6575 | to->wo_tws = copy_option_val(from->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6576 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6577 | #ifdef FEAT_FOLDING |
| 6578 | to->wo_fdc = from->wo_fdc; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6579 | to->wo_fdc_save = from->wo_fdc_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6580 | to->wo_fen = from->wo_fen; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6581 | to->wo_fen_save = from->wo_fen_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6582 | to->wo_fdi = copy_option_val(from->wo_fdi); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6583 | to->wo_fml = from->wo_fml; |
| 6584 | to->wo_fdl = from->wo_fdl; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6585 | to->wo_fdl_save = from->wo_fdl_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6586 | to->wo_fdm = copy_option_val(from->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6587 | to->wo_fdm_save = from->wo_diff_saved |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6588 | ? vim_strsave(from->wo_fdm_save) : empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6589 | to->wo_fdn = from->wo_fdn; |
| 6590 | # ifdef FEAT_EVAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6591 | to->wo_fde = copy_option_val(from->wo_fde); |
| 6592 | to->wo_fdt = copy_option_val(from->wo_fdt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6593 | # endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6594 | to->wo_fmr = copy_option_val(from->wo_fmr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6595 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6596 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6597 | to->wo_scl = copy_option_val(from->wo_scl); |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6598 | #endif |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6599 | |
| 6600 | #ifdef FEAT_EVAL |
| 6601 | // Copy the script context so that we know where the value was last set. |
| 6602 | mch_memmove(to->wo_script_ctx, from->wo_script_ctx, |
| 6603 | sizeof(to->wo_script_ctx)); |
| 6604 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6605 | check_winopt(to); // don't want NULL pointers |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6606 | } |
| 6607 | |
| 6608 | /* |
| 6609 | * Check string options in a window for a NULL value. |
| 6610 | */ |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 6611 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6612 | check_win_options(win_T *win) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6613 | { |
| 6614 | check_winopt(&win->w_onebuf_opt); |
| 6615 | check_winopt(&win->w_allbuf_opt); |
| 6616 | } |
| 6617 | |
| 6618 | /* |
| 6619 | * Check for NULL pointers in a winopt_T and replace them with empty_option. |
| 6620 | */ |
Bram Moolenaar | 8dc907d | 2014-06-25 14:44:10 +0200 | [diff] [blame] | 6621 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6622 | check_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6623 | { |
| 6624 | #ifdef FEAT_FOLDING |
| 6625 | check_string_option(&wop->wo_fdi); |
| 6626 | check_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6627 | check_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6628 | # ifdef FEAT_EVAL |
| 6629 | check_string_option(&wop->wo_fde); |
| 6630 | check_string_option(&wop->wo_fdt); |
| 6631 | # endif |
| 6632 | check_string_option(&wop->wo_fmr); |
| 6633 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6634 | #ifdef FEAT_SIGNS |
| 6635 | check_string_option(&wop->wo_scl); |
| 6636 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6637 | #ifdef FEAT_RIGHTLEFT |
| 6638 | check_string_option(&wop->wo_rlc); |
| 6639 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6640 | #ifdef FEAT_LINEBREAK |
| 6641 | check_string_option(&wop->wo_sbr); |
| 6642 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6643 | #ifdef FEAT_STL_OPT |
| 6644 | check_string_option(&wop->wo_stl); |
| 6645 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6646 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6647 | check_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6648 | check_string_option(&wop->wo_cc); |
| 6649 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6650 | #ifdef FEAT_CONCEAL |
| 6651 | check_string_option(&wop->wo_cocu); |
| 6652 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6653 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6654 | check_string_option(&wop->wo_twk); |
| 6655 | check_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6656 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6657 | #ifdef FEAT_LINEBREAK |
| 6658 | check_string_option(&wop->wo_briopt); |
| 6659 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6660 | check_string_option(&wop->wo_wcr); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6661 | check_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6662 | check_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6663 | check_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | /* |
| 6667 | * Free the allocated memory inside a winopt_T. |
| 6668 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6669 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6670 | clear_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6671 | { |
| 6672 | #ifdef FEAT_FOLDING |
| 6673 | clear_string_option(&wop->wo_fdi); |
| 6674 | clear_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6675 | clear_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6676 | # ifdef FEAT_EVAL |
| 6677 | clear_string_option(&wop->wo_fde); |
| 6678 | clear_string_option(&wop->wo_fdt); |
| 6679 | # endif |
| 6680 | clear_string_option(&wop->wo_fmr); |
| 6681 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6682 | #ifdef FEAT_SIGNS |
| 6683 | clear_string_option(&wop->wo_scl); |
| 6684 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6685 | #ifdef FEAT_LINEBREAK |
| 6686 | clear_string_option(&wop->wo_briopt); |
| 6687 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6688 | clear_string_option(&wop->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6689 | #ifdef FEAT_RIGHTLEFT |
| 6690 | clear_string_option(&wop->wo_rlc); |
| 6691 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6692 | #ifdef FEAT_LINEBREAK |
| 6693 | clear_string_option(&wop->wo_sbr); |
| 6694 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6695 | #ifdef FEAT_STL_OPT |
| 6696 | clear_string_option(&wop->wo_stl); |
| 6697 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6698 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6699 | clear_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6700 | clear_string_option(&wop->wo_cc); |
| 6701 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6702 | #ifdef FEAT_CONCEAL |
| 6703 | clear_string_option(&wop->wo_cocu); |
| 6704 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6705 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6706 | clear_string_option(&wop->wo_twk); |
| 6707 | clear_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6708 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6709 | clear_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6710 | clear_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6711 | clear_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6712 | } |
| 6713 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6714 | #ifdef FEAT_EVAL |
| 6715 | // Index into the options table for a buffer-local option enum. |
| 6716 | static int buf_opt_idx[BV_COUNT]; |
| 6717 | # define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].script_ctx |
| 6718 | |
| 6719 | /* |
| 6720 | * Initialize buf_opt_idx[] if not done already. |
| 6721 | */ |
| 6722 | static void |
| 6723 | init_buf_opt_idx(void) |
| 6724 | { |
| 6725 | static int did_init_buf_opt_idx = FALSE; |
| 6726 | int i; |
| 6727 | |
| 6728 | if (did_init_buf_opt_idx) |
| 6729 | return; |
| 6730 | did_init_buf_opt_idx = TRUE; |
| 6731 | for (i = 0; !istermoption_idx(i); i++) |
| 6732 | if (options[i].indir & PV_BUF) |
| 6733 | buf_opt_idx[options[i].indir & PV_MASK] = i; |
| 6734 | } |
| 6735 | #else |
| 6736 | # define COPY_OPT_SCTX(buf, bv) |
| 6737 | #endif |
| 6738 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6739 | /* |
| 6740 | * Copy global option values to local options for one buffer. |
| 6741 | * Used when creating a new buffer and sometimes when entering a buffer. |
| 6742 | * flags: |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6743 | * BCO_ENTER We will enter the buffer "buf". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6744 | * BCO_ALWAYS Always copy the options, but only set b_p_initialized when |
| 6745 | * appropriate. |
| 6746 | * BCO_NOHELP Don't copy the values to a help buffer. |
| 6747 | */ |
| 6748 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6749 | buf_copy_options(buf_T *buf, int flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6750 | { |
| 6751 | int should_copy = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6752 | char_u *save_p_isk = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6753 | int dont_do_help; |
| 6754 | int did_isk = FALSE; |
| 6755 | |
| 6756 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6757 | * Skip this when the option defaults have not been set yet. Happens when |
| 6758 | * main() allocates the first buffer. |
| 6759 | */ |
| 6760 | if (p_cpo != NULL) |
| 6761 | { |
| 6762 | /* |
| 6763 | * Always copy when entering and 'cpo' contains 'S'. |
| 6764 | * Don't copy when already initialized. |
| 6765 | * Don't copy when 'cpo' contains 's' and not entering. |
| 6766 | * 'S' BCO_ENTER initialized 's' should_copy |
| 6767 | * yes yes X X TRUE |
| 6768 | * yes no yes X FALSE |
| 6769 | * no X yes X FALSE |
| 6770 | * X no no yes FALSE |
| 6771 | * X no no no TRUE |
| 6772 | * no yes no X TRUE |
| 6773 | */ |
| 6774 | if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) |
| 6775 | && (buf->b_p_initialized |
| 6776 | || (!(flags & BCO_ENTER) |
| 6777 | && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) |
| 6778 | should_copy = FALSE; |
| 6779 | |
| 6780 | if (should_copy || (flags & BCO_ALWAYS)) |
| 6781 | { |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6782 | #ifdef FEAT_EVAL |
Bram Moolenaar | a80faa8 | 2020-04-12 19:37:17 +0200 | [diff] [blame] | 6783 | CLEAR_FIELD(buf->b_p_script_ctx); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6784 | init_buf_opt_idx(); |
| 6785 | #endif |
| 6786 | // Don't copy the options specific to a help buffer when |
| 6787 | // BCO_NOHELP is given or the options were initialized already |
| 6788 | // (jumping back to a help file with CTRL-T or CTRL-O) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6789 | dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) |
| 6790 | || buf->b_p_initialized; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6791 | if (dont_do_help) // don't free b_p_isk |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6792 | { |
| 6793 | save_p_isk = buf->b_p_isk; |
| 6794 | buf->b_p_isk = NULL; |
| 6795 | } |
| 6796 | /* |
Bram Moolenaar | 40385db | 2018-08-07 22:31:44 +0200 | [diff] [blame] | 6797 | * Always free the allocated strings. If not already initialized, |
| 6798 | * reset 'readonly' and copy 'fileformat'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6799 | */ |
| 6800 | if (!buf->b_p_initialized) |
| 6801 | { |
| 6802 | free_buf_options(buf, TRUE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6803 | buf->b_p_ro = FALSE; // don't copy readonly |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6804 | buf->b_p_tx = p_tx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6805 | buf->b_p_fenc = vim_strsave(p_fenc); |
Bram Moolenaar | e8ef3a0 | 2016-10-12 17:45:29 +0200 | [diff] [blame] | 6806 | switch (*p_ffs) |
| 6807 | { |
| 6808 | case 'm': |
| 6809 | buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break; |
| 6810 | case 'd': |
| 6811 | buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break; |
| 6812 | case 'u': |
| 6813 | buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break; |
| 6814 | default: |
| 6815 | buf->b_p_ff = vim_strsave(p_ff); |
| 6816 | } |
| 6817 | if (buf->b_p_ff != NULL) |
| 6818 | buf->b_start_ffc = *buf->b_p_ff; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6819 | buf->b_p_bh = empty_option; |
| 6820 | buf->b_p_bt = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6821 | } |
| 6822 | else |
| 6823 | free_buf_options(buf, FALSE); |
| 6824 | |
| 6825 | buf->b_p_ai = p_ai; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6826 | COPY_OPT_SCTX(buf, BV_AI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6827 | buf->b_p_ai_nopaste = p_ai_nopaste; |
| 6828 | buf->b_p_sw = p_sw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6829 | COPY_OPT_SCTX(buf, BV_SW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6830 | buf->b_p_tw = p_tw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6831 | COPY_OPT_SCTX(buf, BV_TW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6832 | buf->b_p_tw_nopaste = p_tw_nopaste; |
| 6833 | buf->b_p_tw_nobin = p_tw_nobin; |
| 6834 | buf->b_p_wm = p_wm; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6835 | COPY_OPT_SCTX(buf, BV_WM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6836 | buf->b_p_wm_nopaste = p_wm_nopaste; |
| 6837 | buf->b_p_wm_nobin = p_wm_nobin; |
| 6838 | buf->b_p_bin = p_bin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6839 | COPY_OPT_SCTX(buf, BV_BIN); |
Bram Moolenaar | e8bb255 | 2005-07-08 22:26:47 +0000 | [diff] [blame] | 6840 | buf->b_p_bomb = p_bomb; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6841 | COPY_OPT_SCTX(buf, BV_BOMB); |
Bram Moolenaar | b388be0 | 2015-07-22 22:19:38 +0200 | [diff] [blame] | 6842 | buf->b_p_fixeol = p_fixeol; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6843 | COPY_OPT_SCTX(buf, BV_FIXEOL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6844 | buf->b_p_et = p_et; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6845 | COPY_OPT_SCTX(buf, BV_ET); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6846 | buf->b_p_et_nobin = p_et_nobin; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6847 | buf->b_p_et_nopaste = p_et_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6848 | buf->b_p_ml = p_ml; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6849 | COPY_OPT_SCTX(buf, BV_ML); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6850 | buf->b_p_ml_nobin = p_ml_nobin; |
| 6851 | buf->b_p_inf = p_inf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6852 | COPY_OPT_SCTX(buf, BV_INF); |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 6853 | if (cmdmod.cmod_flags & CMOD_NOSWAPFILE) |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6854 | buf->b_p_swf = FALSE; |
| 6855 | else |
| 6856 | { |
| 6857 | buf->b_p_swf = p_swf; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 6858 | COPY_OPT_SCTX(buf, BV_SWF); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6859 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6860 | buf->b_p_cpt = vim_strsave(p_cpt); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6861 | COPY_OPT_SCTX(buf, BV_CPT); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6862 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6863 | buf->b_p_csl = vim_strsave(p_csl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6864 | COPY_OPT_SCTX(buf, BV_CSL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6865 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6866 | #ifdef FEAT_COMPL_FUNC |
| 6867 | buf->b_p_cfu = vim_strsave(p_cfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6868 | COPY_OPT_SCTX(buf, BV_CFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6869 | set_buflocal_cfu_callback(buf); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6870 | buf->b_p_ofu = vim_strsave(p_ofu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6871 | COPY_OPT_SCTX(buf, BV_OFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6872 | set_buflocal_ofu_callback(buf); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6873 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6874 | #ifdef FEAT_EVAL |
| 6875 | buf->b_p_tfu = vim_strsave(p_tfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6876 | COPY_OPT_SCTX(buf, BV_TFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6877 | set_buflocal_tfu_callback(buf); |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6878 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6879 | buf->b_p_sts = p_sts; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6880 | COPY_OPT_SCTX(buf, BV_STS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6881 | buf->b_p_sts_nopaste = p_sts_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6882 | #ifdef FEAT_VARTABS |
| 6883 | buf->b_p_vsts = vim_strsave(p_vsts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6884 | COPY_OPT_SCTX(buf, BV_VSTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6885 | if (p_vsts && p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 6886 | (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6887 | else |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 6888 | buf->b_p_vsts_array = NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6889 | buf->b_p_vsts_nopaste = p_vsts_nopaste |
| 6890 | ? vim_strsave(p_vsts_nopaste) : NULL; |
| 6891 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6892 | buf->b_p_sn = p_sn; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6893 | COPY_OPT_SCTX(buf, BV_SN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6894 | buf->b_p_com = vim_strsave(p_com); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6895 | COPY_OPT_SCTX(buf, BV_COM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6896 | #ifdef FEAT_FOLDING |
| 6897 | buf->b_p_cms = vim_strsave(p_cms); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6898 | COPY_OPT_SCTX(buf, BV_CMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6899 | #endif |
| 6900 | buf->b_p_fo = vim_strsave(p_fo); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6901 | COPY_OPT_SCTX(buf, BV_FO); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 6902 | buf->b_p_flp = vim_strsave(p_flp); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6903 | COPY_OPT_SCTX(buf, BV_FLP); |
Bram Moolenaar | 473952e | 2019-09-28 16:30:04 +0200 | [diff] [blame] | 6904 | // NOTE: Valgrind may report a bogus memory leak for 'nrformats' |
| 6905 | // when it is set to 8 bytes in defaults.vim. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6906 | buf->b_p_nf = vim_strsave(p_nf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6907 | COPY_OPT_SCTX(buf, BV_NF); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6908 | buf->b_p_mps = vim_strsave(p_mps); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6909 | COPY_OPT_SCTX(buf, BV_MPS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6910 | buf->b_p_si = p_si; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6911 | COPY_OPT_SCTX(buf, BV_SI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6912 | buf->b_p_ci = p_ci; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6913 | COPY_OPT_SCTX(buf, BV_CI); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6914 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6915 | buf->b_p_cin = p_cin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6916 | COPY_OPT_SCTX(buf, BV_CIN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6917 | buf->b_p_cink = vim_strsave(p_cink); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6918 | COPY_OPT_SCTX(buf, BV_CINK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6919 | buf->b_p_cino = vim_strsave(p_cino); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6920 | COPY_OPT_SCTX(buf, BV_CINO); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 6921 | buf->b_p_cinsd = vim_strsave(p_cinsd); |
| 6922 | COPY_OPT_SCTX(buf, BV_CINSD); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 6923 | buf->b_p_lop = vim_strsave(p_lop); |
| 6924 | COPY_OPT_SCTX(buf, BV_LOP); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6925 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6926 | // Don't copy 'filetype', it must be detected |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6927 | buf->b_p_ft = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6928 | buf->b_p_pi = p_pi; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6929 | COPY_OPT_SCTX(buf, BV_PI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6930 | buf->b_p_cinw = vim_strsave(p_cinw); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6931 | COPY_OPT_SCTX(buf, BV_CINW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6932 | buf->b_p_lisp = p_lisp; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6933 | COPY_OPT_SCTX(buf, BV_LISP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6934 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6935 | // Don't copy 'syntax', it must be set |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | buf->b_p_syn = empty_option; |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 6937 | buf->b_p_smc = p_smc; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6938 | COPY_OPT_SCTX(buf, BV_SMC); |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 6939 | buf->b_s.b_syn_isk = empty_option; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6940 | #endif |
| 6941 | #ifdef FEAT_SPELL |
Bram Moolenaar | d5784f9 | 2010-10-13 14:05:35 +0200 | [diff] [blame] | 6942 | buf->b_s.b_p_spc = vim_strsave(p_spc); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6943 | COPY_OPT_SCTX(buf, BV_SPC); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6944 | (void)compile_cap_prog(&buf->b_s); |
| 6945 | buf->b_s.b_p_spf = vim_strsave(p_spf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6946 | COPY_OPT_SCTX(buf, BV_SPF); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6947 | buf->b_s.b_p_spl = vim_strsave(p_spl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6948 | COPY_OPT_SCTX(buf, BV_SPL); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 6949 | buf->b_s.b_p_spo = vim_strsave(p_spo); |
| 6950 | COPY_OPT_SCTX(buf, BV_SPO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6951 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6952 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6953 | buf->b_p_inde = vim_strsave(p_inde); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6954 | COPY_OPT_SCTX(buf, BV_INDE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6955 | buf->b_p_indk = vim_strsave(p_indk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6956 | COPY_OPT_SCTX(buf, BV_INDK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6957 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6958 | buf->b_p_fp = empty_option; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6959 | #if defined(FEAT_EVAL) |
| 6960 | buf->b_p_fex = vim_strsave(p_fex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6961 | COPY_OPT_SCTX(buf, BV_FEX); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6962 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6963 | #ifdef FEAT_CRYPT |
| 6964 | buf->b_p_key = vim_strsave(p_key); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6965 | COPY_OPT_SCTX(buf, BV_KEY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6967 | buf->b_p_sua = vim_strsave(p_sua); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6968 | COPY_OPT_SCTX(buf, BV_SUA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6969 | #ifdef FEAT_KEYMAP |
| 6970 | buf->b_p_keymap = vim_strsave(p_keymap); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6971 | COPY_OPT_SCTX(buf, BV_KMAP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6972 | buf->b_kmap_state |= KEYMAP_INIT; |
| 6973 | #endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6974 | #ifdef FEAT_TERMINAL |
| 6975 | buf->b_p_twsl = p_twsl; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6976 | COPY_OPT_SCTX(buf, BV_TWSL); |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6977 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6978 | // This isn't really an option, but copying the langmap and IME |
| 6979 | // state from the current buffer is better than resetting it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6980 | buf->b_p_iminsert = p_iminsert; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6981 | COPY_OPT_SCTX(buf, BV_IMI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6982 | buf->b_p_imsearch = p_imsearch; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6983 | COPY_OPT_SCTX(buf, BV_IMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6984 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6985 | // options that are normally global but also have a local value |
| 6986 | // are not copied, start using the global value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6987 | buf->b_p_ar = -1; |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6988 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6989 | buf->b_p_bkc = empty_option; |
| 6990 | buf->b_bkc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6991 | #ifdef FEAT_QUICKFIX |
| 6992 | buf->b_p_gp = empty_option; |
| 6993 | buf->b_p_mp = empty_option; |
| 6994 | buf->b_p_efm = empty_option; |
| 6995 | #endif |
| 6996 | buf->b_p_ep = empty_option; |
| 6997 | buf->b_p_kp = empty_option; |
| 6998 | buf->b_p_path = empty_option; |
| 6999 | buf->b_p_tags = empty_option; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 7000 | buf->b_p_tc = empty_option; |
| 7001 | buf->b_tc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7002 | #ifdef FEAT_FIND_ID |
| 7003 | buf->b_p_def = empty_option; |
| 7004 | buf->b_p_inc = empty_option; |
| 7005 | # ifdef FEAT_EVAL |
| 7006 | buf->b_p_inex = vim_strsave(p_inex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7007 | COPY_OPT_SCTX(buf, BV_INEX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7008 | # endif |
| 7009 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7010 | buf->b_p_dict = empty_option; |
| 7011 | buf->b_p_tsr = empty_option; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 7012 | #ifdef FEAT_COMPL_FUNC |
| 7013 | buf->b_p_tsrfu = empty_option; |
| 7014 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 7015 | buf->b_p_qe = vim_strsave(p_qe); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7016 | COPY_OPT_SCTX(buf, BV_QE); |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 7017 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 7018 | buf->b_p_bexpr = empty_option; |
| 7019 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 7020 | #if defined(FEAT_CRYPT) |
| 7021 | buf->b_p_cm = empty_option; |
| 7022 | #endif |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7023 | #ifdef FEAT_PERSISTENT_UNDO |
| 7024 | buf->b_p_udf = p_udf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7025 | COPY_OPT_SCTX(buf, BV_UDF); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7026 | #endif |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 7027 | buf->b_p_lw = empty_option; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 7028 | buf->b_p_menc = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7029 | |
| 7030 | /* |
| 7031 | * Don't copy the options set by ex_help(), use the saved values, |
| 7032 | * when going from a help buffer to a non-help buffer. |
| 7033 | * Don't touch these at all when BCO_NOHELP is used and going from |
| 7034 | * or to a help buffer. |
| 7035 | */ |
| 7036 | if (dont_do_help) |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7037 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7038 | buf->b_p_isk = save_p_isk; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7039 | #ifdef FEAT_VARTABS |
| 7040 | if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7041 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7042 | else |
| 7043 | buf->b_p_vts_array = NULL; |
| 7044 | #endif |
| 7045 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7046 | else |
| 7047 | { |
| 7048 | buf->b_p_isk = vim_strsave(p_isk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7049 | COPY_OPT_SCTX(buf, BV_ISK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7050 | did_isk = TRUE; |
| 7051 | buf->b_p_ts = p_ts; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 7052 | COPY_OPT_SCTX(buf, BV_TS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7053 | #ifdef FEAT_VARTABS |
| 7054 | buf->b_p_vts = vim_strsave(p_vts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7055 | COPY_OPT_SCTX(buf, BV_VTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7056 | if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7057 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7058 | else |
| 7059 | buf->b_p_vts_array = NULL; |
| 7060 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7061 | buf->b_help = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7062 | if (buf->b_p_bt[0] == 'h') |
| 7063 | clear_string_option(&buf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7064 | buf->b_p_ma = p_ma; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7065 | COPY_OPT_SCTX(buf, BV_MA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7066 | } |
| 7067 | } |
| 7068 | |
| 7069 | /* |
| 7070 | * When the options should be copied (ignoring BCO_ALWAYS), set the |
| 7071 | * flag that indicates that the options have been initialized. |
| 7072 | */ |
| 7073 | if (should_copy) |
| 7074 | buf->b_p_initialized = TRUE; |
| 7075 | } |
| 7076 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7077 | check_buf_options(buf); // make sure we don't have NULLs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7078 | if (did_isk) |
| 7079 | (void)buf_init_chartab(buf, FALSE); |
| 7080 | } |
| 7081 | |
| 7082 | /* |
| 7083 | * Reset the 'modifiable' option and its default value. |
| 7084 | */ |
| 7085 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7086 | reset_modifiable(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7087 | { |
| 7088 | int opt_idx; |
| 7089 | |
| 7090 | curbuf->b_p_ma = FALSE; |
| 7091 | p_ma = FALSE; |
| 7092 | opt_idx = findoption((char_u *)"ma"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7093 | if (opt_idx >= 0) |
| 7094 | options[opt_idx].def_val[VI_DEFAULT] = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | /* |
| 7098 | * Set the global value for 'iminsert' to the local value. |
| 7099 | */ |
| 7100 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7101 | set_iminsert_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7102 | { |
| 7103 | p_iminsert = curbuf->b_p_iminsert; |
| 7104 | } |
| 7105 | |
| 7106 | /* |
| 7107 | * Set the global value for 'imsearch' to the local value. |
| 7108 | */ |
| 7109 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7110 | set_imsearch_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7111 | { |
| 7112 | p_imsearch = curbuf->b_p_imsearch; |
| 7113 | } |
| 7114 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7115 | static int expand_option_idx = -1; |
| 7116 | static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; |
| 7117 | static int expand_option_flags = 0; |
| 7118 | |
| 7119 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7120 | set_context_in_set_cmd( |
| 7121 | expand_T *xp, |
| 7122 | char_u *arg, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7123 | int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7124 | { |
| 7125 | int nextchar; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7126 | long_u flags = 0; // init for GCC |
| 7127 | int opt_idx = 0; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7128 | char_u *p; |
| 7129 | char_u *s; |
| 7130 | int is_term_option = FALSE; |
| 7131 | int key; |
| 7132 | |
| 7133 | expand_option_flags = opt_flags; |
| 7134 | |
| 7135 | xp->xp_context = EXPAND_SETTINGS; |
| 7136 | if (*arg == NUL) |
| 7137 | { |
| 7138 | xp->xp_pattern = arg; |
| 7139 | return; |
| 7140 | } |
| 7141 | p = arg + STRLEN(arg) - 1; |
| 7142 | if (*p == ' ' && *(p - 1) != '\\') |
| 7143 | { |
| 7144 | xp->xp_pattern = p + 1; |
| 7145 | return; |
| 7146 | } |
| 7147 | while (p > arg) |
| 7148 | { |
| 7149 | s = p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7150 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7151 | if (*p == ' ' || *p == ',') |
| 7152 | { |
| 7153 | while (s > arg && *(s - 1) == '\\') |
| 7154 | --s; |
| 7155 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7156 | // break at a space with an even number of backslashes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7157 | if (*p == ' ' && ((p - s) & 1) == 0) |
| 7158 | { |
| 7159 | ++p; |
| 7160 | break; |
| 7161 | } |
| 7162 | --p; |
| 7163 | } |
Bram Moolenaar | 2a7b9ee | 2009-06-16 15:50:33 +0000 | [diff] [blame] | 7164 | if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7165 | { |
| 7166 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
| 7167 | p += 2; |
| 7168 | } |
| 7169 | if (STRNCMP(p, "inv", 3) == 0) |
| 7170 | { |
| 7171 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
| 7172 | p += 3; |
| 7173 | } |
| 7174 | xp->xp_pattern = arg = p; |
| 7175 | if (*arg == '<') |
| 7176 | { |
| 7177 | while (*p != '>') |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7178 | if (*p++ == NUL) // expand terminal option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7179 | return; |
| 7180 | key = get_special_key_code(arg + 1); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7181 | if (key == 0) // unknown name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7182 | { |
| 7183 | xp->xp_context = EXPAND_NOTHING; |
| 7184 | return; |
| 7185 | } |
| 7186 | nextchar = *++p; |
| 7187 | is_term_option = TRUE; |
| 7188 | expand_option_name[2] = KEY2TERMCAP0(key); |
| 7189 | expand_option_name[3] = KEY2TERMCAP1(key); |
| 7190 | } |
| 7191 | else |
| 7192 | { |
| 7193 | if (p[0] == 't' && p[1] == '_') |
| 7194 | { |
| 7195 | p += 2; |
| 7196 | if (*p != NUL) |
| 7197 | ++p; |
| 7198 | if (*p == NUL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7199 | return; // expand option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7200 | nextchar = *++p; |
| 7201 | is_term_option = TRUE; |
| 7202 | expand_option_name[2] = p[-2]; |
| 7203 | expand_option_name[3] = p[-1]; |
| 7204 | } |
| 7205 | else |
| 7206 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7207 | // Allow * wildcard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7208 | while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') |
| 7209 | p++; |
| 7210 | if (*p == NUL) |
| 7211 | return; |
| 7212 | nextchar = *p; |
| 7213 | *p = NUL; |
| 7214 | opt_idx = findoption(arg); |
| 7215 | *p = nextchar; |
| 7216 | if (opt_idx == -1 || options[opt_idx].var == NULL) |
| 7217 | { |
| 7218 | xp->xp_context = EXPAND_NOTHING; |
| 7219 | return; |
| 7220 | } |
| 7221 | flags = options[opt_idx].flags; |
| 7222 | if (flags & P_BOOL) |
| 7223 | { |
| 7224 | xp->xp_context = EXPAND_NOTHING; |
| 7225 | return; |
| 7226 | } |
| 7227 | } |
| 7228 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7229 | // handle "-=" and "+=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7230 | if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') |
| 7231 | { |
| 7232 | ++p; |
| 7233 | nextchar = '='; |
| 7234 | } |
| 7235 | if ((nextchar != '=' && nextchar != ':') |
| 7236 | || xp->xp_context == EXPAND_BOOL_SETTINGS) |
| 7237 | { |
| 7238 | xp->xp_context = EXPAND_UNSUCCESSFUL; |
| 7239 | return; |
| 7240 | } |
| 7241 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL) |
| 7242 | { |
| 7243 | xp->xp_context = EXPAND_OLD_SETTING; |
| 7244 | if (is_term_option) |
| 7245 | expand_option_idx = -1; |
| 7246 | else |
| 7247 | expand_option_idx = opt_idx; |
| 7248 | xp->xp_pattern = p + 1; |
| 7249 | return; |
| 7250 | } |
| 7251 | xp->xp_context = EXPAND_NOTHING; |
| 7252 | if (is_term_option || (flags & P_NUM)) |
| 7253 | return; |
| 7254 | |
| 7255 | xp->xp_pattern = p + 1; |
| 7256 | |
| 7257 | if (flags & P_EXPAND) |
| 7258 | { |
| 7259 | p = options[opt_idx].var; |
| 7260 | if (p == (char_u *)&p_bdir |
| 7261 | || p == (char_u *)&p_dir |
| 7262 | || p == (char_u *)&p_path |
Bram Moolenaar | f6fee0e | 2016-02-21 23:02:49 +0100 | [diff] [blame] | 7263 | || p == (char_u *)&p_pp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7264 | || p == (char_u *)&p_rtp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7265 | || p == (char_u *)&p_cdpath |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7266 | #ifdef FEAT_SESSION |
| 7267 | || p == (char_u *)&p_vdir |
| 7268 | #endif |
| 7269 | ) |
| 7270 | { |
| 7271 | xp->xp_context = EXPAND_DIRECTORIES; |
Bram Moolenaar | f80f40a | 2022-08-25 16:02:23 +0100 | [diff] [blame] | 7272 | if (p == (char_u *)&p_path || p == (char_u *)&p_cdpath) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7273 | xp->xp_backslash = XP_BS_THREE; |
| 7274 | else |
| 7275 | xp->xp_backslash = XP_BS_ONE; |
| 7276 | } |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 7277 | else if (p == (char_u *)&p_ft) |
| 7278 | { |
| 7279 | xp->xp_context = EXPAND_FILETYPE; |
| 7280 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7281 | else |
| 7282 | { |
| 7283 | xp->xp_context = EXPAND_FILES; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7284 | // for 'tags' need three backslashes for a space |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7285 | if (p == (char_u *)&p_tags) |
| 7286 | xp->xp_backslash = XP_BS_THREE; |
| 7287 | else |
| 7288 | xp->xp_backslash = XP_BS_ONE; |
| 7289 | } |
| 7290 | } |
| 7291 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7292 | // For an option that is a list of file names, find the start of the |
| 7293 | // last file name. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7294 | for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) |
| 7295 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7296 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7297 | if (*p == ' ' || *p == ',') |
| 7298 | { |
| 7299 | s = p; |
| 7300 | while (s > xp->xp_pattern && *(s - 1) == '\\') |
| 7301 | --s; |
| 7302 | if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) |
| 7303 | || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) |
| 7304 | { |
| 7305 | xp->xp_pattern = p + 1; |
| 7306 | break; |
| 7307 | } |
| 7308 | } |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 7309 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 7310 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7311 | // for 'spellsuggest' start at "file:" |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 7312 | if (options[opt_idx].var == (char_u *)&p_sps |
| 7313 | && STRNCMP(p, "file:", 5) == 0) |
| 7314 | { |
| 7315 | xp->xp_pattern = p + 5; |
| 7316 | break; |
| 7317 | } |
| 7318 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7319 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7320 | } |
| 7321 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7322 | /* |
| 7323 | * Returns TRUE if 'str' either matches 'regmatch' or fuzzy matches 'pat'. |
| 7324 | * |
| 7325 | * If 'test_only' is TRUE and 'fuzzy' is FALSE and if 'str' matches the regular |
| 7326 | * expression 'regmatch', then returns TRUE. Otherwise returns FALSE. |
| 7327 | * |
| 7328 | * If 'test_only' is FALSE and 'fuzzy' is FALSE and if 'str' matches the |
| 7329 | * regular expression 'regmatch', then stores the match in matches[idx] and |
| 7330 | * returns TRUE. |
| 7331 | * |
| 7332 | * If 'test_only' is TRUE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7333 | * 'fuzzystr', then returns TRUE. Otherwise returns FALSE. |
| 7334 | * |
| 7335 | * If 'test_only' is FALSE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7336 | * 'fuzzystr', then stores the match details in fuzmatch[idx] and returns TRUE. |
| 7337 | */ |
| 7338 | static int |
| 7339 | match_str( |
| 7340 | char_u *str, |
| 7341 | regmatch_T *regmatch, |
| 7342 | char_u **matches, |
| 7343 | int idx, |
| 7344 | int test_only, |
| 7345 | int fuzzy, |
| 7346 | char_u *fuzzystr, |
| 7347 | fuzmatch_str_T *fuzmatch) |
| 7348 | { |
| 7349 | if (!fuzzy) |
| 7350 | { |
| 7351 | if (vim_regexec(regmatch, str, (colnr_T)0)) |
| 7352 | { |
| 7353 | if (!test_only) |
| 7354 | matches[idx] = vim_strsave(str); |
| 7355 | return TRUE; |
| 7356 | } |
| 7357 | } |
| 7358 | else |
| 7359 | { |
| 7360 | int score; |
| 7361 | |
| 7362 | score = fuzzy_match_str(str, fuzzystr); |
| 7363 | if (score != 0) |
| 7364 | { |
| 7365 | if (!test_only) |
| 7366 | { |
| 7367 | fuzmatch[idx].idx = idx; |
| 7368 | fuzmatch[idx].str = vim_strsave(str); |
| 7369 | fuzmatch[idx].score = score; |
| 7370 | } |
| 7371 | |
| 7372 | return TRUE; |
| 7373 | } |
| 7374 | } |
| 7375 | |
| 7376 | return FALSE; |
| 7377 | } |
| 7378 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7379 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7380 | ExpandSettings( |
| 7381 | expand_T *xp, |
| 7382 | regmatch_T *regmatch, |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7383 | char_u *fuzzystr, |
| 7384 | int *numMatches, |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7385 | char_u ***matches, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7386 | int can_fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7387 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7388 | int num_normal = 0; // Nr of matching non-term-code settings |
| 7389 | int num_term = 0; // Nr of matching terminal code settings |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7390 | int opt_idx; |
| 7391 | int match; |
| 7392 | int count = 0; |
| 7393 | char_u *str; |
| 7394 | int loop; |
| 7395 | int is_term_opt; |
| 7396 | char_u name_buf[MAX_KEY_NAME_LEN]; |
| 7397 | static char *(names[]) = {"all", "termcap"}; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7398 | int ic = regmatch->rm_ic; // remember the ignore-case flag |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7399 | int fuzzy; |
| 7400 | fuzmatch_str_T *fuzmatch = NULL; |
| 7401 | |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7402 | fuzzy = can_fuzzy && cmdline_fuzzy_complete(fuzzystr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7403 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7404 | // do this loop twice: |
| 7405 | // loop == 0: count the number of matching options |
| 7406 | // loop == 1: copy the matching options into allocated memory |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7407 | for (loop = 0; loop <= 1; ++loop) |
| 7408 | { |
| 7409 | regmatch->rm_ic = ic; |
| 7410 | if (xp->xp_context != EXPAND_BOOL_SETTINGS) |
| 7411 | { |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 7412 | for (match = 0; match < (int)ARRAY_LENGTH(names); ++match) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7413 | { |
| 7414 | if (match_str((char_u *)names[match], regmatch, *matches, |
| 7415 | count, (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7416 | { |
| 7417 | if (loop == 0) |
| 7418 | num_normal++; |
| 7419 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7420 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7421 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7422 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7423 | } |
| 7424 | for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; |
| 7425 | opt_idx++) |
| 7426 | { |
| 7427 | if (options[opt_idx].var == NULL) |
| 7428 | continue; |
| 7429 | if (xp->xp_context == EXPAND_BOOL_SETTINGS |
| 7430 | && !(options[opt_idx].flags & P_BOOL)) |
| 7431 | continue; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7432 | is_term_opt = istermoption_idx(opt_idx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7433 | if (is_term_opt && num_normal > 0) |
| 7434 | continue; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7435 | |
| 7436 | if (match_str(str, regmatch, *matches, count, (loop == 0), |
| 7437 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7438 | { |
| 7439 | if (loop == 0) |
| 7440 | { |
| 7441 | if (is_term_opt) |
| 7442 | num_term++; |
| 7443 | else |
| 7444 | num_normal++; |
| 7445 | } |
| 7446 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7447 | count++; |
| 7448 | } |
| 7449 | else if (!fuzzy && options[opt_idx].shortname != NULL |
| 7450 | && vim_regexec(regmatch, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7451 | (char_u *)options[opt_idx].shortname, (colnr_T)0)) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7452 | { |
| 7453 | // Compare against the abbreviated option name (for regular |
| 7454 | // expression match). Fuzzy matching (previous if) already |
| 7455 | // matches against both the expanded and abbreviated names. |
| 7456 | if (loop == 0) |
| 7457 | { |
| 7458 | if (is_term_opt) |
| 7459 | num_term++; |
| 7460 | else |
| 7461 | num_normal++; |
| 7462 | } |
| 7463 | else |
| 7464 | (*matches)[count++] = vim_strsave(str); |
| 7465 | } |
| 7466 | else if (is_term_opt) |
| 7467 | { |
| 7468 | name_buf[0] = '<'; |
| 7469 | name_buf[1] = 't'; |
| 7470 | name_buf[2] = '_'; |
| 7471 | name_buf[3] = str[2]; |
| 7472 | name_buf[4] = str[3]; |
| 7473 | name_buf[5] = '>'; |
| 7474 | name_buf[6] = NUL; |
| 7475 | |
| 7476 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7477 | fuzzy, fuzzystr, fuzmatch)) |
| 7478 | { |
| 7479 | if (loop == 0) |
| 7480 | num_term++; |
| 7481 | else |
| 7482 | count++; |
| 7483 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7484 | } |
| 7485 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7486 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7487 | /* |
| 7488 | * Check terminal key codes, these are not in the option table |
| 7489 | */ |
| 7490 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) |
| 7491 | { |
| 7492 | for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) |
| 7493 | { |
| 7494 | if (!isprint(str[0]) || !isprint(str[1])) |
| 7495 | continue; |
| 7496 | |
| 7497 | name_buf[0] = 't'; |
| 7498 | name_buf[1] = '_'; |
| 7499 | name_buf[2] = str[0]; |
| 7500 | name_buf[3] = str[1]; |
| 7501 | name_buf[4] = NUL; |
| 7502 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7503 | if (match_str(name_buf, regmatch, *matches, count, |
| 7504 | (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
| 7505 | { |
| 7506 | if (loop == 0) |
| 7507 | num_term++; |
| 7508 | else |
| 7509 | count++; |
| 7510 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7511 | else |
| 7512 | { |
| 7513 | name_buf[0] = '<'; |
| 7514 | name_buf[1] = 't'; |
| 7515 | name_buf[2] = '_'; |
| 7516 | name_buf[3] = str[0]; |
| 7517 | name_buf[4] = str[1]; |
| 7518 | name_buf[5] = '>'; |
| 7519 | name_buf[6] = NUL; |
| 7520 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7521 | if (match_str(name_buf, regmatch, *matches, count, |
| 7522 | (loop == 0), fuzzy, fuzzystr, |
| 7523 | fuzmatch)) |
| 7524 | { |
| 7525 | if (loop == 0) |
| 7526 | num_term++; |
| 7527 | else |
| 7528 | count++; |
| 7529 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7530 | } |
| 7531 | } |
| 7532 | |
| 7533 | /* |
| 7534 | * Check special key names. |
| 7535 | */ |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7536 | regmatch->rm_ic = TRUE; // ignore case here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7537 | for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) |
| 7538 | { |
| 7539 | name_buf[0] = '<'; |
| 7540 | STRCPY(name_buf + 1, str); |
| 7541 | STRCAT(name_buf, ">"); |
| 7542 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7543 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7544 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7545 | { |
| 7546 | if (loop == 0) |
| 7547 | num_term++; |
| 7548 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7549 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7550 | } |
| 7551 | } |
| 7552 | } |
| 7553 | if (loop == 0) |
| 7554 | { |
| 7555 | if (num_normal > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7556 | *numMatches = num_normal; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7557 | else if (num_term > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7558 | *numMatches = num_term; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7559 | else |
| 7560 | return OK; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7561 | if (!fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7562 | { |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7563 | *matches = ALLOC_MULT(char_u *, *numMatches); |
| 7564 | if (*matches == NULL) |
| 7565 | { |
| 7566 | *matches = (char_u **)""; |
| 7567 | return FAIL; |
| 7568 | } |
| 7569 | } |
| 7570 | else |
| 7571 | { |
| 7572 | fuzmatch = ALLOC_MULT(fuzmatch_str_T, *numMatches); |
| 7573 | if (fuzmatch == NULL) |
| 7574 | { |
| 7575 | *matches = (char_u **)""; |
| 7576 | return FAIL; |
| 7577 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7578 | } |
| 7579 | } |
| 7580 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7581 | |
| 7582 | if (fuzzy && |
| 7583 | fuzzymatches_to_strmatches(fuzmatch, matches, count, FALSE) == FAIL) |
| 7584 | return FAIL; |
| 7585 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7586 | return OK; |
| 7587 | } |
| 7588 | |
| 7589 | int |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7590 | ExpandOldSetting(int *numMatches, char_u ***matches) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7591 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7592 | char_u *var = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7593 | char_u *buf; |
| 7594 | |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7595 | *numMatches = 0; |
| 7596 | *matches = ALLOC_ONE(char_u *); |
| 7597 | if (*matches == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7598 | return FAIL; |
| 7599 | |
| 7600 | /* |
| 7601 | * For a terminal key code expand_option_idx is < 0. |
| 7602 | */ |
| 7603 | if (expand_option_idx < 0) |
| 7604 | { |
| 7605 | var = find_termcode(expand_option_name + 2); |
| 7606 | if (var == NULL) |
| 7607 | expand_option_idx = findoption(expand_option_name); |
| 7608 | } |
| 7609 | |
| 7610 | if (expand_option_idx >= 0) |
| 7611 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7612 | // put string of option value in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7613 | option_value2string(&options[expand_option_idx], expand_option_flags); |
| 7614 | var = NameBuff; |
| 7615 | } |
| 7616 | else if (var == NULL) |
| 7617 | var = (char_u *)""; |
| 7618 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7619 | // A backslash is required before some characters. This is the reverse of |
| 7620 | // what happens in do_set(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7621 | buf = vim_strsave_escaped(var, escape_chars); |
| 7622 | |
| 7623 | if (buf == NULL) |
| 7624 | { |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7625 | VIM_CLEAR(*matches); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7626 | return FAIL; |
| 7627 | } |
| 7628 | |
| 7629 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7630 | // For MS-Windows et al. we don't double backslashes at the start and |
| 7631 | // before a file name character. |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 7632 | for (var = buf; *var != NUL; MB_PTR_ADV(var)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7633 | if (var[0] == '\\' && var[1] == '\\' |
| 7634 | && expand_option_idx >= 0 |
| 7635 | && (options[expand_option_idx].flags & P_EXPAND) |
| 7636 | && vim_isfilec(var[2]) |
| 7637 | && (var[2] != '\\' || (var == buf && var[4] != '\\'))) |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 7638 | STRMOVE(var, var + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7639 | #endif |
| 7640 | |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7641 | *matches[0] = buf; |
| 7642 | *numMatches = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7643 | return OK; |
| 7644 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7645 | |
| 7646 | /* |
| 7647 | * Get the value for the numeric or string option *opp in a nice format into |
| 7648 | * NameBuff[]. Must not be called with a hidden option! |
| 7649 | */ |
| 7650 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7651 | option_value2string( |
| 7652 | struct vimoption *opp, |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 7653 | int scope) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7654 | { |
| 7655 | char_u *varp; |
| 7656 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 7657 | varp = get_varp_scope(opp, scope); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7658 | |
| 7659 | if (opp->flags & P_NUM) |
| 7660 | { |
| 7661 | long wc = 0; |
| 7662 | |
| 7663 | if (wc_use_keyname(varp, &wc)) |
| 7664 | STRCPY(NameBuff, get_special_key_name((int)wc, 0)); |
| 7665 | else if (wc != 0) |
| 7666 | STRCPY(NameBuff, transchar((int)wc)); |
| 7667 | else |
| 7668 | sprintf((char *)NameBuff, "%ld", *(long *)varp); |
| 7669 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7670 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7671 | { |
| 7672 | varp = *(char_u **)(varp); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7673 | if (varp == NULL) // just in case |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7674 | NameBuff[0] = NUL; |
| 7675 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7676 | // 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] | 7677 | else if (opp->var == (char_u *)&p_key && *varp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7678 | STRCPY(NameBuff, "*****"); |
| 7679 | #endif |
| 7680 | else if (opp->flags & P_EXPAND) |
| 7681 | home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7682 | // Translate 'pastetoggle' into special key names |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7683 | else if ((char_u **)opp->var == &p_pt) |
| 7684 | str2specialbuf(p_pt, NameBuff, MAXPATHL); |
| 7685 | else |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 7686 | vim_strncpy(NameBuff, varp, MAXPATHL - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7687 | } |
| 7688 | } |
| 7689 | |
| 7690 | /* |
| 7691 | * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be |
| 7692 | * printed as a keyname. |
| 7693 | * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. |
| 7694 | */ |
| 7695 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7696 | wc_use_keyname(char_u *varp, long *wcp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7697 | { |
| 7698 | if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) |
| 7699 | { |
| 7700 | *wcp = *(long *)varp; |
| 7701 | if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) |
| 7702 | return TRUE; |
| 7703 | } |
| 7704 | return FALSE; |
| 7705 | } |
| 7706 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7707 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7708 | * Return TRUE if "x" is present in 'shortmess' option, or |
| 7709 | * 'shortmess' contains 'a' and "x" is present in SHM_A. |
| 7710 | */ |
| 7711 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7712 | shortmess(int x) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7713 | { |
Bram Moolenaar | 7f29f7a | 2012-02-29 13:51:37 +0100 | [diff] [blame] | 7714 | return p_shm != NULL && |
| 7715 | ( vim_strchr(p_shm, x) != NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7716 | || (vim_strchr(p_shm, 'a') != NULL |
| 7717 | && vim_strchr((char_u *)SHM_A, x) != NULL)); |
| 7718 | } |
| 7719 | |
| 7720 | /* |
| 7721 | * paste_option_changed() - Called after p_paste was set or reset. |
| 7722 | */ |
| 7723 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7724 | paste_option_changed(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7725 | { |
| 7726 | static int old_p_paste = FALSE; |
| 7727 | static int save_sm = 0; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7728 | static int save_sta = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7729 | static int save_ru = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7730 | #ifdef FEAT_RIGHTLEFT |
| 7731 | static int save_ri = 0; |
| 7732 | static int save_hkmap = 0; |
| 7733 | #endif |
| 7734 | buf_T *buf; |
| 7735 | |
| 7736 | if (p_paste) |
| 7737 | { |
| 7738 | /* |
| 7739 | * Paste switched from off to on. |
| 7740 | * Save the current values, so they can be restored later. |
| 7741 | */ |
| 7742 | if (!old_p_paste) |
| 7743 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7744 | // save options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 7745 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7746 | { |
| 7747 | buf->b_p_tw_nopaste = buf->b_p_tw; |
| 7748 | buf->b_p_wm_nopaste = buf->b_p_wm; |
| 7749 | buf->b_p_sts_nopaste = buf->b_p_sts; |
| 7750 | buf->b_p_ai_nopaste = buf->b_p_ai; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7751 | buf->b_p_et_nopaste = buf->b_p_et; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7752 | #ifdef FEAT_VARTABS |
| 7753 | if (buf->b_p_vsts_nopaste) |
| 7754 | vim_free(buf->b_p_vsts_nopaste); |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 7755 | buf->b_p_vsts_nopaste = |
| 7756 | buf->b_p_vsts && buf->b_p_vsts != empty_option |
| 7757 | ? vim_strsave(buf->b_p_vsts) : NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7758 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7759 | } |
| 7760 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7761 | // save global options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7762 | save_sm = p_sm; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7763 | save_sta = p_sta; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7764 | save_ru = p_ru; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7765 | #ifdef FEAT_RIGHTLEFT |
| 7766 | save_ri = p_ri; |
| 7767 | save_hkmap = p_hkmap; |
| 7768 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7769 | // save global values for local buffer options |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7770 | p_ai_nopaste = p_ai; |
| 7771 | p_et_nopaste = p_et; |
| 7772 | p_sts_nopaste = p_sts; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7773 | p_tw_nopaste = p_tw; |
| 7774 | p_wm_nopaste = p_wm; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7775 | #ifdef FEAT_VARTABS |
| 7776 | if (p_vsts_nopaste) |
| 7777 | vim_free(p_vsts_nopaste); |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 7778 | p_vsts_nopaste = p_vsts && p_vsts != empty_option |
| 7779 | ? vim_strsave(p_vsts) : NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7780 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7781 | } |
| 7782 | |
| 7783 | /* |
| 7784 | * Always set the option values, also when 'paste' is set when it is |
| 7785 | * already on. |
| 7786 | */ |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7787 | // set options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 7788 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7789 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7790 | buf->b_p_tw = 0; // textwidth is 0 |
| 7791 | buf->b_p_wm = 0; // wrapmargin is 0 |
| 7792 | buf->b_p_sts = 0; // softtabstop is 0 |
| 7793 | buf->b_p_ai = 0; // no auto-indent |
| 7794 | buf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7795 | #ifdef FEAT_VARTABS |
| 7796 | if (buf->b_p_vsts) |
| 7797 | free_string_option(buf->b_p_vsts); |
| 7798 | buf->b_p_vsts = empty_option; |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 7799 | VIM_CLEAR(buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7800 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7801 | } |
| 7802 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7803 | // set global options |
| 7804 | p_sm = 0; // no showmatch |
| 7805 | p_sta = 0; // no smarttab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7806 | if (p_ru) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7807 | status_redraw_all(); // redraw to remove the ruler |
| 7808 | p_ru = 0; // no ruler |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7809 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7810 | p_ri = 0; // no reverse insert |
| 7811 | p_hkmap = 0; // no Hebrew keyboard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7812 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7813 | // set global values for local buffer options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7814 | p_tw = 0; |
| 7815 | p_wm = 0; |
| 7816 | p_sts = 0; |
| 7817 | p_ai = 0; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7818 | #ifdef FEAT_VARTABS |
| 7819 | if (p_vsts) |
| 7820 | free_string_option(p_vsts); |
| 7821 | p_vsts = empty_option; |
| 7822 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | /* |
| 7826 | * Paste switched from on to off: Restore saved values. |
| 7827 | */ |
| 7828 | else if (old_p_paste) |
| 7829 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7830 | // restore options for each buffer |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 7831 | FOR_ALL_BUFFERS(buf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7832 | { |
| 7833 | buf->b_p_tw = buf->b_p_tw_nopaste; |
| 7834 | buf->b_p_wm = buf->b_p_wm_nopaste; |
| 7835 | buf->b_p_sts = buf->b_p_sts_nopaste; |
| 7836 | buf->b_p_ai = buf->b_p_ai_nopaste; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7837 | buf->b_p_et = buf->b_p_et_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7838 | #ifdef FEAT_VARTABS |
| 7839 | if (buf->b_p_vsts) |
| 7840 | free_string_option(buf->b_p_vsts); |
| 7841 | buf->b_p_vsts = buf->b_p_vsts_nopaste |
| 7842 | ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option; |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 7843 | vim_free(buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7844 | if (buf->b_p_vsts && buf->b_p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7845 | (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7846 | else |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 7847 | buf->b_p_vsts_array = NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7848 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7849 | } |
| 7850 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7851 | // restore global options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7852 | p_sm = save_sm; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7853 | p_sta = save_sta; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7854 | if (p_ru != save_ru) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7855 | status_redraw_all(); // redraw to draw the ruler |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7856 | p_ru = save_ru; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7857 | #ifdef FEAT_RIGHTLEFT |
| 7858 | p_ri = save_ri; |
| 7859 | p_hkmap = save_hkmap; |
| 7860 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7861 | // set global values for local buffer options |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 7862 | p_ai = p_ai_nopaste; |
| 7863 | p_et = p_et_nopaste; |
| 7864 | p_sts = p_sts_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7865 | p_tw = p_tw_nopaste; |
| 7866 | p_wm = p_wm_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7867 | #ifdef FEAT_VARTABS |
| 7868 | if (p_vsts) |
| 7869 | free_string_option(p_vsts); |
| 7870 | p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; |
| 7871 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7872 | } |
| 7873 | |
| 7874 | old_p_paste = p_paste; |
| 7875 | } |
| 7876 | |
| 7877 | /* |
| 7878 | * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. |
| 7879 | * |
| 7880 | * Reset 'compatible' and set the values for options that didn't get set yet |
| 7881 | * to the Vim defaults. |
| 7882 | * 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] | 7883 | * 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] | 7884 | */ |
| 7885 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7886 | vimrc_found(char_u *fname, char_u *envname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7887 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7888 | int opt_idx; |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 7889 | int dofree = FALSE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7890 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7891 | |
| 7892 | if (!option_was_set((char_u *)"cp")) |
| 7893 | { |
| 7894 | p_cp = FALSE; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7895 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7896 | if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) |
| 7897 | set_option_default(opt_idx, OPT_FREE, FALSE); |
| 7898 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 7899 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7900 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7901 | |
| 7902 | if (fname != NULL) |
| 7903 | { |
| 7904 | p = vim_getenv(envname, &dofree); |
| 7905 | if (p == NULL) |
| 7906 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7907 | // Set $MYVIMRC to the first vimrc file found. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7908 | p = FullName_save(fname, FALSE); |
| 7909 | if (p != NULL) |
| 7910 | { |
| 7911 | vim_setenv(envname, p); |
| 7912 | vim_free(p); |
| 7913 | } |
| 7914 | } |
| 7915 | else if (dofree) |
| 7916 | vim_free(p); |
| 7917 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | /* |
| 7921 | * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. |
| 7922 | */ |
| 7923 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7924 | change_compatible(int on) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7925 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7926 | int opt_idx; |
| 7927 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7928 | if (p_cp != on) |
| 7929 | { |
| 7930 | p_cp = on; |
| 7931 | compatible_set(); |
| 7932 | } |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7933 | opt_idx = findoption((char_u *)"cp"); |
| 7934 | if (opt_idx >= 0) |
| 7935 | options[opt_idx].flags |= P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7936 | } |
| 7937 | |
| 7938 | /* |
| 7939 | * Return TRUE when option "name" has been set. |
Bram Moolenaar | 1a4a75c | 2013-07-28 16:03:06 +0200 | [diff] [blame] | 7940 | * Only works correctly for global options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7941 | */ |
| 7942 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7943 | option_was_set(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7944 | { |
| 7945 | int idx; |
| 7946 | |
| 7947 | idx = findoption(name); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7948 | if (idx < 0) // unknown option |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7949 | return FALSE; |
| 7950 | if (options[idx].flags & P_WAS_SET) |
| 7951 | return TRUE; |
| 7952 | return FALSE; |
| 7953 | } |
| 7954 | |
| 7955 | /* |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7956 | * Reset the flag indicating option "name" was set. |
| 7957 | */ |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 7958 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7959 | reset_option_was_set(char_u *name) |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7960 | { |
| 7961 | int idx = findoption(name); |
| 7962 | |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 7963 | if (idx < 0) |
| 7964 | return FAIL; |
| 7965 | |
| 7966 | options[idx].flags &= ~P_WAS_SET; |
| 7967 | return OK; |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7968 | } |
| 7969 | |
| 7970 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7971 | * compatible_set() - Called when 'compatible' has been set or unset. |
| 7972 | * |
| 7973 | * When 'compatible' set: Set all relevant options (those that have the P_VIM) |
| 7974 | * flag) to a Vi compatible value. |
| 7975 | * When 'compatible' is unset: Set all options that have a different default |
| 7976 | * for Vim (without the P_VI_DEF flag) to that default. |
| 7977 | */ |
| 7978 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7979 | compatible_set(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7980 | { |
| 7981 | int opt_idx; |
| 7982 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7983 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7984 | if ( ((options[opt_idx].flags & P_VIM) && p_cp) |
| 7985 | || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) |
| 7986 | set_option_default(opt_idx, OPT_FREE, p_cp); |
| 7987 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 7988 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7989 | } |
| 7990 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7991 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7992 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7993 | /* |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 7994 | * Called when the 'breakat' option changes value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7995 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 7996 | char * |
| 7997 | did_set_breakat(optset_T *args UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7998 | { |
Bram Moolenaar | ac6e65f | 2005-08-29 22:25:38 +0000 | [diff] [blame] | 7999 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8000 | int i; |
| 8001 | |
| 8002 | for (i = 0; i < 256; i++) |
| 8003 | breakat_flags[i] = FALSE; |
| 8004 | |
| 8005 | if (p_breakat != NULL) |
Bram Moolenaar | ac6e65f | 2005-08-29 22:25:38 +0000 | [diff] [blame] | 8006 | for (p = p_breakat; *p; p++) |
| 8007 | breakat_flags[*p] = TRUE; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 8008 | |
| 8009 | return NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8010 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8011 | #endif |
| 8012 | |
| 8013 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8014 | * Check if backspacing over something is allowed. |
| 8015 | */ |
| 8016 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8017 | can_bs( |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 8018 | int what) // BS_INDENT, BS_EOL, BS_START or BS_NOSTOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8019 | { |
Bram Moolenaar | 6b810d9 | 2018-06-04 17:28:44 +0200 | [diff] [blame] | 8020 | #ifdef FEAT_JOB_CHANNEL |
| 8021 | if (what == BS_START && bt_prompt(curbuf)) |
| 8022 | return FALSE; |
| 8023 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8024 | switch (*p_bs) |
| 8025 | { |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 8026 | case '3': return TRUE; |
| 8027 | case '2': return (what != BS_NOSTOP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8028 | case '1': return (what != BS_START); |
| 8029 | case '0': return FALSE; |
| 8030 | } |
| 8031 | return vim_strchr(p_bs, what) != NULL; |
| 8032 | } |
| 8033 | |
| 8034 | /* |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 8035 | * Return the effective 'scrolloff' value for the current window, using the |
| 8036 | * global value when appropriate. |
| 8037 | */ |
| 8038 | long |
| 8039 | get_scrolloff_value(void) |
| 8040 | { |
| 8041 | return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; |
| 8042 | } |
| 8043 | |
| 8044 | /* |
| 8045 | * Return the effective 'sidescrolloff' value for the current window, using the |
| 8046 | * global value when appropriate. |
| 8047 | */ |
| 8048 | long |
| 8049 | get_sidescrolloff_value(void) |
| 8050 | { |
| 8051 | return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; |
| 8052 | } |
| 8053 | |
| 8054 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 8055 | * Get the local or global value of 'backupcopy'. |
| 8056 | */ |
| 8057 | unsigned int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8058 | get_bkc_value(buf_T *buf) |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 8059 | { |
| 8060 | return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; |
| 8061 | } |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 8062 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 8063 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8064 | /* |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8065 | * Get the local or global value of 'formatlistpat'. |
| 8066 | */ |
| 8067 | char_u * |
| 8068 | get_flp_value(buf_T *buf) |
| 8069 | { |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8070 | if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL) |
| 8071 | return p_flp; |
| 8072 | return buf->b_p_flp; |
| 8073 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 8074 | #endif |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8075 | |
| 8076 | /* |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8077 | * Get the local or global value of the 'virtualedit' flags. |
| 8078 | */ |
| 8079 | unsigned int |
| 8080 | get_ve_flags(void) |
| 8081 | { |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 8082 | return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) |
| 8083 | & ~(VE_NONE | VE_NONEU); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8084 | } |
| 8085 | |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 8086 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 8087 | /* |
| 8088 | * Get the local or global value of 'showbreak'. |
| 8089 | */ |
| 8090 | char_u * |
| 8091 | get_showbreak_value(win_T *win) |
| 8092 | { |
| 8093 | if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) |
| 8094 | return p_sbr; |
| 8095 | if (STRCMP(win->w_p_sbr, "NONE") == 0) |
| 8096 | return empty_option; |
| 8097 | return win->w_p_sbr; |
| 8098 | } |
| 8099 | #endif |
| 8100 | |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8101 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 8102 | /* |
| 8103 | * Get window or buffer local options. |
| 8104 | */ |
| 8105 | dict_T * |
| 8106 | get_winbuf_options(int bufopt) |
| 8107 | { |
| 8108 | dict_T *d; |
| 8109 | int opt_idx; |
| 8110 | |
| 8111 | d = dict_alloc(); |
| 8112 | if (d == NULL) |
| 8113 | return NULL; |
| 8114 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8115 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8116 | { |
| 8117 | struct vimoption *opt = &options[opt_idx]; |
| 8118 | |
| 8119 | if ((bufopt && (opt->indir & PV_BUF)) |
| 8120 | || (!bufopt && (opt->indir & PV_WIN))) |
| 8121 | { |
| 8122 | char_u *varp = get_varp(opt); |
| 8123 | |
| 8124 | if (varp != NULL) |
| 8125 | { |
| 8126 | if (opt->flags & P_STRING) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8127 | dict_add_string(d, opt->fullname, *(char_u **)varp); |
Bram Moolenaar | 789a5c0 | 2016-09-12 19:51:11 +0200 | [diff] [blame] | 8128 | else if (opt->flags & P_NUM) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8129 | dict_add_number(d, opt->fullname, *(long *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8130 | else |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8131 | dict_add_number(d, opt->fullname, *(int *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8132 | } |
| 8133 | } |
| 8134 | } |
| 8135 | |
| 8136 | return d; |
| 8137 | } |
| 8138 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8139 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8140 | #if defined(FEAT_SYN_HL) || defined(PROTO) |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8141 | /* |
| 8142 | * This is called when 'culopt' is changed |
| 8143 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8144 | int |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8145 | fill_culopt_flags(char_u *val, win_T *wp) |
| 8146 | { |
| 8147 | char_u *p; |
| 8148 | char_u culopt_flags_new = 0; |
| 8149 | |
| 8150 | if (val == NULL) |
| 8151 | p = wp->w_p_culopt; |
| 8152 | else |
| 8153 | p = val; |
| 8154 | while (*p != NUL) |
| 8155 | { |
| 8156 | if (STRNCMP(p, "line", 4) == 0) |
| 8157 | { |
| 8158 | p += 4; |
| 8159 | culopt_flags_new |= CULOPT_LINE; |
| 8160 | } |
| 8161 | else if (STRNCMP(p, "both", 4) == 0) |
| 8162 | { |
| 8163 | p += 4; |
| 8164 | culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; |
| 8165 | } |
| 8166 | else if (STRNCMP(p, "number", 6) == 0) |
| 8167 | { |
| 8168 | p += 6; |
| 8169 | culopt_flags_new |= CULOPT_NBR; |
| 8170 | } |
| 8171 | else if (STRNCMP(p, "screenline", 10) == 0) |
| 8172 | { |
| 8173 | p += 10; |
| 8174 | culopt_flags_new |= CULOPT_SCRLINE; |
| 8175 | } |
| 8176 | |
| 8177 | if (*p != ',' && *p != NUL) |
| 8178 | return FAIL; |
| 8179 | if (*p == ',') |
| 8180 | ++p; |
| 8181 | } |
| 8182 | |
| 8183 | // Can't have both "line" and "screenline". |
| 8184 | if ((culopt_flags_new & CULOPT_LINE) && (culopt_flags_new & CULOPT_SCRLINE)) |
| 8185 | return FAIL; |
| 8186 | wp->w_p_culopt_flags = culopt_flags_new; |
| 8187 | |
| 8188 | return OK; |
| 8189 | } |
| 8190 | #endif |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8191 | |
| 8192 | /* |
| 8193 | * Get the value of 'magic' adjusted for Vim9 script. |
| 8194 | */ |
| 8195 | int |
| 8196 | magic_isset(void) |
| 8197 | { |
| 8198 | switch (magic_overruled) |
| 8199 | { |
Bram Moolenaar | d93a7fc | 2021-01-04 12:42:13 +0100 | [diff] [blame] | 8200 | case OPTION_MAGIC_ON: return TRUE; |
| 8201 | case OPTION_MAGIC_OFF: return FALSE; |
| 8202 | case OPTION_MAGIC_NOT_SET: break; |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8203 | } |
| 8204 | #ifdef FEAT_EVAL |
| 8205 | if (in_vim9script()) |
| 8206 | return TRUE; |
| 8207 | #endif |
| 8208 | return p_magic; |
| 8209 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8210 | |
| 8211 | /* |
| 8212 | * Set the callback function value for an option that accepts a function name, |
| 8213 | * lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.) |
| 8214 | * Returns OK if the option is successfully set to a function, otherwise |
| 8215 | * returns FAIL. |
| 8216 | */ |
| 8217 | int |
| 8218 | option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED) |
| 8219 | { |
| 8220 | #ifdef FEAT_EVAL |
| 8221 | typval_T *tv; |
| 8222 | callback_T cb; |
| 8223 | |
| 8224 | if (optval == NULL || *optval == NUL) |
| 8225 | { |
| 8226 | free_callback(optcb); |
| 8227 | return OK; |
| 8228 | } |
| 8229 | |
Yegappan Lakshmanan | 05e59e3 | 2021-12-01 10:30:07 +0000 | [diff] [blame] | 8230 | if (*optval == '{' || (in_vim9script() && *optval == '(') |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8231 | || (STRNCMP(optval, "function(", 9) == 0) |
| 8232 | || (STRNCMP(optval, "funcref(", 8) == 0)) |
| 8233 | // Lambda expression or a funcref |
| 8234 | tv = eval_expr(optval, NULL); |
| 8235 | else |
| 8236 | // treat everything else as a function name string |
Yegappan Lakshmanan | e7f4abd | 2021-12-24 20:47:38 +0000 | [diff] [blame] | 8237 | tv = alloc_string_tv(vim_strsave(optval)); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8238 | if (tv == NULL) |
| 8239 | return FAIL; |
| 8240 | |
| 8241 | cb = get_callback(tv); |
Yegappan Lakshmanan | 4dc24eb | 2021-12-07 12:23:57 +0000 | [diff] [blame] | 8242 | if (cb.cb_name == NULL || *cb.cb_name == NUL) |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8243 | { |
| 8244 | free_tv(tv); |
| 8245 | return FAIL; |
| 8246 | } |
| 8247 | |
| 8248 | free_callback(optcb); |
| 8249 | set_callback(optcb, &cb); |
Bram Moolenaar | c96b7f5 | 2022-12-02 15:58:38 +0000 | [diff] [blame] | 8250 | if (cb.cb_free_name) |
| 8251 | vim_free(cb.cb_name); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8252 | free_tv(tv); |
Bram Moolenaar | f0e7e63 | 2022-01-21 13:29:56 +0000 | [diff] [blame] | 8253 | |
| 8254 | // when using Vim9 style "import.funcname" it needs to be expanded to |
| 8255 | // "import#funcname". |
| 8256 | expand_autload_callback(optcb); |
| 8257 | |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8258 | return OK; |
| 8259 | #else |
| 8260 | return FAIL; |
| 8261 | #endif |
| 8262 | } |