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 compatible_set(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 72 | * Initialize the 'shell' option to a default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 73 | */ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 74 | static void |
| 75 | set_init_default_shell(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | { |
| 77 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 78 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 79 | // Find default value for 'shell' option. |
| 80 | // Don't use it if it is empty. |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 81 | if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 82 | #if defined(MSWIN) |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 83 | || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) |
Bram Moolenaar | 6aa2cd4 | 2016-02-16 15:06:59 +0100 | [diff] [blame] | 84 | || ((p = (char_u *)default_shell()) != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 85 | #endif |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 86 | ) |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 87 | #if defined(MSWIN) |
| 88 | { |
| 89 | // For MS-Windows put the path in quotes instead of escaping spaces. |
| 90 | char_u *cmd; |
| 91 | size_t len; |
| 92 | |
| 93 | if (vim_strchr(p, ' ') != NULL) |
| 94 | { |
| 95 | len = STRLEN(p) + 3; // two quotes and a trailing NUL |
| 96 | cmd = alloc(len); |
Bram Moolenaar | 1671de3 | 2019-10-05 21:35:16 +0200 | [diff] [blame] | 97 | if (cmd != NULL) |
| 98 | { |
| 99 | vim_snprintf((char *)cmd, len, "\"%s\"", p); |
| 100 | set_string_default("sh", cmd); |
| 101 | vim_free(cmd); |
| 102 | } |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 103 | } |
| 104 | else |
| 105 | set_string_default("sh", p); |
| 106 | } |
| 107 | #else |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 108 | set_string_default_esc("sh", p, TRUE); |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 109 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 110 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 111 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 112 | /* |
| 113 | * Set the default for 'backupskip' to include environment variables for |
| 114 | * temp files. |
| 115 | */ |
| 116 | static void |
| 117 | set_init_default_backupskip(void) |
| 118 | { |
| 119 | int opt_idx; |
| 120 | long_u n; |
| 121 | char_u *p; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 122 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 123 | static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 124 | #else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 125 | static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 126 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 127 | int len; |
| 128 | garray_T ga; |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 129 | char_u *item; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 130 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 131 | opt_idx = findoption((char_u *)"backupskip"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 133 | ga_init2(&ga, 1, 100); |
| 134 | for (n = 0; n < (long)ARRAY_LENGTH(names); ++n) |
| 135 | { |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 136 | int mustfree = FALSE; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 137 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 138 | if (*names[n] == NUL) |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 139 | # ifdef MACOS_X |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 140 | p = (char_u *)"/private/tmp"; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 141 | # else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 142 | p = (char_u *)"/tmp"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 144 | else |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 145 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 146 | p = vim_getenv((char_u *)names[n], &mustfree); |
| 147 | if (p != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 148 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 149 | // First time count the NUL, otherwise count the ','. |
| 150 | len = (int)STRLEN(p) + 3; |
| 151 | item = alloc(len); |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 152 | if (item != NULL) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 153 | { |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 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); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 167 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 168 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 169 | if (mustfree) |
| 170 | vim_free(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 171 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 172 | if (ga.ga_data != NULL) |
| 173 | { |
| 174 | set_string_default("bsk", ga.ga_data); |
| 175 | vim_free(ga.ga_data); |
| 176 | } |
| 177 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 179 | /* |
| 180 | * Initialize the 'maxmemtot' and 'maxmem' options to a default value. |
| 181 | * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory. |
| 182 | */ |
| 183 | static void |
| 184 | set_init_default_maxmemtot(void) |
| 185 | { |
| 186 | int opt_idx; |
| 187 | long_u n; |
| 188 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 189 | opt_idx = findoption((char_u *)"maxmemtot"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 190 | if (opt_idx < 0) |
| 191 | return; |
| 192 | |
| 193 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
| 194 | if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) |
| 195 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 196 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 197 | #if defined(HAVE_AVAIL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 198 | // Use amount of memory available at this moment. |
| 199 | n = (mch_avail_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 200 | #elif defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 201 | // Use amount of memory available to Vim. |
| 202 | n = (mch_total_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 203 | #else |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 204 | n = (0x7fffffff >> 11); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 205 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 206 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
| 207 | opt_idx = findoption((char_u *)"maxmem"); |
| 208 | if (opt_idx >= 0) |
| 209 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 210 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 211 | if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n |
| 212 | || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L) |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 213 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 214 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 215 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 216 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 217 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 218 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 219 | /* |
| 220 | * Initialize the 'cdpath' option to a default value. |
| 221 | */ |
| 222 | static void |
| 223 | set_init_default_cdpath(void) |
| 224 | { |
| 225 | int opt_idx; |
| 226 | char_u *cdpath; |
| 227 | char_u *buf; |
| 228 | int i; |
| 229 | int j; |
| 230 | int mustfree = FALSE; |
| 231 | |
| 232 | cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); |
| 233 | if (cdpath == NULL) |
| 234 | return; |
| 235 | |
| 236 | buf = alloc((STRLEN(cdpath) << 1) + 2); |
| 237 | if (buf != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 239 | buf[0] = ','; // start with ",", current dir first |
| 240 | j = 1; |
| 241 | for (i = 0; cdpath[i] != NUL; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 242 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 243 | if (vim_ispathlistsep(cdpath[i])) |
| 244 | buf[j++] = ','; |
| 245 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 246 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 247 | if (cdpath[i] == ' ' || cdpath[i] == ',') |
| 248 | buf[j++] = '\\'; |
| 249 | buf[j++] = cdpath[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 252 | buf[j] = NUL; |
| 253 | opt_idx = findoption((char_u *)"cdpath"); |
| 254 | if (opt_idx >= 0) |
| 255 | { |
| 256 | options[opt_idx].def_val[VI_DEFAULT] = buf; |
| 257 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 258 | } |
| 259 | else |
| 260 | vim_free(buf); // cannot happen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 261 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 262 | if (mustfree) |
| 263 | vim_free(cdpath); |
| 264 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 265 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 266 | /* |
| 267 | * Initialize the 'printencoding' option to a default value. |
| 268 | */ |
| 269 | static void |
| 270 | set_init_default_printencoding(void) |
| 271 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 272 | #if defined(FEAT_POSTSCRIPT) && \ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 273 | (defined(MSWIN) || defined(VMS) || defined(MAC) || defined(hpux)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 274 | // Set print encoding on platforms that don't default to latin1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 275 | set_string_default("penc", |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 276 | # if defined(MSWIN) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 277 | (char_u *)"cp1252" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 278 | # elif defined(VMS) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 279 | (char_u *)"dec-mcs" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 280 | # elif defined(MAC) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 281 | (char_u *)"mac-roman" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 282 | # else // HPUX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 283 | (char_u *)"hp-roman8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 284 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 285 | ); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 286 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 287 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 288 | |
| 289 | #ifdef FEAT_POSTSCRIPT |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 290 | /* |
| 291 | * Initialize the 'printexpr' option to a default value. |
| 292 | */ |
| 293 | static void |
| 294 | set_init_default_printexpr(void) |
| 295 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 296 | // 'printexpr' must be allocated to be able to evaluate it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 297 | set_string_default("pexpr", |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 298 | # if defined(MSWIN) |
Bram Moolenaar | ed20346 | 2004-06-16 11:19:22 +0000 | [diff] [blame] | 299 | (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] | 300 | # elif defined(VMS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 301 | (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" |
| 302 | |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 303 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 304 | (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] | 305 | # endif |
| 306 | ); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 307 | } |
| 308 | #endif |
| 309 | |
| 310 | #ifdef UNIX |
| 311 | /* |
| 312 | * Force restricted-mode on for "nologin" or "false" $SHELL |
| 313 | */ |
| 314 | static void |
| 315 | set_init_restricted_mode(void) |
| 316 | { |
| 317 | char_u *p; |
| 318 | |
| 319 | p = get_isolated_shell_name(); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 320 | if (p == NULL) |
| 321 | return; |
| 322 | if (fnamecmp(p, "nologin") == 0 || fnamecmp(p, "false") == 0) |
| 323 | restricted = TRUE; |
| 324 | vim_free(p); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 325 | } |
| 326 | #endif |
| 327 | |
| 328 | #ifdef CLEAN_RUNTIMEPATH |
| 329 | /* |
| 330 | * When Vim is started with the "--clean" argument, set the default value |
| 331 | * for the 'runtimepath' and 'packpath' options. |
| 332 | */ |
| 333 | static void |
| 334 | set_init_clean_rtp(void) |
| 335 | { |
| 336 | int opt_idx; |
| 337 | |
| 338 | opt_idx = findoption((char_u *)"runtimepath"); |
| 339 | if (opt_idx >= 0) |
| 340 | { |
| 341 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 342 | p_rtp = (char_u *)CLEAN_RUNTIMEPATH; |
| 343 | } |
| 344 | opt_idx = findoption((char_u *)"packpath"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 345 | if (opt_idx < 0) |
| 346 | return; |
| 347 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 348 | p_pp = (char_u *)CLEAN_RUNTIMEPATH; |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 349 | } |
| 350 | #endif |
| 351 | |
| 352 | /* |
| 353 | * Expand environment variables and things like "~" for the defaults. |
| 354 | * If option_expand() returns non-NULL the variable is expanded. This can |
| 355 | * only happen for non-indirect options. |
| 356 | * Also set the default to the expanded value, so ":set" does not list |
| 357 | * them. |
| 358 | * Don't set the P_ALLOCED flag, because we don't want to free the |
| 359 | * default. |
| 360 | */ |
| 361 | static void |
| 362 | set_init_expand_env(void) |
| 363 | { |
| 364 | int opt_idx; |
| 365 | char_u *p; |
| 366 | |
| 367 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
| 368 | { |
| 369 | if ((options[opt_idx].flags & P_GETTEXT) |
| 370 | && options[opt_idx].var != NULL) |
| 371 | p = (char_u *)_(*(char **)options[opt_idx].var); |
| 372 | else |
| 373 | p = option_expand(opt_idx, NULL); |
| 374 | if (p != NULL && (p = vim_strsave(p)) != NULL) |
| 375 | { |
| 376 | *(char_u **)options[opt_idx].var = p; |
| 377 | // VIMEXP |
| 378 | // Defaults for all expanded options are currently the same for Vi |
| 379 | // and Vim. When this changes, add some code here! Also need to |
| 380 | // split P_DEF_ALLOCED in two. |
| 381 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 382 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 383 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 384 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Initialize the 'LANG' environment variable to a default value. |
| 391 | */ |
| 392 | static void |
| 393 | set_init_lang_env(void) |
| 394 | { |
| 395 | #if defined(MSWIN) && defined(FEAT_GETTEXT) |
| 396 | // If $LANG isn't set, try to get a good value for it. This makes the |
| 397 | // right language be used automatically. Don't do this for English. |
| 398 | if (mch_getenv((char_u *)"LANG") == NULL) |
| 399 | { |
| 400 | char buf[20]; |
| 401 | long_u n; |
| 402 | |
| 403 | // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. |
| 404 | // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use |
| 405 | // only the first two. |
| 406 | n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, |
| 407 | (LPTSTR)buf, 20); |
| 408 | if (n >= 2 && STRNICMP(buf, "en", 2) != 0) |
| 409 | { |
| 410 | // There are a few exceptions (probably more) |
| 411 | if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) |
| 412 | STRCPY(buf, "zh_TW"); |
| 413 | else if (STRNICMP(buf, "chs", 3) == 0 |
| 414 | || STRNICMP(buf, "zhc", 3) == 0) |
| 415 | STRCPY(buf, "zh_CN"); |
| 416 | else if (STRNICMP(buf, "jp", 2) == 0) |
| 417 | STRCPY(buf, "ja"); |
| 418 | else |
| 419 | buf[2] = NUL; // truncate to two-letter code |
| 420 | vim_setenv((char_u *)"LANG", (char_u *)buf); |
| 421 | } |
| 422 | } |
| 423 | #elif defined(MACOS_CONVERT) |
| 424 | // Moved to os_mac_conv.c to avoid dependency problems. |
| 425 | mac_lang_init(); |
| 426 | #endif |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Initialize the 'encoding' option to a default value. |
| 431 | */ |
| 432 | static void |
| 433 | set_init_default_encoding(void) |
| 434 | { |
| 435 | char_u *p; |
| 436 | int opt_idx; |
| 437 | |
| 438 | # ifdef MSWIN |
| 439 | // MS-Windows has builtin support for conversion to and from Unicode, using |
| 440 | // "utf-8" for 'encoding' should work best for most users. |
| 441 | p = vim_strsave((char_u *)ENC_DFLT); |
| 442 | # else |
| 443 | // enc_locale() will try to find the encoding of the current locale. |
| 444 | // This works best for properly configured systems, old and new. |
| 445 | p = enc_locale(); |
| 446 | # endif |
| 447 | if (p == NULL) |
| 448 | return; |
| 449 | |
| 450 | // Try setting 'encoding' and check if the value is valid. |
| 451 | // If not, go back to the default encoding. |
| 452 | char_u *save_enc = p_enc; |
| 453 | p_enc = p; |
| 454 | if (STRCMP(p_enc, "gb18030") == 0) |
| 455 | { |
| 456 | // We don't support "gb18030", but "cp936" is a good substitute |
| 457 | // for practical purposes, thus use that. It's not an alias to |
| 458 | // still support conversion between gb18030 and utf-8. |
| 459 | p_enc = vim_strsave((char_u *)"cp936"); |
| 460 | vim_free(p); |
| 461 | } |
| 462 | if (mb_init() == NULL) |
| 463 | { |
| 464 | opt_idx = findoption((char_u *)"encoding"); |
| 465 | if (opt_idx >= 0) |
| 466 | { |
| 467 | options[opt_idx].def_val[VI_DEFAULT] = p_enc; |
| 468 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 469 | } |
| 470 | |
| 471 | #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) |
| 472 | if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) |
| 473 | { |
| 474 | // Adjust the default for 'isprint' and 'iskeyword' to match |
| 475 | // latin1. Also set the defaults for when 'nocompatible' is |
| 476 | // set. |
| 477 | set_string_option_direct((char_u *)"isp", -1, |
| 478 | ISP_LATIN1, OPT_FREE, SID_NONE); |
| 479 | set_string_option_direct((char_u *)"isk", -1, |
| 480 | ISK_LATIN1, OPT_FREE, SID_NONE); |
| 481 | opt_idx = findoption((char_u *)"isp"); |
| 482 | if (opt_idx >= 0) |
| 483 | options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; |
| 484 | opt_idx = findoption((char_u *)"isk"); |
| 485 | if (opt_idx >= 0) |
| 486 | options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; |
| 487 | (void)init_chartab(); |
| 488 | } |
| 489 | #endif |
| 490 | |
| 491 | #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
| 492 | // Win32 console: When GetACP() returns a different value from |
| 493 | // GetConsoleCP() set 'termencoding'. |
| 494 | if ( |
| 495 | # ifdef VIMDLL |
| 496 | (!gui.in_use && !gui.starting) && |
| 497 | # endif |
| 498 | GetACP() != GetConsoleCP()) |
| 499 | { |
| 500 | char buf[50]; |
| 501 | |
| 502 | // Win32 console: In ConPTY, GetConsoleCP() returns zero. |
| 503 | // Use an alternative value. |
| 504 | if (GetConsoleCP() == 0) |
| 505 | sprintf(buf, "cp%ld", (long)GetACP()); |
| 506 | else |
| 507 | sprintf(buf, "cp%ld", (long)GetConsoleCP()); |
| 508 | p_tenc = vim_strsave((char_u *)buf); |
| 509 | if (p_tenc != NULL) |
| 510 | { |
| 511 | opt_idx = findoption((char_u *)"termencoding"); |
| 512 | if (opt_idx >= 0) |
| 513 | { |
| 514 | options[opt_idx].def_val[VI_DEFAULT] = p_tenc; |
| 515 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 516 | } |
| 517 | convert_setup(&input_conv, p_tenc, p_enc); |
| 518 | convert_setup(&output_conv, p_enc, p_tenc); |
| 519 | } |
| 520 | else |
| 521 | p_tenc = empty_option; |
| 522 | } |
| 523 | #endif |
| 524 | #if defined(MSWIN) |
| 525 | // $HOME may have characters in active code page. |
| 526 | init_homedir(); |
| 527 | #endif |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | vim_free(p_enc); |
| 532 | p_enc = save_enc; |
| 533 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* |
| 537 | * Initialize the options, first part. |
| 538 | * |
| 539 | * Called only once from main(), just after creating the first buffer. |
| 540 | * If "clean_arg" is TRUE Vim was started with --clean. |
| 541 | */ |
| 542 | void |
| 543 | set_init_1(int clean_arg) |
| 544 | { |
| 545 | #ifdef FEAT_LANGMAP |
| 546 | langmap_init(); |
| 547 | #endif |
| 548 | |
| 549 | // Be Vi compatible by default |
| 550 | p_cp = TRUE; |
| 551 | |
| 552 | // Use POSIX compatibility when $VIM_POSIX is set. |
| 553 | if (mch_getenv((char_u *)"VIM_POSIX") != NULL) |
| 554 | { |
| 555 | set_string_default("cpo", (char_u *)CPO_ALL); |
| 556 | set_string_default("shm", (char_u *)SHM_POSIX); |
| 557 | } |
| 558 | |
| 559 | set_init_default_shell(); |
| 560 | set_init_default_backupskip(); |
| 561 | set_init_default_maxmemtot(); |
| 562 | set_init_default_cdpath(); |
| 563 | set_init_default_printencoding(); |
| 564 | #ifdef FEAT_POSTSCRIPT |
| 565 | set_init_default_printexpr(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 566 | #endif |
| 567 | |
| 568 | /* |
| 569 | * Set all the options (except the terminal options) to their default |
| 570 | * value. Also set the global value for local options. |
| 571 | */ |
| 572 | set_options_default(0); |
| 573 | |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 574 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 575 | set_init_restricted_mode(); |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 576 | #endif |
| 577 | |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 578 | #ifdef CLEAN_RUNTIMEPATH |
| 579 | if (clean_arg) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 580 | set_init_clean_rtp(); |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 581 | #endif |
| 582 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 583 | #ifdef FEAT_GUI |
| 584 | if (found_reverse_arg) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 585 | 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] | 586 | #endif |
| 587 | |
| 588 | curbuf->b_p_initialized = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 589 | curbuf->b_p_ar = -1; // no local 'autoread' value |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 590 | curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 591 | check_buf_options(curbuf); |
| 592 | check_win_options(curwin); |
| 593 | check_options(); |
| 594 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 595 | // Must be before option_expand(), because that one needs vim_isIDc() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 596 | didset_options(); |
| 597 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 598 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 599 | // Use the current chartab for the generic chartab. This is not in |
| 600 | // didset_options() because it only depends on 'encoding'. |
Bram Moolenaar | 6bb6836 | 2005-03-22 23:03:44 +0000 | [diff] [blame] | 601 | init_spell_chartab(); |
| 602 | #endif |
| 603 | |
K.Takata | ce3189d | 2023-02-15 19:13:43 +0000 | [diff] [blame] | 604 | set_init_default_encoding(); |
| 605 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 606 | // Expand environment variables and things like "~" for the defaults. |
| 607 | set_init_expand_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 608 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 609 | save_file_ff(curbuf); // Buffer is unchanged |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 610 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 611 | #if defined(FEAT_ARABIC) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 612 | // Detect use of mlterm. |
| 613 | // Mlterm is a terminal emulator akin to xterm that has some special |
| 614 | // abilities (bidi namely). |
| 615 | // NOTE: mlterm's author is being asked to 'set' a variable |
| 616 | // instead of an environment variable due to inheritance. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 617 | if (mch_getenv((char_u *)"MLTERM") != NULL) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 618 | set_option_value_give_err((char_u *)"tbidi", 1L, NULL, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 619 | #endif |
| 620 | |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 621 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 622 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 623 | set_init_lang_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 624 | |
| 625 | #ifdef FEAT_MULTI_LANG |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 626 | // Set the default for 'helplang'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 627 | set_helplang_default(get_mess_lang()); |
| 628 | #endif |
| 629 | } |
| 630 | |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 631 | static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1"; |
| 632 | |
| 633 | /* |
| 634 | * Set the "fileencodings" option to the default value for when 'encoding' is |
| 635 | * utf-8. |
| 636 | */ |
| 637 | void |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 638 | set_fencs_unicode(void) |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 639 | { |
| 640 | set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, |
| 641 | OPT_FREE, 0); |
| 642 | } |
| 643 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 644 | /* |
| 645 | * Set an option to its default value. |
| 646 | * This does not take care of side effects! |
| 647 | */ |
| 648 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 649 | set_option_default( |
| 650 | int opt_idx, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 651 | int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
| 652 | int compatible) // use Vi default value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 653 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 654 | char_u *varp; // pointer to variable for current option |
| 655 | int dvi; // index in def_val[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 656 | long_u flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 657 | long_u *flagsp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 658 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 659 | |
| 660 | varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); |
| 661 | flags = options[opt_idx].flags; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 662 | if (varp != NULL) // skip hidden option, nothing to do for it |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 663 | { |
| 664 | dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
| 665 | if (flags & P_STRING) |
| 666 | { |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 667 | // 'fencs' default value depends on 'encoding' |
| 668 | if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8) |
| 669 | set_fencs_unicode(); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 670 | // Use set_string_option_direct() for local options to handle |
| 671 | // freeing and allocating the value. |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 672 | else if (options[opt_idx].indir != PV_NONE) |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 673 | set_string_option_direct(NULL, opt_idx, |
| 674 | options[opt_idx].def_val[dvi], opt_flags, 0); |
| 675 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 676 | { |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 677 | if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) |
| 678 | free_string_option(*(char_u **)(varp)); |
| 679 | *(char_u **)varp = options[opt_idx].def_val[dvi]; |
| 680 | options[opt_idx].flags &= ~P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | else if (flags & P_NUM) |
| 684 | { |
Bram Moolenaar | 5fc1a8b | 2006-10-17 16:34:24 +0000 | [diff] [blame] | 685 | if (options[opt_idx].indir == PV_SCROLL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 686 | win_comp_scroll(curwin); |
| 687 | else |
| 688 | { |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 689 | long def_val = (long)(long_i)options[opt_idx].def_val[dvi]; |
| 690 | |
| 691 | if ((long *)varp == &curwin->w_p_so |
| 692 | || (long *)varp == &curwin->w_p_siso) |
| 693 | // 'scrolloff' and 'sidescrolloff' local values have a |
| 694 | // different default value than the global default. |
| 695 | *(long *)varp = -1; |
| 696 | else |
| 697 | *(long *)varp = def_val; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 698 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 699 | if (both) |
| 700 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 701 | def_val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 704 | else // P_BOOL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 705 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 706 | // the cast to long is required for Manx C, long_i is needed for |
| 707 | // MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 708 | *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 709 | #ifdef UNIX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 710 | // 'modeline' defaults to off for root |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 711 | if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) |
| 712 | *(int *)varp = FALSE; |
| 713 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 714 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 715 | if (both) |
| 716 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
| 717 | *(int *)varp; |
| 718 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 719 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 720 | // The default value is not insecure. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 721 | flagsp = insecure_flag(opt_idx, opt_flags); |
| 722 | *flagsp = *flagsp & ~P_INSECURE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | #ifdef FEAT_EVAL |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 726 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 727 | #endif |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Set all options (except terminal options) to their default value. |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 732 | * When "opt_flags" is non-zero skip 'encoding'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 733 | */ |
| 734 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 735 | set_options_default( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 736 | int opt_flags) // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 737 | { |
| 738 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 739 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 740 | tabpage_T *tp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 741 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 742 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 743 | if (!(options[i].flags & P_NODEFAULT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 744 | && (opt_flags == 0 |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 745 | || (options[i].var != (char_u *)&p_enc |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 746 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 747 | && options[i].var != (char_u *)&p_cm |
Bram Moolenaar | 8060687 | 2015-08-25 21:27:35 +0200 | [diff] [blame] | 748 | && options[i].var != (char_u *)&p_key |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 749 | # endif |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 750 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 751 | set_option_default(i, opt_flags, p_cp); |
| 752 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 753 | // The 'scroll' option must be computed for all windows. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 754 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 755 | win_comp_scroll(wp); |
Bram Moolenaar | 5a4eceb | 2014-09-09 17:33:07 +0200 | [diff] [blame] | 756 | parse_cino(curbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* |
| 760 | * Set the Vi-default value of a string option. |
| 761 | * Used for 'sh', 'backupskip' and 'term'. |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 762 | * When "escape" is TRUE escape spaces with a backslash. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 763 | */ |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 764 | static void |
| 765 | set_string_default_esc(char *name, char_u *val, int escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 766 | { |
| 767 | char_u *p; |
| 768 | int opt_idx; |
| 769 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 770 | if (escape && vim_strchr(val, ' ') != NULL) |
| 771 | p = vim_strsave_escaped(val, (char_u *)" "); |
| 772 | else |
| 773 | p = vim_strsave(val); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 774 | if (p == NULL) // we don't want a NULL |
| 775 | return; |
| 776 | |
| 777 | opt_idx = findoption((char_u *)name); |
| 778 | if (opt_idx < 0) |
| 779 | return; |
| 780 | |
| 781 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 782 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 783 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 784 | options[opt_idx].flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 787 | void |
| 788 | set_string_default(char *name, char_u *val) |
| 789 | { |
| 790 | set_string_default_esc(name, val, FALSE); |
| 791 | } |
| 792 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 793 | /* |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 794 | * For an option value that contains comma separated items, find "newval" in |
| 795 | * "origval". Return NULL if not found. |
| 796 | */ |
| 797 | static char_u * |
| 798 | find_dup_item(char_u *origval, char_u *newval, long_u flags) |
| 799 | { |
Bram Moolenaar | 8f13d82 | 2020-09-12 21:04:23 +0200 | [diff] [blame] | 800 | int bs = 0; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 801 | size_t newlen; |
| 802 | char_u *s; |
| 803 | |
| 804 | if (origval == NULL) |
| 805 | return NULL; |
| 806 | |
| 807 | newlen = STRLEN(newval); |
| 808 | for (s = origval; *s != NUL; ++s) |
| 809 | { |
| 810 | if ((!(flags & P_COMMA) |
| 811 | || s == origval |
| 812 | || (s[-1] == ',' && !(bs & 1))) |
| 813 | && STRNCMP(s, newval, newlen) == 0 |
| 814 | && (!(flags & P_COMMA) |
| 815 | || s[newlen] == ',' |
| 816 | || s[newlen] == NUL)) |
| 817 | return s; |
| 818 | // Count backslashes. Only a comma with an even number of backslashes |
| 819 | // or a single backslash preceded by a comma before it is recognized as |
| 820 | // a separator. |
| 821 | if ((s > origval + 1 |
| 822 | && s[-1] == '\\' |
| 823 | && s[-2] != ',') |
| 824 | || (s == origval + 1 |
| 825 | && s[-1] == '\\')) |
| 826 | ++bs; |
| 827 | else |
| 828 | bs = 0; |
| 829 | } |
| 830 | return NULL; |
| 831 | } |
| 832 | |
| 833 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 834 | * Set the Vi-default value of a number option. |
| 835 | * Used for 'lines' and 'columns'. |
| 836 | */ |
| 837 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 838 | set_number_default(char *name, long val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 839 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 840 | int opt_idx; |
| 841 | |
| 842 | opt_idx = findoption((char_u *)name); |
| 843 | if (opt_idx >= 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 844 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 847 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 848 | /* |
| 849 | * Set all window-local and buffer-local options to the Vim default. |
| 850 | * local-global options will use the global value. |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 851 | * When "do_buffer" is FALSE don't set buffer-local options. |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 852 | */ |
| 853 | void |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 854 | set_local_options_default(win_T *wp, int do_buffer) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 855 | { |
| 856 | win_T *save_curwin = curwin; |
| 857 | int i; |
| 858 | |
| 859 | curwin = wp; |
| 860 | curbuf = curwin->w_buffer; |
| 861 | block_autocmds(); |
| 862 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 863 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 864 | { |
| 865 | struct vimoption *p = &(options[i]); |
| 866 | char_u *varp = get_varp_scope(p, OPT_LOCAL); |
| 867 | |
| 868 | if (p->indir != PV_NONE |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 869 | && (do_buffer || (p->indir & PV_BUF) == 0) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 870 | && !(options[i].flags & P_NODEFAULT) |
| 871 | && !optval_default(p, varp, FALSE)) |
Bram Moolenaar | 8617348 | 2019-10-01 17:02:16 +0200 | [diff] [blame] | 872 | set_option_default(i, OPT_FREE|OPT_LOCAL, FALSE); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | unblock_autocmds(); |
| 876 | curwin = save_curwin; |
| 877 | curbuf = curwin->w_buffer; |
| 878 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 879 | #endif |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 880 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 881 | #if defined(EXITFREE) || defined(PROTO) |
| 882 | /* |
| 883 | * Free all options. |
| 884 | */ |
| 885 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 886 | free_all_options(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 887 | { |
| 888 | int i; |
| 889 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 890 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 891 | { |
| 892 | if (options[i].indir == PV_NONE) |
| 893 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 894 | // global option: free value and default value. |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 895 | if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 896 | free_string_option(*(char_u **)options[i].var); |
| 897 | if (options[i].flags & P_DEF_ALLOCED) |
| 898 | free_string_option(options[i].def_val[VI_DEFAULT]); |
| 899 | } |
| 900 | else if (options[i].var != VAR_WIN |
| 901 | && (options[i].flags & P_STRING)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 902 | // buffer-local option: free global value |
Bram Moolenaar | 77111e2 | 2021-07-29 21:11:30 +0200 | [diff] [blame] | 903 | clear_string_option((char_u **)options[i].var); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 904 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 905 | free_operatorfunc_option(); |
Yegappan Lakshmanan | 19916a8 | 2021-11-24 16:32:55 +0000 | [diff] [blame] | 906 | free_tagfunc_option(); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 907 | } |
| 908 | #endif |
| 909 | |
| 910 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 911 | /* |
| 912 | * Initialize the options, part two: After getting Rows and Columns and |
| 913 | * setting 'term'. |
| 914 | */ |
| 915 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 916 | set_init_2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 917 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 918 | int idx; |
| 919 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [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 | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 922 | idx = findoption((char_u *)"scroll"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 923 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 924 | set_option_default(idx, OPT_LOCAL, p_cp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 925 | comp_col(); |
| 926 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 927 | // 'window' is only for backwards compatibility with Vi. |
| 928 | // Default is Rows - 1. |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 929 | if (!option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 930 | p_window = Rows - 1; |
| 931 | set_number_default("window", Rows - 1); |
| 932 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 933 | // For DOS console the default is always black. |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 934 | #if !((defined(MSWIN)) && !defined(FEAT_GUI)) |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 935 | // If 'background' wasn't set by the user, try guessing the value, |
| 936 | // depending on the terminal name. Only need to check for terminals |
| 937 | // with a dark background, that can handle color. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 938 | idx = findoption((char_u *)"bg"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 939 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET) |
| 940 | && *term_bg_default() == 'd') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 941 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 942 | set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 943 | // don't mark it as set, when starting the GUI it may be |
| 944 | // changed again |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 945 | options[idx].flags &= ~P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 946 | } |
| 947 | #endif |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 948 | |
| 949 | #ifdef CURSOR_SHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 950 | parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 951 | #endif |
| 952 | #ifdef FEAT_MOUSESHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 953 | parse_shape_opt(SHAPE_MOUSE); // set mouse shapes from 'mouseshape' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 954 | #endif |
| 955 | #ifdef FEAT_PRINTER |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 956 | (void)parse_printoptions(NULL); // parse 'printoptions' default value |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 957 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /* |
| 961 | * Initialize the options, part three: After reading the .vimrc |
| 962 | */ |
| 963 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 964 | set_init_3(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 965 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 966 | #if defined(UNIX) || defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 967 | /* |
| 968 | * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. |
| 969 | * This is done after other initializations, where 'shell' might have been |
| 970 | * set, but only if they have not been set before. |
| 971 | */ |
| 972 | char_u *p; |
| 973 | int idx_srr; |
| 974 | int do_srr; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 975 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 976 | int idx_sp; |
| 977 | int do_sp; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 978 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 979 | |
| 980 | idx_srr = findoption((char_u *)"srr"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 981 | if (idx_srr < 0) |
| 982 | do_srr = FALSE; |
| 983 | else |
| 984 | do_srr = !(options[idx_srr].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 985 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 986 | idx_sp = findoption((char_u *)"sp"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 987 | if (idx_sp < 0) |
| 988 | do_sp = FALSE; |
| 989 | else |
| 990 | do_sp = !(options[idx_sp].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 991 | # endif |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 992 | p = get_isolated_shell_name(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 993 | if (p != NULL) |
| 994 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 995 | // Default for p_sp is "| tee", for p_srr is ">". |
| 996 | // For known shells it is changed here to include stderr. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 997 | if ( fnamecmp(p, "csh") == 0 |
| 998 | || fnamecmp(p, "tcsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 999 | # if defined(MSWIN) // also check with .exe extension |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1000 | || fnamecmp(p, "csh.exe") == 0 |
| 1001 | || fnamecmp(p, "tcsh.exe") == 0 |
| 1002 | # endif |
| 1003 | ) |
| 1004 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1005 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | if (do_sp) |
| 1007 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1008 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1009 | p_sp = (char_u *)">&"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1010 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1011 | p_sp = (char_u *)"|& tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1012 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1013 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1014 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1015 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1016 | if (do_srr) |
| 1017 | { |
| 1018 | p_srr = (char_u *)">&"; |
| 1019 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1020 | } |
| 1021 | } |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1022 | # ifdef MSWIN |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1023 | // Windows PowerShell output is UTF-16 with BOM so re-encode to the |
| 1024 | // current codepage. |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1025 | else if ( fnamecmp(p, "powershell") == 0 |
| 1026 | || fnamecmp(p, "powershell.exe") == 0 |
| 1027 | ) |
| 1028 | { |
| 1029 | # if defined(FEAT_QUICKFIX) |
| 1030 | if (do_sp) |
| 1031 | { |
| 1032 | p_sp = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1033 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1034 | } |
| 1035 | # endif |
| 1036 | if (do_srr) |
| 1037 | { |
| 1038 | p_srr = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1039 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1040 | } |
| 1041 | } |
| 1042 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1043 | else |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1044 | // Always use POSIX shell style redirection if we reach this |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1045 | if ( fnamecmp(p, "sh") == 0 |
| 1046 | || fnamecmp(p, "ksh") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1047 | || fnamecmp(p, "mksh") == 0 |
| 1048 | || fnamecmp(p, "pdksh") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1049 | || fnamecmp(p, "zsh") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1050 | || fnamecmp(p, "zsh-beta") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1051 | || fnamecmp(p, "bash") == 0 |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 1052 | || fnamecmp(p, "fish") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1053 | || fnamecmp(p, "ash") == 0 |
| 1054 | || fnamecmp(p, "dash") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1055 | || fnamecmp(p, "pwsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1056 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1057 | || fnamecmp(p, "cmd") == 0 |
| 1058 | || fnamecmp(p, "sh.exe") == 0 |
| 1059 | || fnamecmp(p, "ksh.exe") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1060 | || fnamecmp(p, "mksh.exe") == 0 |
| 1061 | || fnamecmp(p, "pdksh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1062 | || fnamecmp(p, "zsh.exe") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1063 | || fnamecmp(p, "zsh-beta.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1064 | || fnamecmp(p, "bash.exe") == 0 |
| 1065 | || fnamecmp(p, "cmd.exe") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1066 | || fnamecmp(p, "dash.exe") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1067 | || fnamecmp(p, "pwsh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1068 | # endif |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1069 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1070 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1071 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1072 | if (do_sp) |
| 1073 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1074 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1075 | p_sp = (char_u *)">%s 2>&1"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1076 | # else |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1077 | if (fnamecmp(p, "pwsh") == 0) |
| 1078 | p_sp = (char_u *)">%s 2>&1"; |
| 1079 | else |
| 1080 | p_sp = (char_u *)"2>&1| tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1081 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1082 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1083 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1084 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1085 | if (do_srr) |
| 1086 | { |
| 1087 | p_srr = (char_u *)">%s 2>&1"; |
| 1088 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1089 | } |
| 1090 | } |
| 1091 | vim_free(p); |
| 1092 | } |
| 1093 | #endif |
| 1094 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1095 | #if defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1096 | /* |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1097 | * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the |
| 1098 | * 'shell' option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1099 | * This is done after other initializations, where 'shell' might have been |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1100 | * set, but only if they have not been set before. |
| 1101 | * Default values depend on shell (cmd.exe is default shell): |
| 1102 | * |
| 1103 | * p_shcf p_sxq |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 1104 | * cmd.exe - "/c" "(" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1105 | * powershell.exe - "-Command" "\"" |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1106 | * pwsh.exe - "-c" "\"" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1107 | * "sh" like shells - "-c" "\"" |
| 1108 | * |
| 1109 | * 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] | 1110 | */ |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1111 | if (strstr((char *)gettail(p_sh), "powershell") != NULL) |
| 1112 | { |
| 1113 | int idx_opt; |
| 1114 | |
| 1115 | idx_opt = findoption((char_u *)"shcf"); |
| 1116 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1117 | { |
| 1118 | p_shcf = (char_u*)"-Command"; |
| 1119 | options[idx_opt].def_val[VI_DEFAULT] = p_shcf; |
| 1120 | } |
| 1121 | |
| 1122 | idx_opt = findoption((char_u *)"sxq"); |
| 1123 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1124 | { |
| 1125 | p_sxq = (char_u*)"\""; |
| 1126 | options[idx_opt].def_val[VI_DEFAULT] = p_sxq; |
| 1127 | } |
| 1128 | } |
| 1129 | else if (strstr((char *)gettail(p_sh), "sh") != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1130 | { |
| 1131 | int idx3; |
| 1132 | |
| 1133 | idx3 = findoption((char_u *)"shcf"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1134 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1135 | { |
| 1136 | p_shcf = (char_u *)"-c"; |
| 1137 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1138 | } |
| 1139 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1140 | // Somehow Win32 requires the quotes around the redirection too |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1141 | idx3 = findoption((char_u *)"sxq"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1142 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1143 | { |
| 1144 | p_sxq = (char_u *)"\""; |
| 1145 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1146 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1147 | } |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1148 | else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL) |
| 1149 | { |
| 1150 | int idx3; |
| 1151 | |
| 1152 | /* |
| 1153 | * cmd.exe on Windows will strip the first and last double quote given |
| 1154 | * on the command line, e.g. most of the time things like: |
| 1155 | * cmd /c "my path/to/echo" "my args to echo" |
| 1156 | * become: |
| 1157 | * my path/to/echo" "my args to echo |
| 1158 | * when executed. |
| 1159 | * |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1160 | * To avoid this, set shellxquote to surround the command in |
| 1161 | * parenthesis. This appears to make most commands work, without |
| 1162 | * breaking commands that worked previously, such as |
| 1163 | * '"path with spaces/cmd" "a&b"'. |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1164 | */ |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1165 | idx3 = findoption((char_u *)"sxq"); |
| 1166 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1167 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1168 | p_sxq = (char_u *)"("; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1169 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1170 | } |
| 1171 | |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1172 | idx3 = findoption((char_u *)"shcf"); |
| 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_shcf = (char_u *)"/c"; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1176 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1177 | } |
| 1178 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1179 | #endif |
| 1180 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1181 | if (BUFEMPTY()) |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1182 | { |
| 1183 | int idx_ffs = findoption((char_u *)"ffs"); |
| 1184 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1185 | // Apply the first entry of 'fileformats' to the initial buffer. |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1186 | if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) |
| 1187 | set_fileformat(default_fileformat(), OPT_LOCAL); |
| 1188 | } |
| 1189 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1190 | set_title_defaults(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
| 1194 | /* |
| 1195 | * When 'helplang' is still at its default value, set it to "lang". |
| 1196 | * Only the first two characters of "lang" are used. |
| 1197 | */ |
| 1198 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1199 | set_helplang_default(char_u *lang) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1200 | { |
| 1201 | int idx; |
| 1202 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1203 | if (lang == NULL || STRLEN(lang) < 2) // safety check |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1204 | return; |
| 1205 | idx = findoption((char_u *)"hlg"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1206 | if (idx < 0 || (options[idx].flags & P_WAS_SET)) |
| 1207 | return; |
| 1208 | |
| 1209 | if (options[idx].flags & P_ALLOCED) |
| 1210 | free_string_option(p_hlg); |
| 1211 | p_hlg = vim_strsave(lang); |
| 1212 | if (p_hlg == NULL) |
| 1213 | p_hlg = empty_option; |
| 1214 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1215 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1216 | // zh_CN becomes "cn", zh_TW becomes "tw" |
| 1217 | if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1218 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1219 | p_hlg[0] = TOLOWER_ASC(p_hlg[3]); |
| 1220 | p_hlg[1] = TOLOWER_ASC(p_hlg[4]); |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1221 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1222 | // any C like setting, such as C.UTF-8, becomes "en" |
| 1223 | else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') |
| 1224 | { |
| 1225 | p_hlg[0] = 'e'; |
| 1226 | p_hlg[1] = 'n'; |
| 1227 | } |
| 1228 | p_hlg[2] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1229 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1230 | options[idx].flags |= P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1231 | } |
| 1232 | #endif |
| 1233 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1234 | /* |
| 1235 | * 'title' and 'icon' only default to true if they have not been set or reset |
| 1236 | * in .vimrc and we can read the old value. |
| 1237 | * When 'title' and 'icon' have been reset in .vimrc, we won't even check if |
| 1238 | * they can be reset. This reduces startup time when using X on a remote |
| 1239 | * machine. |
| 1240 | */ |
| 1241 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1242 | set_title_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1243 | { |
| 1244 | int idx1; |
| 1245 | long val; |
| 1246 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 1247 | // If GUI is (going to be) used, we can always set the window title and |
| 1248 | // icon name. Saves a bit of time, because the X11 display server does |
| 1249 | // not need to be contacted. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | idx1 = findoption((char_u *)"title"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1251 | if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1252 | { |
| 1253 | #ifdef FEAT_GUI |
| 1254 | if (gui.starting || gui.in_use) |
| 1255 | val = TRUE; |
| 1256 | else |
| 1257 | #endif |
| 1258 | val = mch_can_restore_title(); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1259 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1260 | p_title = val; |
| 1261 | } |
| 1262 | idx1 = findoption((char_u *)"icon"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1263 | if (idx1 < 0 || (options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1264 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1265 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1266 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1267 | |
| 1268 | #ifdef FEAT_GUI |
| 1269 | if (gui.starting || gui.in_use) |
| 1270 | val = TRUE; |
| 1271 | else |
| 1272 | #endif |
| 1273 | val = mch_can_restore_icon(); |
| 1274 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
| 1275 | p_icon = val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1276 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1277 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1278 | void |
| 1279 | ex_set(exarg_T *eap) |
| 1280 | { |
| 1281 | int flags = 0; |
| 1282 | |
| 1283 | if (eap->cmdidx == CMD_setlocal) |
| 1284 | flags = OPT_LOCAL; |
| 1285 | else if (eap->cmdidx == CMD_setglobal) |
| 1286 | flags = OPT_GLOBAL; |
| 1287 | #if defined(FEAT_EVAL) && defined(FEAT_BROWSE) |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 1288 | if ((cmdmod.cmod_flags & CMOD_BROWSE) && flags == 0) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1289 | ex_options(eap); |
| 1290 | else |
| 1291 | #endif |
| 1292 | { |
| 1293 | if (eap->forceit) |
| 1294 | flags |= OPT_ONECOLUMN; |
| 1295 | (void)do_set(eap->arg, flags); |
| 1296 | } |
| 1297 | } |
| 1298 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1299 | /* |
| 1300 | * :set operator types |
| 1301 | */ |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1302 | typedef enum { |
| 1303 | OP_NONE = 0, |
| 1304 | OP_ADDING, // "opt+=arg" |
| 1305 | OP_PREPENDING, // "opt^=arg" |
| 1306 | OP_REMOVING, // "opt-=arg" |
| 1307 | } set_op_T; |
| 1308 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1309 | typedef enum { |
| 1310 | PREFIX_NO = 0, // "no" prefix |
| 1311 | PREFIX_NONE, // no prefix |
| 1312 | PREFIX_INV, // "inv" prefix |
| 1313 | } set_prefix_T; |
| 1314 | |
| 1315 | /* |
| 1316 | * Return the prefix type for the option name in *argp. |
| 1317 | */ |
| 1318 | static set_prefix_T |
| 1319 | get_option_prefix(char_u **argp) |
| 1320 | { |
| 1321 | int prefix = PREFIX_NONE; |
| 1322 | char_u *arg = *argp; |
| 1323 | |
| 1324 | if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0) |
| 1325 | { |
| 1326 | prefix = PREFIX_NO; |
| 1327 | arg += 2; |
| 1328 | } |
| 1329 | else if (STRNCMP(arg, "inv", 3) == 0) |
| 1330 | { |
| 1331 | prefix = PREFIX_INV; |
| 1332 | arg += 3; |
| 1333 | } |
| 1334 | |
| 1335 | *argp = arg; |
| 1336 | return prefix; |
| 1337 | } |
| 1338 | |
| 1339 | /* |
| 1340 | * Parse the option name in "arg" and return the option index in "*opt_idxp", |
| 1341 | * and the option name length in "*lenp". For a <t_xx> option, return the key |
| 1342 | * number in "*keyp". |
| 1343 | * |
| 1344 | * Returns FAIL if an option starting with "<" doesn't end with a ">", |
| 1345 | * otherwise returns OK. |
| 1346 | */ |
| 1347 | static int |
| 1348 | parse_option_name(char_u *arg, int *opt_idxp, int *lenp, int *keyp) |
| 1349 | { |
| 1350 | int key = 0; |
| 1351 | int len; |
| 1352 | int opt_idx; |
| 1353 | |
| 1354 | if (*arg == '<') |
| 1355 | { |
| 1356 | opt_idx = -1; |
| 1357 | // look out for <t_>;> |
| 1358 | if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) |
| 1359 | len = 5; |
| 1360 | else |
| 1361 | { |
| 1362 | len = 1; |
| 1363 | while (arg[len] != NUL && arg[len] != '>') |
| 1364 | ++len; |
| 1365 | } |
| 1366 | if (arg[len] != '>') |
| 1367 | return FAIL; |
| 1368 | |
| 1369 | arg[len] = NUL; // put NUL after name |
| 1370 | if (arg[1] == 't' && arg[2] == '_') // could be term code |
| 1371 | opt_idx = findoption(arg + 1); |
| 1372 | arg[len++] = '>'; // restore '>' |
| 1373 | if (opt_idx == -1) |
| 1374 | key = find_key_option(arg + 1, TRUE); |
| 1375 | } |
| 1376 | else |
| 1377 | { |
| 1378 | int nextchar; // next non-white char after option name |
| 1379 | |
| 1380 | len = 0; |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 1381 | // The two characters after "t_" may not be alphanumeric. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1382 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 1383 | len = 4; |
| 1384 | else |
| 1385 | while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') |
| 1386 | ++len; |
| 1387 | nextchar = arg[len]; |
| 1388 | arg[len] = NUL; // put NUL after name |
| 1389 | opt_idx = findoption(arg); |
| 1390 | arg[len] = nextchar; // restore nextchar |
| 1391 | if (opt_idx == -1) |
| 1392 | key = find_key_option(arg, FALSE); |
| 1393 | } |
| 1394 | |
| 1395 | *keyp = key; |
| 1396 | *lenp = len; |
| 1397 | *opt_idxp = opt_idx; |
| 1398 | |
| 1399 | return OK; |
| 1400 | } |
| 1401 | |
| 1402 | /* |
| 1403 | * Get the option operator (+=, ^=, -=). |
| 1404 | */ |
| 1405 | static set_op_T |
| 1406 | get_opt_op(char_u *arg) |
| 1407 | { |
| 1408 | set_op_T op = OP_NONE; |
| 1409 | |
| 1410 | if (*arg != NUL && *(arg + 1) == '=') |
| 1411 | { |
| 1412 | if (*arg == '+') |
| 1413 | op = OP_ADDING; // "+=" |
| 1414 | else if (*arg == '^') |
| 1415 | op = OP_PREPENDING; // "^=" |
| 1416 | else if (*arg == '-') |
| 1417 | op = OP_REMOVING; // "-=" |
| 1418 | } |
| 1419 | |
| 1420 | return op; |
| 1421 | } |
| 1422 | |
| 1423 | /* |
| 1424 | * Validate whether the value of the option in "opt_idx" can be changed. |
| 1425 | * Returns FAIL if the option can be skipped or cannot be changed. Returns OK |
| 1426 | * if it can be changed. |
| 1427 | */ |
| 1428 | static int |
| 1429 | validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg) |
| 1430 | { |
| 1431 | // Skip all options that are not window-local (used when showing |
| 1432 | // an already loaded buffer in a window). |
| 1433 | if ((opt_flags & OPT_WINONLY) |
| 1434 | && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) |
| 1435 | return FAIL; |
| 1436 | |
| 1437 | // Skip all options that are window-local (used for :vimgrep). |
| 1438 | if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 |
| 1439 | && options[opt_idx].var == VAR_WIN) |
| 1440 | return FAIL; |
| 1441 | |
| 1442 | // Disallow changing some options from modelines. |
| 1443 | if (opt_flags & OPT_MODELINE) |
| 1444 | { |
| 1445 | if (flags & (P_SECURE | P_NO_ML)) |
| 1446 | { |
| 1447 | *errmsg = e_not_allowed_in_modeline; |
| 1448 | return FAIL; |
| 1449 | } |
| 1450 | if ((flags & P_MLE) && !p_mle) |
| 1451 | { |
| 1452 | *errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off; |
| 1453 | return FAIL; |
| 1454 | } |
| 1455 | #ifdef FEAT_DIFF |
| 1456 | // In diff mode some options are overruled. This avoids that |
| 1457 | // 'foldmethod' becomes "marker" instead of "diff" and that |
| 1458 | // "wrap" gets set. |
| 1459 | if (curwin->w_p_diff |
| 1460 | && opt_idx >= 0 // shut up coverity warning |
| 1461 | && ( |
| 1462 | # ifdef FEAT_FOLDING |
| 1463 | options[opt_idx].indir == PV_FDM || |
| 1464 | # endif |
| 1465 | options[opt_idx].indir == PV_WRAP)) |
| 1466 | return FAIL; |
| 1467 | #endif |
| 1468 | } |
| 1469 | |
| 1470 | #ifdef HAVE_SANDBOX |
| 1471 | // Disallow changing some options in the sandbox |
| 1472 | if (sandbox != 0 && (flags & P_SECURE)) |
| 1473 | { |
| 1474 | *errmsg = e_not_allowed_in_sandbox; |
| 1475 | return FAIL; |
| 1476 | } |
| 1477 | #endif |
| 1478 | |
| 1479 | return OK; |
| 1480 | } |
| 1481 | |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1482 | /* |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1483 | * Get the Vim/Vi default value for a string option. |
| 1484 | */ |
| 1485 | static char_u * |
| 1486 | stropt_get_default_val( |
| 1487 | int opt_idx, |
| 1488 | char_u *varp, |
| 1489 | int flags, |
| 1490 | int cp_val) |
| 1491 | { |
| 1492 | char_u *newval; |
| 1493 | |
| 1494 | newval = options[opt_idx].def_val[((flags & P_VI_DEF) || cp_val) |
| 1495 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1496 | if ((char_u **)varp == &p_bg) |
| 1497 | { |
| 1498 | // guess the value of 'background' |
| 1499 | #ifdef FEAT_GUI |
| 1500 | if (gui.in_use) |
| 1501 | newval = gui_bg_default(); |
| 1502 | else |
| 1503 | #endif |
| 1504 | newval = term_bg_default(); |
| 1505 | } |
| 1506 | else if ((char_u **)varp == &p_fencs && enc_utf8) |
| 1507 | newval = fencs_utf8_default; |
| 1508 | |
| 1509 | // expand environment variables and ~ since the default value was |
| 1510 | // already expanded, only required when an environment variable was set |
| 1511 | // later |
| 1512 | if (newval == NULL) |
| 1513 | newval = empty_option; |
| 1514 | else |
| 1515 | { |
| 1516 | char_u *s = option_expand(opt_idx, newval); |
| 1517 | if (s == NULL) |
| 1518 | s = newval; |
| 1519 | newval = vim_strsave(s); |
| 1520 | } |
| 1521 | |
| 1522 | return newval; |
| 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | * Convert the 'backspace' option number value to a string: for adding, |
| 1527 | * prepending and removing string. |
| 1528 | */ |
| 1529 | static void |
| 1530 | opt_backspace_nr2str( |
| 1531 | char_u *varp, |
| 1532 | char_u **origval_p, |
| 1533 | char_u **origval_l_p, |
| 1534 | char_u **origval_g_p, |
| 1535 | char_u **oldval_p) |
| 1536 | { |
| 1537 | int i = getdigits((char_u **)varp); |
| 1538 | |
| 1539 | switch (i) |
| 1540 | { |
| 1541 | case 0: |
| 1542 | *(char_u **)varp = empty_option; |
| 1543 | break; |
| 1544 | case 1: |
| 1545 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); |
| 1546 | break; |
| 1547 | case 2: |
| 1548 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start"); |
| 1549 | break; |
| 1550 | case 3: |
| 1551 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop"); |
| 1552 | break; |
| 1553 | } |
| 1554 | vim_free(*oldval_p); |
| 1555 | if (*origval_p == *oldval_p) |
| 1556 | *origval_p = *(char_u **)varp; |
| 1557 | if (*origval_l_p == *oldval_p) |
| 1558 | *origval_l_p = *(char_u **)varp; |
| 1559 | if (*origval_g_p == *oldval_p) |
| 1560 | *origval_g_p = *(char_u **)varp; |
| 1561 | *oldval_p = *(char_u **)varp; |
| 1562 | } |
| 1563 | |
| 1564 | /* |
| 1565 | * Convert the 'whichwrap' option number value to a string, for backwards |
| 1566 | * compatibility with Vim 3.0. |
| 1567 | * Note: 'argp' is a pointer to a char_u pointer and is updated. |
| 1568 | */ |
| 1569 | static char_u * |
| 1570 | opt_whichwrap_nr2str(char_u **argp, char_u *whichwrap) |
| 1571 | { |
| 1572 | *whichwrap = NUL; |
| 1573 | int i = getdigits(argp); |
| 1574 | if (i & 1) |
| 1575 | STRCAT(whichwrap, "b,"); |
| 1576 | if (i & 2) |
| 1577 | STRCAT(whichwrap, "s,"); |
| 1578 | if (i & 4) |
| 1579 | STRCAT(whichwrap, "h,l,"); |
| 1580 | if (i & 8) |
| 1581 | STRCAT(whichwrap, "<,>,"); |
| 1582 | if (i & 16) |
| 1583 | STRCAT(whichwrap, "[,],"); |
| 1584 | if (*whichwrap != NUL) // remove trailing , |
| 1585 | whichwrap[STRLEN(whichwrap) - 1] = NUL; |
| 1586 | |
| 1587 | return whichwrap; |
| 1588 | } |
| 1589 | |
| 1590 | /* |
| 1591 | * Copy the new string value into allocated memory for the option. |
| 1592 | * Can't use set_string_option_direct(), because we need to remove the |
| 1593 | * backslashes. |
| 1594 | */ |
| 1595 | static char_u * |
| 1596 | stropt_copy_value( |
| 1597 | char_u *origval, |
| 1598 | char_u **argp, |
| 1599 | set_op_T op, |
| 1600 | int flags UNUSED) |
| 1601 | { |
| 1602 | char_u *arg = *argp; |
| 1603 | unsigned newlen; |
| 1604 | char_u *newval; |
| 1605 | char_u *s = NULL; |
| 1606 | |
| 1607 | // get a bit too much |
| 1608 | newlen = (unsigned)STRLEN(arg) + 1; |
| 1609 | if (op != OP_NONE) |
| 1610 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1611 | newval = alloc(newlen); |
| 1612 | if (newval == NULL) // out of mem, don't change |
| 1613 | return NULL; |
| 1614 | s = newval; |
| 1615 | |
| 1616 | // Copy the string, skip over escaped chars. |
| 1617 | // For MS-DOS and WIN32 backslashes before normal file name characters |
| 1618 | // are not removed, and keep backslash at start, for "\\machine\path", |
| 1619 | // but do remove it for "\\\\machine\\path". |
| 1620 | // The reverse is found in ExpandOldSetting(). |
| 1621 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
| 1622 | { |
| 1623 | int i; |
| 1624 | |
| 1625 | if (*arg == '\\' && arg[1] != NUL |
| 1626 | #ifdef BACKSLASH_IN_FILENAME |
| 1627 | && !((flags & P_EXPAND) |
| 1628 | && vim_isfilec(arg[1]) |
| 1629 | && !VIM_ISWHITE(arg[1]) |
| 1630 | && (arg[1] != '\\' |
| 1631 | || (s == newval && arg[2] != '\\'))) |
| 1632 | #endif |
| 1633 | ) |
| 1634 | ++arg; // remove backslash |
| 1635 | if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) |
| 1636 | { |
| 1637 | // copy multibyte char |
| 1638 | mch_memmove(s, arg, (size_t)i); |
| 1639 | arg += i; |
| 1640 | s += i; |
| 1641 | } |
| 1642 | else |
| 1643 | *s++ = *arg++; |
| 1644 | } |
| 1645 | *s = NUL; |
| 1646 | |
| 1647 | *argp = arg; |
| 1648 | return newval; |
| 1649 | } |
| 1650 | |
| 1651 | /* |
| 1652 | * Expand environment variables and ~ in string option value 'newval'. |
| 1653 | */ |
| 1654 | static char_u * |
| 1655 | stropt_expand_envvar( |
| 1656 | int opt_idx, |
| 1657 | char_u *origval, |
| 1658 | char_u *newval, |
| 1659 | set_op_T op) |
| 1660 | { |
| 1661 | char_u *s = option_expand(opt_idx, newval); |
| 1662 | if (s == NULL) |
| 1663 | return newval; |
| 1664 | |
| 1665 | vim_free(newval); |
| 1666 | unsigned newlen = (unsigned)STRLEN(s) + 1; |
| 1667 | if (op != OP_NONE) |
| 1668 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1669 | |
| 1670 | newval = alloc(newlen); |
| 1671 | if (newval == NULL) |
| 1672 | return NULL; |
| 1673 | |
| 1674 | STRCPY(newval, s); |
| 1675 | |
| 1676 | return newval; |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Concatenate the original and new values of a string option, adding a "," if |
| 1681 | * needed. |
| 1682 | */ |
| 1683 | static void |
| 1684 | stropt_concat_with_comma( |
| 1685 | char_u *origval, |
| 1686 | char_u *newval, |
| 1687 | set_op_T op, |
| 1688 | int flags) |
| 1689 | { |
| 1690 | int len = 0; |
| 1691 | |
| 1692 | int comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); |
| 1693 | if (op == OP_ADDING) |
| 1694 | { |
| 1695 | len = (int)STRLEN(origval); |
| 1696 | // strip a trailing comma, would get 2 |
| 1697 | if (comma && len > 1 |
| 1698 | && (flags & P_ONECOMMA) == P_ONECOMMA |
| 1699 | && origval[len - 1] == ',' |
| 1700 | && origval[len - 2] != '\\') |
| 1701 | len--; |
| 1702 | mch_memmove(newval + len + comma, newval, STRLEN(newval) + 1); |
| 1703 | mch_memmove(newval, origval, (size_t)len); |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | len = (int)STRLEN(newval); |
| 1708 | STRMOVE(newval + len + comma, origval); |
| 1709 | } |
| 1710 | if (comma) |
| 1711 | newval[len] = ','; |
| 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * Remove a value from a string option. Copy string option value in "origval" |
| 1716 | * to "newval" and then remove the string "strval" of length "len". |
| 1717 | */ |
| 1718 | static void |
| 1719 | stropt_remove_val( |
| 1720 | char_u *origval, |
| 1721 | char_u *newval, |
| 1722 | int flags, |
| 1723 | char_u *strval, |
| 1724 | int len) |
| 1725 | { |
| 1726 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1727 | // and is used here). |
| 1728 | STRCPY(newval, origval); |
| 1729 | if (*strval) |
| 1730 | { |
| 1731 | // may need to remove a comma |
| 1732 | if (flags & P_COMMA) |
| 1733 | { |
| 1734 | if (strval == origval) |
| 1735 | { |
| 1736 | // include comma after string |
| 1737 | if (strval[len] == ',') |
| 1738 | ++len; |
| 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | // include comma before string |
| 1743 | --strval; |
| 1744 | ++len; |
| 1745 | } |
| 1746 | } |
| 1747 | STRMOVE(newval + (strval - origval), strval + len); |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | /* |
| 1752 | * Remove flags that appear twice in the string option value 'newval'. |
| 1753 | */ |
| 1754 | static void |
| 1755 | stropt_remove_dupflags(char_u *newval, int flags) |
| 1756 | { |
| 1757 | char_u *s = newval; |
| 1758 | |
| 1759 | // Remove flags that appear twice. |
| 1760 | while (*s) |
| 1761 | { |
| 1762 | // if options have P_FLAGLIST and P_ONECOMMA such as 'whichwrap' |
| 1763 | if (flags & P_ONECOMMA) |
| 1764 | { |
| 1765 | if (*s != ',' && *(s + 1) == ',' && vim_strchr(s + 2, *s) != NULL) |
| 1766 | { |
| 1767 | // Remove the duplicated value and the next comma. |
| 1768 | STRMOVE(s, s + 2); |
| 1769 | continue; |
| 1770 | } |
| 1771 | } |
| 1772 | else |
| 1773 | { |
| 1774 | if ((!(flags & P_COMMA) || *s != ',') |
| 1775 | && vim_strchr(s + 1, *s) != NULL) |
| 1776 | { |
| 1777 | STRMOVE(s, s + 1); |
| 1778 | continue; |
| 1779 | } |
| 1780 | } |
| 1781 | ++s; |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | /* |
| 1786 | * Get the string value specified for a ":set" command. The following set |
| 1787 | * options are supported: |
| 1788 | * set {opt}& |
| 1789 | * set {opt}< |
| 1790 | * set {opt}={val} |
| 1791 | * set {opt}:{val} |
| 1792 | */ |
| 1793 | static char_u * |
| 1794 | stropt_get_newval( |
| 1795 | int nextchar, |
| 1796 | int opt_idx, |
| 1797 | char_u **argp, |
| 1798 | char_u *varp, |
| 1799 | char_u **origval_arg, |
| 1800 | char_u **origval_l_arg, |
| 1801 | char_u **origval_g_arg, |
| 1802 | char_u **oldval_arg, |
| 1803 | set_op_T *op_arg, |
| 1804 | int flags, |
| 1805 | int cp_val) |
| 1806 | { |
| 1807 | char_u *arg = *argp; |
| 1808 | char_u *origval = *origval_arg; |
| 1809 | char_u *origval_l = *origval_l_arg; |
| 1810 | char_u *origval_g = *origval_g_arg; |
| 1811 | char_u *oldval = *oldval_arg; |
| 1812 | set_op_T op = *op_arg; |
| 1813 | char_u *save_arg = NULL; |
| 1814 | char_u *newval; |
| 1815 | char_u *s = NULL; |
| 1816 | char_u whichwrap[80]; |
| 1817 | |
| 1818 | if (nextchar == '&') // set to default val |
| 1819 | newval = stropt_get_default_val(opt_idx, varp, flags, cp_val); |
| 1820 | else if (nextchar == '<') // set to global val |
| 1821 | newval = vim_strsave(*(char_u **)get_varp_scope( |
| 1822 | &(options[opt_idx]), OPT_GLOBAL)); |
| 1823 | else |
| 1824 | { |
| 1825 | ++arg; // jump to after the '=' or ':' |
| 1826 | |
| 1827 | // Set 'keywordprg' to ":help" if an empty |
| 1828 | // value was passed to :set by the user. |
| 1829 | if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' ')) |
| 1830 | { |
| 1831 | save_arg = arg; |
| 1832 | arg = (char_u *)":help"; |
| 1833 | } |
| 1834 | // Convert 'backspace' number to string |
| 1835 | else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) |
| 1836 | opt_backspace_nr2str(varp, &origval, &origval_l, &origval_g, |
| 1837 | &oldval); |
| 1838 | else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) |
| 1839 | { |
| 1840 | // Convert 'whichwrap' number to string, for backwards |
| 1841 | // compatibility with Vim 3.0. |
| 1842 | char_u *t = opt_whichwrap_nr2str(&arg, whichwrap); |
| 1843 | save_arg = arg; |
| 1844 | arg = t; |
| 1845 | } |
| 1846 | // Remove '>' before 'dir' and 'bdir', for backwards compatibility with |
| 1847 | // version 3.0 |
| 1848 | else if (*arg == '>' && (varp == (char_u *)&p_dir |
| 1849 | || varp == (char_u *)&p_bdir)) |
| 1850 | ++arg; |
| 1851 | |
| 1852 | // Copy the new string into allocated memory. |
| 1853 | newval = stropt_copy_value(origval, &arg, op, flags); |
| 1854 | if (newval == NULL) |
| 1855 | goto done; |
| 1856 | |
| 1857 | // Expand environment variables and ~. |
| 1858 | // Don't do it when adding without inserting a comma. |
| 1859 | if (op == OP_NONE || (flags & P_COMMA)) |
| 1860 | { |
| 1861 | newval = stropt_expand_envvar(opt_idx, origval, newval, op); |
| 1862 | if (newval == NULL) |
| 1863 | goto done; |
| 1864 | } |
| 1865 | |
| 1866 | // locate newval[] in origval[] when removing it and when adding to |
| 1867 | // avoid duplicates |
| 1868 | int len = 0; |
| 1869 | if (op == OP_REMOVING || (flags & P_NODUP)) |
| 1870 | { |
| 1871 | len = (int)STRLEN(newval); |
| 1872 | s = find_dup_item(origval, newval, flags); |
| 1873 | |
| 1874 | // do not add if already there |
| 1875 | if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) |
| 1876 | { |
| 1877 | op = OP_NONE; |
| 1878 | STRCPY(newval, origval); |
| 1879 | } |
| 1880 | |
| 1881 | // if no duplicate, move pointer to end of original value |
| 1882 | if (s == NULL) |
| 1883 | s = origval + (int)STRLEN(origval); |
| 1884 | } |
| 1885 | |
| 1886 | // concatenate the two strings; add a ',' if needed |
| 1887 | if (op == OP_ADDING || op == OP_PREPENDING) |
| 1888 | stropt_concat_with_comma(origval, newval, op, flags); |
| 1889 | else if (op == OP_REMOVING) |
| 1890 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1891 | // and is used here). |
| 1892 | stropt_remove_val(origval, newval, flags, s, len); |
| 1893 | |
| 1894 | if (flags & P_FLAGLIST) |
| 1895 | // Remove flags that appear twice. |
| 1896 | stropt_remove_dupflags(newval, flags); |
| 1897 | } |
| 1898 | |
| 1899 | done: |
| 1900 | if (save_arg != NULL) |
| 1901 | arg = save_arg; // arg was temporarily changed, restore it |
| 1902 | *argp = arg; |
| 1903 | *origval_arg = origval; |
| 1904 | *origval_l_arg = origval_l; |
| 1905 | *origval_g_arg = origval_g; |
| 1906 | *oldval_arg = oldval; |
| 1907 | *op_arg = op; |
| 1908 | |
| 1909 | return newval; |
| 1910 | } |
| 1911 | |
| 1912 | /* |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1913 | * Part of do_set() for string options. |
| 1914 | * Returns FAIL on failure, do not process further options. |
| 1915 | */ |
| 1916 | static int |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1917 | do_set_option_string( |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1918 | int opt_idx, |
| 1919 | int opt_flags, |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1920 | char_u **argp, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1921 | int nextchar, |
| 1922 | set_op_T op_arg, |
| 1923 | int flags, |
| 1924 | int cp_val, |
| 1925 | char_u *varp_arg, |
| 1926 | char *errbuf, |
| 1927 | int *value_checked, |
| 1928 | char **errmsg) |
| 1929 | { |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1930 | char_u *arg = *argp; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1931 | set_op_T op = op_arg; |
| 1932 | char_u *varp = varp_arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1933 | char_u *oldval = NULL; // previous value if *varp |
| 1934 | char_u *newval; |
| 1935 | char_u *origval = NULL; |
| 1936 | char_u *origval_l = NULL; |
| 1937 | char_u *origval_g = NULL; |
| 1938 | #if defined(FEAT_EVAL) |
| 1939 | char_u *saved_origval = NULL; |
| 1940 | char_u *saved_origval_l = NULL; |
| 1941 | char_u *saved_origval_g = NULL; |
| 1942 | char_u *saved_newval = NULL; |
| 1943 | #endif |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1944 | |
| 1945 | // When using ":set opt=val" for a global option |
| 1946 | // with a local value the local value will be |
| 1947 | // reset, use the global value here. |
| 1948 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
| 1949 | && ((int)options[opt_idx].indir & PV_BOTH)) |
| 1950 | varp = options[opt_idx].var; |
| 1951 | |
| 1952 | // The old value is kept until we are sure that the new value is valid. |
| 1953 | oldval = *(char_u **)varp; |
| 1954 | |
| 1955 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 1956 | { |
| 1957 | origval_l = *(char_u **)get_varp_scope( |
| 1958 | &(options[opt_idx]), OPT_LOCAL); |
| 1959 | origval_g = *(char_u **)get_varp_scope( |
| 1960 | &(options[opt_idx]), OPT_GLOBAL); |
| 1961 | |
| 1962 | // A global-local string option might have an empty option as value to |
| 1963 | // indicate that the global value should be used. |
| 1964 | if (((int)options[opt_idx].indir & PV_BOTH) |
| 1965 | && origval_l == empty_option) |
| 1966 | origval_l = origval_g; |
| 1967 | } |
| 1968 | |
| 1969 | // When setting the local value of a global option, the old value may be |
| 1970 | // the global value. |
| 1971 | if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) |
| 1972 | origval = *(char_u **)get_varp(&options[opt_idx]); |
| 1973 | else |
| 1974 | origval = oldval; |
| 1975 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1976 | // Get the new value for the option |
| 1977 | newval = stropt_get_newval(nextchar, opt_idx, &arg, varp, &origval, |
| 1978 | &origval_l, &origval_g, &oldval, &op, flags, |
| 1979 | cp_val); |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1980 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1981 | // Set the new value. |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1982 | *(char_u **)(varp) = newval; |
Bram Moolenaar | 339e114 | 2023-02-15 14:26:25 +0000 | [diff] [blame] | 1983 | if (newval == NULL) |
| 1984 | *(char_u **)(varp) = empty_option; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1985 | |
| 1986 | #if defined(FEAT_EVAL) |
| 1987 | if (!starting |
| 1988 | # ifdef FEAT_CRYPT |
| 1989 | && options[opt_idx].indir != PV_KEY |
| 1990 | # endif |
| 1991 | && origval != NULL && newval != NULL) |
| 1992 | { |
| 1993 | // origval may be freed by did_set_string_option(), make a copy. |
| 1994 | saved_origval = vim_strsave(origval); |
| 1995 | // newval (and varp) may become invalid if the buffer is closed by |
| 1996 | // autocommands. |
| 1997 | saved_newval = vim_strsave(newval); |
| 1998 | if (origval_l != NULL) |
| 1999 | saved_origval_l = vim_strsave(origval_l); |
| 2000 | if (origval_g != NULL) |
| 2001 | saved_origval_g = vim_strsave(origval_g); |
| 2002 | } |
| 2003 | #endif |
| 2004 | |
| 2005 | { |
| 2006 | long_u *p = insecure_flag(opt_idx, opt_flags); |
| 2007 | int secure_saved = secure; |
| 2008 | |
| 2009 | // When an option is set in the sandbox, from a modeline or in secure |
| 2010 | // mode, then deal with side effects in secure mode. Also when the |
| 2011 | // value was set with the P_INSECURE flag and is not completely |
| 2012 | // replaced. |
| 2013 | if ((opt_flags & OPT_MODELINE) |
| 2014 | #ifdef HAVE_SANDBOX |
| 2015 | || sandbox != 0 |
| 2016 | #endif |
| 2017 | || (op != OP_NONE && (*p & P_INSECURE))) |
| 2018 | secure = 1; |
| 2019 | |
| 2020 | // Handle side effects, and set the global value for ":set" on local |
| 2021 | // options. Note: when setting 'syntax' or 'filetype' autocommands may |
| 2022 | // be triggered that can cause havoc. |
| 2023 | *errmsg = did_set_string_option( |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2024 | opt_idx, (char_u **)varp, oldval, newval, errbuf, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2025 | opt_flags, value_checked); |
| 2026 | |
| 2027 | secure = secure_saved; |
| 2028 | } |
| 2029 | |
| 2030 | #if defined(FEAT_EVAL) |
| 2031 | if (*errmsg == NULL) |
zeertzjq | 269aa2b | 2022-11-28 11:36:50 +0000 | [diff] [blame] | 2032 | trigger_optionset_string(opt_idx, opt_flags, saved_origval, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2033 | saved_origval_l, saved_origval_g, saved_newval); |
| 2034 | vim_free(saved_origval); |
| 2035 | vim_free(saved_origval_l); |
| 2036 | vim_free(saved_origval_g); |
| 2037 | vim_free(saved_newval); |
| 2038 | #endif |
| 2039 | |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 2040 | *argp = arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2041 | return *errmsg == NULL ? OK : FAIL; |
| 2042 | } |
| 2043 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2044 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2045 | * Set a boolean option. |
| 2046 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2047 | */ |
| 2048 | static char * |
| 2049 | do_set_option_bool( |
| 2050 | int opt_idx, |
| 2051 | int opt_flags, |
| 2052 | set_prefix_T prefix, |
| 2053 | long_u flags, |
| 2054 | char_u *varp, |
| 2055 | int nextchar, |
| 2056 | int afterchar, |
| 2057 | int cp_val) |
| 2058 | |
| 2059 | { |
| 2060 | varnumber_T value; |
| 2061 | |
| 2062 | if (nextchar == '=' || nextchar == ':') |
| 2063 | return e_invalid_argument; |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2064 | if (opt_idx < 0 || varp == NULL) |
| 2065 | return NULL; // "cannot happen" |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2066 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2067 | // ":set opt!": invert |
| 2068 | // ":set opt&": reset to default value |
| 2069 | // ":set opt<": reset to global value |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2070 | if (nextchar == '!') |
| 2071 | value = *(int *)(varp) ^ 1; |
| 2072 | else if (nextchar == '&') |
| 2073 | value = (int)(long)(long_i)options[opt_idx].def_val[ |
| 2074 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2075 | else if (nextchar == '<') |
| 2076 | { |
| 2077 | // For 'autoread' -1 means to use global value. |
| 2078 | if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL) |
| 2079 | value = -1; |
| 2080 | else |
| 2081 | value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2082 | } |
| 2083 | else |
| 2084 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2085 | // ":set invopt": invert |
| 2086 | // ":set opt" or ":set noopt": set or reset |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2087 | if (nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2088 | return e_trailing_characters; |
| 2089 | if (prefix == PREFIX_INV) |
| 2090 | value = *(int *)(varp) ^ 1; |
| 2091 | else |
| 2092 | value = prefix == PREFIX_NO ? 0 : 1; |
| 2093 | } |
| 2094 | |
| 2095 | return set_bool_option(opt_idx, varp, (int)value, opt_flags); |
| 2096 | } |
| 2097 | |
| 2098 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2099 | * Set a numeric option. |
| 2100 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2101 | */ |
| 2102 | static char * |
| 2103 | do_set_option_numeric( |
| 2104 | int opt_idx, |
| 2105 | int opt_flags, |
| 2106 | char_u **argp, |
| 2107 | int nextchar, |
| 2108 | set_op_T op, |
| 2109 | long_u flags, |
| 2110 | int cp_val, |
| 2111 | char_u *varp, |
| 2112 | char *errbuf, |
| 2113 | size_t errbuflen) |
| 2114 | { |
| 2115 | char_u *arg = *argp; |
| 2116 | varnumber_T value; |
| 2117 | int i; |
| 2118 | char *errmsg = NULL; |
| 2119 | |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2120 | if (opt_idx < 0 || varp == NULL) |
| 2121 | return NULL; // "cannot happen" |
| 2122 | // |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2123 | /* |
| 2124 | * Different ways to set a number option: |
| 2125 | * & set to default value |
| 2126 | * < set to global value |
| 2127 | * <xx> accept special key codes for 'wildchar' |
| 2128 | * c accept any non-digit for 'wildchar' |
| 2129 | * [-]0-9 set number |
| 2130 | * other error |
| 2131 | */ |
| 2132 | ++arg; |
| 2133 | if (nextchar == '&') |
| 2134 | value = (long)(long_i)options[opt_idx].def_val[ |
| 2135 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2136 | else if (nextchar == '<') |
| 2137 | { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2138 | if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 2139 | // for 'undolevels' NO_LOCAL_UNDOLEVEL means using the global value |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2140 | value = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 2141 | else if (opt_flags == OPT_LOCAL |
| 2142 | && ((long *)varp == &curwin->w_p_siso |
| 2143 | || (long *)varp == &curwin->w_p_so)) |
| 2144 | // for 'scrolloff'/'sidescrolloff' -1 means using the global value |
| 2145 | value = -1; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2146 | else |
| 2147 | value = *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2148 | } |
| 2149 | else if (((long *)varp == &p_wc || (long *)varp == &p_wcm) |
| 2150 | && (*arg == '<' |
| 2151 | || *arg == '^' |
| 2152 | || (*arg != NUL |
| 2153 | && (!arg[1] || VIM_ISWHITE(arg[1])) |
| 2154 | && !VIM_ISDIGIT(*arg)))) |
| 2155 | { |
| 2156 | value = string_to_key(arg, FALSE); |
| 2157 | if (value == 0 && (long *)varp != &p_wcm) |
| 2158 | { |
| 2159 | errmsg = e_invalid_argument; |
| 2160 | goto skip; |
| 2161 | } |
| 2162 | } |
| 2163 | else if (*arg == '-' || VIM_ISDIGIT(*arg)) |
| 2164 | { |
| 2165 | // Allow negative (for 'undolevels'), octal and hex numbers. |
Bram Moolenaar | 5fb78c3 | 2023-03-04 20:47:39 +0000 | [diff] [blame] | 2166 | vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, TRUE, NULL); |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2167 | if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i]))) |
| 2168 | { |
| 2169 | errmsg = e_number_required_after_equal; |
| 2170 | goto skip; |
| 2171 | } |
| 2172 | } |
| 2173 | else |
| 2174 | { |
| 2175 | errmsg = e_number_required_after_equal; |
| 2176 | goto skip; |
| 2177 | } |
| 2178 | |
| 2179 | if (op == OP_ADDING) |
| 2180 | value = *(long *)varp + value; |
| 2181 | else if (op == OP_PREPENDING) |
| 2182 | value = *(long *)varp * value; |
| 2183 | else if (op == OP_REMOVING) |
| 2184 | value = *(long *)varp - value; |
| 2185 | |
| 2186 | errmsg = set_num_option(opt_idx, varp, value, errbuf, errbuflen, |
| 2187 | opt_flags); |
| 2188 | |
| 2189 | skip: |
| 2190 | *argp = arg; |
| 2191 | return errmsg; |
| 2192 | } |
| 2193 | |
| 2194 | /* |
| 2195 | * Set a key code (t_xx) option |
| 2196 | */ |
| 2197 | static char * |
| 2198 | do_set_option_keycode(char_u **argp, char_u *key_name, int nextchar) |
| 2199 | { |
| 2200 | char_u *arg = *argp; |
| 2201 | char_u *p; |
| 2202 | |
| 2203 | if (nextchar == '&') |
| 2204 | { |
| 2205 | if (add_termcap_entry(key_name, TRUE) == FAIL) |
| 2206 | return e_not_found_in_termcap; |
| 2207 | } |
| 2208 | else |
| 2209 | { |
| 2210 | ++arg; // jump to after the '=' or ':' |
| 2211 | for (p = arg; *p && !VIM_ISWHITE(*p); ++p) |
| 2212 | if (*p == '\\' && p[1] != NUL) |
| 2213 | ++p; |
| 2214 | nextchar = *p; |
| 2215 | *p = NUL; |
| 2216 | add_termcode(key_name, arg, FALSE); |
| 2217 | *p = nextchar; |
| 2218 | } |
| 2219 | if (full_screen) |
| 2220 | ttest(FALSE); |
| 2221 | redraw_all_later(UPD_CLEAR); |
| 2222 | |
| 2223 | *argp = arg; |
| 2224 | return NULL; |
| 2225 | } |
| 2226 | |
| 2227 | /* |
| 2228 | * Set an option to a new value. |
| 2229 | */ |
| 2230 | static char * |
| 2231 | do_set_option_value( |
| 2232 | int opt_idx, |
| 2233 | int opt_flags, |
| 2234 | char_u **argp, |
| 2235 | set_prefix_T prefix, |
| 2236 | set_op_T op, |
| 2237 | long_u flags, |
| 2238 | char_u *varp, |
| 2239 | char_u *key_name, |
| 2240 | int nextchar, |
| 2241 | int afterchar, |
| 2242 | int cp_val, |
| 2243 | int *stopopteval, |
| 2244 | char *errbuf, |
| 2245 | size_t errbuflen) |
| 2246 | { |
| 2247 | int value_checked = FALSE; |
| 2248 | char *errmsg = NULL; |
| 2249 | char_u *arg = *argp; |
| 2250 | |
| 2251 | if (flags & P_BOOL) |
| 2252 | { |
| 2253 | // boolean option |
| 2254 | errmsg = do_set_option_bool(opt_idx, opt_flags, prefix, flags, varp, |
| 2255 | nextchar, afterchar, cp_val); |
| 2256 | if (errmsg != NULL) |
| 2257 | goto skip; |
| 2258 | } |
| 2259 | else |
| 2260 | { |
| 2261 | // numeric or string option |
| 2262 | if (vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2263 | || prefix != PREFIX_NONE) |
| 2264 | { |
| 2265 | errmsg = e_invalid_argument; |
| 2266 | goto skip; |
| 2267 | } |
| 2268 | |
| 2269 | if (flags & P_NUM) |
| 2270 | { |
| 2271 | // numeric option |
| 2272 | errmsg = do_set_option_numeric(opt_idx, opt_flags, &arg, nextchar, |
| 2273 | op, flags, cp_val, varp, |
| 2274 | errbuf, errbuflen); |
| 2275 | if (errmsg != NULL) |
| 2276 | goto skip; |
| 2277 | } |
| 2278 | else if (opt_idx >= 0) |
| 2279 | { |
| 2280 | // string option |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 2281 | if (do_set_option_string(opt_idx, opt_flags, &arg, nextchar, op, |
| 2282 | flags, cp_val, varp, errbuf, |
| 2283 | &value_checked, &errmsg) == FAIL) |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2284 | { |
| 2285 | if (errmsg != NULL) |
| 2286 | goto skip; |
| 2287 | *stopopteval = TRUE; |
| 2288 | goto skip; |
| 2289 | } |
| 2290 | } |
| 2291 | else |
| 2292 | { |
| 2293 | // key code option |
| 2294 | errmsg = do_set_option_keycode(&arg, key_name, nextchar); |
| 2295 | if (errmsg != NULL) |
| 2296 | goto skip; |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | if (opt_idx >= 0) |
| 2301 | did_set_option(opt_idx, opt_flags, op == OP_NONE, value_checked); |
| 2302 | |
| 2303 | skip: |
| 2304 | *argp = arg; |
| 2305 | return errmsg; |
| 2306 | } |
| 2307 | |
| 2308 | /* |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2309 | * Set an option to a new value. |
| 2310 | * Return NULL if OK, return an untranslated error message when something is |
| 2311 | * wrong. "errbuf[errbuflen]" can be used to create the error message. |
| 2312 | */ |
| 2313 | static char * |
| 2314 | do_set_option( |
| 2315 | int opt_flags, |
| 2316 | char_u **argp, |
| 2317 | char_u *arg_start, |
| 2318 | char_u **startarg, |
| 2319 | int *did_show, |
| 2320 | int *stopopteval, |
| 2321 | char *errbuf, |
| 2322 | size_t errbuflen) |
| 2323 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2324 | int opt_idx; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2325 | char_u *arg; |
| 2326 | set_prefix_T prefix; // no prefix, "no" prefix or "inv" prefix |
| 2327 | set_op_T op; |
| 2328 | long_u flags; // flags for current option |
| 2329 | char_u *varp; // pointer to variable for current option |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2330 | char_u key_name[2]; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2331 | int nextchar; // next non-white char after option name |
| 2332 | int afterchar; // character just after option name |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2333 | char *errmsg = NULL; |
| 2334 | int key; |
| 2335 | int len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2336 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2337 | prefix = get_option_prefix(argp); |
| 2338 | arg = *argp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2339 | |
| 2340 | // find end of name |
| 2341 | key = 0; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2342 | if (parse_option_name(arg, &opt_idx, &len, &key) == FAIL) |
| 2343 | return e_invalid_argument; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2344 | |
| 2345 | // remember character after option name |
| 2346 | afterchar = arg[len]; |
| 2347 | |
| 2348 | if (in_vim9script()) |
| 2349 | { |
| 2350 | char_u *p = skipwhite(arg + len); |
| 2351 | |
| 2352 | // disallow white space before =val, +=val, -=val, ^=val |
| 2353 | if (p > arg + len && (p[0] == '=' |
| 2354 | || (vim_strchr((char_u *)"+-^", p[0]) != NULL |
| 2355 | && p[1] == '='))) |
| 2356 | { |
| 2357 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2358 | arg = p; |
| 2359 | *startarg = p; |
| 2360 | goto skip; |
| 2361 | } |
| 2362 | } |
| 2363 | else |
| 2364 | // skip white space, allow ":set ai ?", ":set hlsearch !" |
| 2365 | while (VIM_ISWHITE(arg[len])) |
| 2366 | ++len; |
| 2367 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2368 | op = get_opt_op(arg + len); |
| 2369 | if (op != OP_NONE) |
| 2370 | len++; |
| 2371 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2372 | nextchar = arg[len]; |
| 2373 | |
| 2374 | if (opt_idx == -1 && key == 0) // found a mismatch: skip |
| 2375 | { |
| 2376 | if (in_vim9script() && arg > arg_start |
| 2377 | && vim_strchr((char_u *)"!&<", *arg) != NULL) |
| 2378 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2379 | else |
| 2380 | errmsg = e_unknown_option; |
| 2381 | goto skip; |
| 2382 | } |
| 2383 | |
| 2384 | if (opt_idx >= 0) |
| 2385 | { |
| 2386 | if (options[opt_idx].var == NULL) // hidden option: skip |
| 2387 | { |
| 2388 | // Only give an error message when requesting the value of |
| 2389 | // a hidden option, ignore setting it. |
| 2390 | if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL |
| 2391 | && (!(options[opt_idx].flags & P_BOOL) |
| 2392 | || nextchar == '?')) |
| 2393 | errmsg = e_option_not_supported; |
| 2394 | goto skip; |
| 2395 | } |
| 2396 | |
| 2397 | flags = options[opt_idx].flags; |
| 2398 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 2399 | } |
| 2400 | else |
| 2401 | { |
| 2402 | flags = P_STRING; |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2403 | varp = NULL; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2404 | if (key < 0) |
| 2405 | { |
| 2406 | key_name[0] = KEY2TERMCAP0(key); |
| 2407 | key_name[1] = KEY2TERMCAP1(key); |
| 2408 | } |
| 2409 | else |
| 2410 | { |
| 2411 | key_name[0] = KS_KEY; |
| 2412 | key_name[1] = (key & 0xff); |
| 2413 | } |
| 2414 | } |
| 2415 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2416 | // Make sure the option value can be changed. |
| 2417 | if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg) == FAIL) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2418 | goto skip; |
| 2419 | |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2420 | int cp_val = p_cp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2421 | if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) |
| 2422 | { |
| 2423 | arg += len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2424 | if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') |
| 2425 | { |
| 2426 | if (arg[3] == 'm') // "opt&vim": set to Vim default |
| 2427 | { |
| 2428 | cp_val = FALSE; |
| 2429 | arg += 3; |
| 2430 | } |
| 2431 | else // "opt&vi": set to Vi default |
| 2432 | { |
| 2433 | cp_val = TRUE; |
| 2434 | arg += 2; |
| 2435 | } |
| 2436 | } |
| 2437 | if (vim_strchr((char_u *)"?!&<", nextchar) != NULL |
| 2438 | && arg[1] != NUL && !VIM_ISWHITE(arg[1])) |
| 2439 | { |
| 2440 | errmsg = e_trailing_characters; |
| 2441 | goto skip; |
| 2442 | } |
| 2443 | } |
| 2444 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2445 | // Allow '=' and ':' for historical reasons (MSDOS command.com). |
| 2446 | // Allows only one '=' character per "set" command line. grrr. (jw) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2447 | if (nextchar == '?' |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2448 | || (prefix == PREFIX_NONE |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2449 | && vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2450 | && !(flags & P_BOOL))) |
| 2451 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2452 | // print value |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2453 | if (*did_show) |
| 2454 | msg_putchar('\n'); // cursor below last one |
| 2455 | else |
| 2456 | { |
| 2457 | gotocmdline(TRUE); // cursor at status line |
| 2458 | *did_show = TRUE; // remember that we did a line |
| 2459 | } |
| 2460 | if (opt_idx >= 0) |
| 2461 | { |
| 2462 | showoneopt(&options[opt_idx], opt_flags); |
| 2463 | #ifdef FEAT_EVAL |
| 2464 | if (p_verbose > 0) |
| 2465 | { |
| 2466 | // Mention where the option was last set. |
| 2467 | if (varp == options[opt_idx].var) |
| 2468 | last_set_msg(options[opt_idx].script_ctx); |
| 2469 | else if ((int)options[opt_idx].indir & PV_WIN) |
| 2470 | last_set_msg(curwin->w_p_script_ctx[ |
| 2471 | (int)options[opt_idx].indir & PV_MASK]); |
| 2472 | else if ((int)options[opt_idx].indir & PV_BUF) |
| 2473 | last_set_msg(curbuf->b_p_script_ctx[ |
| 2474 | (int)options[opt_idx].indir & PV_MASK]); |
| 2475 | } |
| 2476 | #endif |
| 2477 | } |
| 2478 | else |
| 2479 | { |
| 2480 | char_u *p; |
| 2481 | |
| 2482 | p = find_termcode(key_name); |
| 2483 | if (p == NULL) |
| 2484 | { |
| 2485 | errmsg = e_key_code_not_set; |
| 2486 | goto skip; |
| 2487 | } |
| 2488 | else |
| 2489 | (void)show_one_termcode(key_name, p, TRUE); |
| 2490 | } |
| 2491 | if (nextchar != '?' |
| 2492 | && nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2493 | errmsg = e_trailing_characters; |
| 2494 | } |
| 2495 | else |
| 2496 | { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2497 | errmsg = do_set_option_value(opt_idx, opt_flags, &arg, prefix, op, |
| 2498 | flags, varp, key_name, nextchar, |
| 2499 | afterchar, cp_val, stopopteval, errbuf, |
| 2500 | errbuflen); |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | skip: |
| 2504 | *argp = arg; |
| 2505 | return errmsg; |
| 2506 | } |
| 2507 | |
| 2508 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2509 | * Parse 'arg' for option settings. |
| 2510 | * |
| 2511 | * 'arg' may be IObuff, but only when no errors can be present and option |
| 2512 | * does not need to be expanded with option_expand(). |
| 2513 | * "opt_flags": |
| 2514 | * 0 for ":set" |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2515 | * OPT_GLOBAL for ":setglobal" |
| 2516 | * OPT_LOCAL for ":setlocal" and a modeline |
| 2517 | * OPT_MODELINE for a modeline |
| 2518 | * OPT_WINONLY to only set window-local options |
| 2519 | * OPT_NOWIN to skip setting window-local options |
| 2520 | * OPT_ONECOLUMN do not use multiple columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2521 | * |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2522 | * Returns FAIL if an error is detected, OK otherwise. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2523 | */ |
| 2524 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2525 | do_set( |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2526 | char_u *arg_start, // option string (may be written to!) |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2527 | int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2528 | { |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2529 | char_u *arg = arg_start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2530 | int i; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2531 | int did_show = FALSE; // already showed one value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2532 | |
| 2533 | if (*arg == NUL) |
| 2534 | { |
| 2535 | showoptions(0, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2536 | did_show = TRUE; |
| 2537 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2540 | while (*arg != NUL) // loop to process all options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2541 | { |
zeertzjq | 0ef9a5c | 2023-01-17 21:38:25 +0000 | [diff] [blame] | 2542 | if (STRNCMP(arg, "all", 3) == 0 && !ASCII_ISALPHA(arg[3]) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2543 | && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2544 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2545 | // ":set all" show all options. |
| 2546 | // ":set all&" set all options to their default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2547 | arg += 3; |
| 2548 | if (*arg == '&') |
| 2549 | { |
| 2550 | ++arg; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2551 | // Only for :set command set global value of local options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2552 | set_options_default(OPT_FREE | opt_flags); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2553 | didset_options(); |
| 2554 | didset_options2(); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 2555 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2556 | } |
| 2557 | else |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2558 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2559 | showoptions(1, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2560 | did_show = TRUE; |
| 2561 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2562 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2563 | else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2564 | { |
| 2565 | showoptions(2, opt_flags); |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2566 | show_termcodes(opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2567 | did_show = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2568 | arg += 7; |
| 2569 | } |
| 2570 | else |
| 2571 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2572 | int stopopteval = FALSE; |
| 2573 | char *errmsg = NULL; |
| 2574 | char errbuf[80]; |
| 2575 | char_u *startarg = arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2576 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2577 | errmsg = do_set_option(opt_flags, &arg, arg_start, &startarg, |
| 2578 | &did_show, &stopopteval, errbuf, |
| 2579 | sizeof(errbuf)); |
| 2580 | if (stopopteval) |
| 2581 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2582 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2583 | // Advance to next argument. |
| 2584 | // - skip until a blank found, taking care of backslashes |
| 2585 | // - skip blanks |
| 2586 | // - skip one "=val" argument (for hidden options ":set gfn =xx") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2587 | for (i = 0; i < 2 ; ++i) |
| 2588 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 2589 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2590 | if (*arg++ == '\\' && *arg != NUL) |
| 2591 | ++arg; |
| 2592 | arg = skipwhite(arg); |
| 2593 | if (*arg != '=') |
| 2594 | break; |
| 2595 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2596 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2597 | if (errmsg != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2598 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2599 | vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1); |
| 2600 | i = (int)STRLEN(IObuff) + 2; |
| 2601 | if (i + (arg - startarg) < IOSIZE) |
| 2602 | { |
| 2603 | // append the argument with the error |
| 2604 | STRCAT(IObuff, ": "); |
| 2605 | mch_memmove(IObuff + i, startarg, (arg - startarg)); |
| 2606 | IObuff[i + (arg - startarg)] = NUL; |
| 2607 | } |
| 2608 | // make sure all characters are printable |
| 2609 | trans_characters(IObuff, IOSIZE); |
| 2610 | |
| 2611 | ++no_wait_return; // wait_return() done later |
| 2612 | emsg((char *)IObuff); // show error highlighted |
| 2613 | --no_wait_return; |
| 2614 | |
| 2615 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2616 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | arg = skipwhite(arg); |
| 2620 | } |
| 2621 | |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2622 | theend: |
| 2623 | if (silent_mode && did_show) |
| 2624 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2625 | // After displaying option values in silent mode. |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2626 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2627 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2628 | msg_putchar('\n'); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2629 | cursor_on(); // msg_start() switches it off |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2630 | out_flush(); |
| 2631 | silent_mode = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2632 | info_message = FALSE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2635 | return OK; |
| 2636 | } |
| 2637 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2638 | /* |
| 2639 | * Call this when an option has been given a new value through a user command. |
| 2640 | * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. |
| 2641 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2642 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2643 | did_set_option( |
| 2644 | int opt_idx, |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2645 | int opt_flags, // possibly with OPT_MODELINE |
| 2646 | int new_value, // value was replaced completely |
| 2647 | int value_checked) // value was checked to be safe, no need to set the |
| 2648 | // P_INSECURE flag. |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2649 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2650 | long_u *p; |
| 2651 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2652 | options[opt_idx].flags |= P_WAS_SET; |
| 2653 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2654 | // When an option is set in the sandbox, from a modeline or in secure mode |
| 2655 | // set the P_INSECURE flag. Otherwise, if a new value is stored reset the |
| 2656 | // flag. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2657 | p = insecure_flag(opt_idx, opt_flags); |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2658 | if (!value_checked && (secure |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2659 | #ifdef HAVE_SANDBOX |
| 2660 | || sandbox != 0 |
| 2661 | #endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2662 | || (opt_flags & OPT_MODELINE))) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2663 | *p = *p | P_INSECURE; |
| 2664 | else if (new_value) |
| 2665 | *p = *p & ~P_INSECURE; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2666 | } |
| 2667 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2668 | /* |
| 2669 | * Convert a key name or string into a key value. |
| 2670 | * Used for 'wildchar' and 'cedit' options. |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2671 | * When "multi_byte" is TRUE allow for multi-byte characters. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2672 | */ |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2673 | int |
| 2674 | string_to_key(char_u *arg, int multi_byte) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2675 | { |
| 2676 | if (*arg == '<') |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 2677 | return find_key_option(arg + 1, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2678 | if (*arg == '^') |
| 2679 | return Ctrl_chr(arg[1]); |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2680 | if (multi_byte) |
| 2681 | return PTR2CHAR(arg); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2682 | return *arg; |
| 2683 | } |
| 2684 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2685 | /* |
| 2686 | * When changing 'title', 'titlestring', 'icon' or 'iconstring', call |
| 2687 | * maketitle() to create and display it. |
| 2688 | * When switching the title or icon off, call mch_restore_title() to get |
| 2689 | * the old value back. |
| 2690 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2691 | void |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 2692 | did_set_title(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2693 | { |
| 2694 | if (starting != NO_SCREEN |
| 2695 | #ifdef FEAT_GUI |
| 2696 | && !gui.starting |
| 2697 | #endif |
| 2698 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2699 | maketitle(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2700 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2701 | |
| 2702 | /* |
| 2703 | * set_options_bin - called when 'bin' changes value. |
| 2704 | */ |
| 2705 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2706 | set_options_bin( |
| 2707 | int oldval, |
| 2708 | int newval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2709 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2710 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2711 | // The option values that are changed when 'bin' changes are |
| 2712 | // copied when 'bin is set and restored when 'bin' is reset. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2713 | if (newval) |
| 2714 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2715 | if (!oldval) // switched on |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2716 | { |
| 2717 | if (!(opt_flags & OPT_GLOBAL)) |
| 2718 | { |
| 2719 | curbuf->b_p_tw_nobin = curbuf->b_p_tw; |
| 2720 | curbuf->b_p_wm_nobin = curbuf->b_p_wm; |
| 2721 | curbuf->b_p_ml_nobin = curbuf->b_p_ml; |
| 2722 | curbuf->b_p_et_nobin = curbuf->b_p_et; |
| 2723 | } |
| 2724 | if (!(opt_flags & OPT_LOCAL)) |
| 2725 | { |
| 2726 | p_tw_nobin = p_tw; |
| 2727 | p_wm_nobin = p_wm; |
| 2728 | p_ml_nobin = p_ml; |
| 2729 | p_et_nobin = p_et; |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | if (!(opt_flags & OPT_GLOBAL)) |
| 2734 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2735 | curbuf->b_p_tw = 0; // no automatic line wrap |
| 2736 | curbuf->b_p_wm = 0; // no automatic line wrap |
| 2737 | curbuf->b_p_ml = 0; // no modelines |
| 2738 | curbuf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2739 | } |
| 2740 | if (!(opt_flags & OPT_LOCAL)) |
| 2741 | { |
| 2742 | p_tw = 0; |
| 2743 | p_wm = 0; |
| 2744 | p_ml = FALSE; |
| 2745 | p_et = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2746 | p_bin = TRUE; // needed when called for the "-b" argument |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2747 | } |
| 2748 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2749 | else if (oldval) // switched off |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2750 | { |
| 2751 | if (!(opt_flags & OPT_GLOBAL)) |
| 2752 | { |
| 2753 | curbuf->b_p_tw = curbuf->b_p_tw_nobin; |
| 2754 | curbuf->b_p_wm = curbuf->b_p_wm_nobin; |
| 2755 | curbuf->b_p_ml = curbuf->b_p_ml_nobin; |
| 2756 | curbuf->b_p_et = curbuf->b_p_et_nobin; |
| 2757 | } |
| 2758 | if (!(opt_flags & OPT_LOCAL)) |
| 2759 | { |
| 2760 | p_tw = p_tw_nobin; |
| 2761 | p_wm = p_wm_nobin; |
| 2762 | p_ml = p_ml_nobin; |
| 2763 | p_et = p_et_nobin; |
| 2764 | } |
| 2765 | } |
| 2766 | } |
| 2767 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2768 | /* |
| 2769 | * Expand environment variables for some string options. |
| 2770 | * These string options cannot be indirect! |
| 2771 | * If "val" is NULL expand the current value of the option. |
| 2772 | * Return pointer to NameBuff, or NULL when not expanded. |
| 2773 | */ |
| 2774 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2775 | option_expand(int opt_idx, char_u *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2776 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2777 | // if option doesn't need expansion nothing to do |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2778 | if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) |
| 2779 | return NULL; |
| 2780 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2781 | // If val is longer than MAXPATHL no meaningful expansion can be done, |
| 2782 | // expand_env() would truncate the string. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2783 | if (val != NULL && STRLEN(val) > MAXPATHL) |
| 2784 | return NULL; |
| 2785 | |
| 2786 | if (val == NULL) |
| 2787 | val = *(char_u **)options[opt_idx].var; |
| 2788 | |
| 2789 | /* |
| 2790 | * Expanding this with NameBuff, expand_env() must not be passed IObuff. |
| 2791 | * Escape spaces when expanding 'tags', they are used to separate file |
| 2792 | * names. |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2793 | * For 'spellsuggest' expand after "file:". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2794 | */ |
| 2795 | expand_env_esc(val, NameBuff, MAXPATHL, |
Bram Moolenaar | 9f0545d | 2007-09-26 20:36:32 +0000 | [diff] [blame] | 2796 | (char_u **)options[opt_idx].var == &p_tags, FALSE, |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2797 | #ifdef FEAT_SPELL |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2798 | (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : |
| 2799 | #endif |
| 2800 | NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2801 | if (STRCMP(NameBuff, val) == 0) // they are the same |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2802 | return NULL; |
| 2803 | |
| 2804 | return NameBuff; |
| 2805 | } |
| 2806 | |
| 2807 | /* |
| 2808 | * After setting various option values: recompute variables that depend on |
| 2809 | * option values. |
| 2810 | */ |
| 2811 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2812 | didset_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2813 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2814 | // initialize the table for 'iskeyword' et.al. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2815 | (void)init_chartab(); |
| 2816 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2817 | didset_string_options(); |
| 2818 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2819 | #ifdef FEAT_SPELL |
Bram Moolenaar | 8aff23a | 2005-08-19 20:40:30 +0000 | [diff] [blame] | 2820 | (void)spell_check_msm(); |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2821 | (void)spell_check_sps(); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2822 | (void)compile_cap_prog(curwin->w_s); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2823 | (void)did_set_spell_option(TRUE); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 2824 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2825 | // set cedit_key |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2826 | (void)did_set_cedit(NULL); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 2827 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2828 | // initialize the table for 'breakat'. |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2829 | did_set_breakat(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2830 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2831 | after_copy_winopt(curwin); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | /* |
| 2835 | * More side effects of setting options. |
| 2836 | */ |
| 2837 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2838 | didset_options2(void) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2839 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2840 | // Initialize the highlight_attr[] table. |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2841 | (void)highlight_changed(); |
| 2842 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2843 | // Parse default for 'wildmode' |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2844 | check_opt_wim(); |
| 2845 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2846 | // Parse default for 'listchars'. |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2847 | (void)set_listchars_option(curwin, curwin->w_p_lcs, TRUE); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2848 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2849 | // Parse default for 'fillchars'. |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2850 | (void)set_fillchars_option(curwin, curwin->w_p_fcs, TRUE); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2851 | |
| 2852 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2853 | // Parse default for 'clipboard' |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2854 | (void)did_set_clipboard(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2855 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2856 | #ifdef FEAT_VARTABS |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2857 | vim_free(curbuf->b_p_vsts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2858 | (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2859 | vim_free(curbuf->b_p_vts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2860 | (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2861 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | /* |
| 2865 | * Check for string options that are NULL (normally only termcap options). |
| 2866 | */ |
| 2867 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2868 | check_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2869 | { |
| 2870 | int opt_idx; |
| 2871 | |
| 2872 | for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) |
| 2873 | if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) |
| 2874 | check_string_option((char_u **)get_varp(&(options[opt_idx]))); |
| 2875 | } |
| 2876 | |
| 2877 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2878 | * Return the option index found by a pointer into term_strings[]. |
| 2879 | * Return -1 if not found. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2880 | */ |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2881 | int |
| 2882 | get_term_opt_idx(char_u **p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2883 | { |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2884 | int opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2885 | |
| 2886 | for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) |
| 2887 | if (options[opt_idx].var == (char_u *)p) |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2888 | return opt_idx; |
| 2889 | return -1; // cannot happen: didn't find it! |
| 2890 | } |
| 2891 | |
| 2892 | /* |
| 2893 | * Mark a terminal option as allocated, found by a pointer into term_strings[]. |
| 2894 | * Return the option index or -1 if not found. |
| 2895 | */ |
| 2896 | int |
| 2897 | set_term_option_alloced(char_u **p) |
| 2898 | { |
| 2899 | int opt_idx = get_term_opt_idx(p); |
| 2900 | |
| 2901 | if (opt_idx >= 0) |
| 2902 | options[opt_idx].flags |= P_ALLOCED; |
| 2903 | return opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2906 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2907 | /* |
| 2908 | * Return TRUE when option "opt" was set from a modeline or in secure mode. |
| 2909 | * Return FALSE when it wasn't. |
| 2910 | * Return -1 for an unknown option. |
| 2911 | */ |
| 2912 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2913 | was_set_insecurely(char_u *opt, int opt_flags) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2914 | { |
| 2915 | int idx = findoption(opt); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2916 | long_u *flagp; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2917 | |
| 2918 | if (idx >= 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2919 | { |
| 2920 | flagp = insecure_flag(idx, opt_flags); |
| 2921 | return (*flagp & P_INSECURE) != 0; |
| 2922 | } |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 2923 | internal_error("was_set_insecurely()"); |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2924 | return -1; |
| 2925 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2926 | |
| 2927 | /* |
| 2928 | * Get a pointer to the flags used for the P_INSECURE flag of option |
| 2929 | * "opt_idx". For some local options a local flags field is used. |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 2930 | * NOTE: Caller must make sure that "curwin" is set to the window from which |
| 2931 | * the option is used. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2932 | */ |
| 2933 | static long_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2934 | insecure_flag(int opt_idx, int opt_flags) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2935 | { |
| 2936 | if (opt_flags & OPT_LOCAL) |
| 2937 | switch ((int)options[opt_idx].indir) |
| 2938 | { |
| 2939 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2940 | case PV_STL: return &curwin->w_p_stl_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2941 | #endif |
| 2942 | #ifdef FEAT_EVAL |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2943 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2944 | case PV_FDE: return &curwin->w_p_fde_flags; |
| 2945 | case PV_FDT: return &curwin->w_p_fdt_flags; |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2946 | # endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 2947 | # ifdef FEAT_BEVAL |
| 2948 | case PV_BEXPR: return &curbuf->b_p_bexpr_flags; |
| 2949 | # endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2950 | case PV_INDE: return &curbuf->b_p_inde_flags; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2951 | case PV_FEX: return &curbuf->b_p_fex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2952 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2953 | case PV_INEX: return &curbuf->b_p_inex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2954 | # endif |
| 2955 | #endif |
| 2956 | } |
| 2957 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2958 | // Nothing special, return global flags field. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2959 | return &options[opt_idx].flags; |
| 2960 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2961 | #endif |
| 2962 | |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2963 | /* |
| 2964 | * Redraw the window title and/or tab page text later. |
| 2965 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2966 | void redraw_titles(void) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2967 | { |
| 2968 | need_maketitle = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2969 | redraw_tabline = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2970 | } |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2971 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2972 | /* |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2973 | * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII |
| 2974 | * characters or characters in "allowed". |
| 2975 | */ |
Bram Moolenaar | e677df8 | 2019-09-02 22:31:11 +0200 | [diff] [blame] | 2976 | int |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2977 | valid_name(char_u *val, char *allowed) |
| 2978 | { |
| 2979 | char_u *s; |
| 2980 | |
| 2981 | for (s = val; *s != NUL; ++s) |
| 2982 | if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL) |
| 2983 | return FALSE; |
| 2984 | return TRUE; |
| 2985 | } |
| 2986 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2987 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2988 | /* |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2989 | * 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] | 2990 | * window-local value. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2991 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2992 | void |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2993 | 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] | 2994 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2995 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 2996 | int indir = (int)options[opt_idx].indir; |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 2997 | sctx_T new_script_ctx = script_ctx; |
| 2998 | |
Bram Moolenaar | 5125874 | 2020-05-03 17:19:33 +0200 | [diff] [blame] | 2999 | // Modeline already has the line number set. |
| 3000 | if (!(opt_flags & OPT_MODELINE)) |
| 3001 | new_script_ctx.sc_lnum += SOURCING_LNUM; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3002 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3003 | // Remember where the option was set. For local options need to do that |
| 3004 | // in the buffer or window structure. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3005 | if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3006 | options[opt_idx].script_ctx = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3007 | if (both || (opt_flags & OPT_LOCAL)) |
| 3008 | { |
| 3009 | if (indir & PV_BUF) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3010 | curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3011 | else if (indir & PV_WIN) |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3012 | { |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3013 | curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3014 | if (both) |
| 3015 | // also setting the "all buffers" value |
| 3016 | curwin->w_allbuf_opt.wo_script_ctx[indir & PV_MASK] = |
| 3017 | new_script_ctx; |
| 3018 | } |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3019 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3020 | } |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3021 | |
| 3022 | /* |
Bram Moolenaar | 5600a70 | 2022-01-22 15:09:36 +0000 | [diff] [blame] | 3023 | * Get the script context of global option "name". |
| 3024 | * |
| 3025 | */ |
| 3026 | sctx_T * |
| 3027 | get_option_sctx(char *name) |
| 3028 | { |
| 3029 | int idx = findoption((char_u *)name); |
| 3030 | |
| 3031 | if (idx >= 0) |
| 3032 | return &options[idx].script_ctx; |
| 3033 | siemsg("no such option: %s", name); |
| 3034 | return NULL; |
| 3035 | } |
| 3036 | |
| 3037 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3038 | * Set the script_ctx for a termcap option. |
| 3039 | * "name" must be the two character code, e.g. "RV". |
| 3040 | * When "name" is NULL use "opt_idx". |
| 3041 | */ |
| 3042 | void |
| 3043 | set_term_option_sctx_idx(char *name, int opt_idx) |
| 3044 | { |
| 3045 | char_u buf[5]; |
| 3046 | int idx; |
| 3047 | |
| 3048 | if (name == NULL) |
| 3049 | idx = opt_idx; |
| 3050 | else |
| 3051 | { |
| 3052 | buf[0] = 't'; |
| 3053 | buf[1] = '_'; |
| 3054 | buf[2] = name[0]; |
| 3055 | buf[3] = name[1]; |
| 3056 | buf[4] = 0; |
| 3057 | idx = findoption(buf); |
| 3058 | } |
| 3059 | if (idx >= 0) |
| 3060 | set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx); |
| 3061 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3062 | #endif |
| 3063 | |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3064 | #if defined(FEAT_EVAL) |
| 3065 | /* |
| 3066 | * Apply the OptionSet autocommand. |
| 3067 | */ |
| 3068 | static void |
| 3069 | apply_optionset_autocmd( |
| 3070 | int opt_idx, |
| 3071 | long opt_flags, |
| 3072 | long oldval, |
| 3073 | long oldval_g, |
| 3074 | long newval, |
| 3075 | char *errmsg) |
| 3076 | { |
| 3077 | char_u buf_old[12], buf_old_global[12], buf_new[12], buf_type[12]; |
| 3078 | |
| 3079 | // Don't do this while starting up, failure or recursively. |
| 3080 | if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL) |
| 3081 | return; |
| 3082 | |
| 3083 | vim_snprintf((char *)buf_old, sizeof(buf_old), "%ld", oldval); |
| 3084 | vim_snprintf((char *)buf_old_global, sizeof(buf_old_global), "%ld", |
| 3085 | oldval_g); |
| 3086 | vim_snprintf((char *)buf_new, sizeof(buf_new), "%ld", newval); |
| 3087 | vim_snprintf((char *)buf_type, sizeof(buf_type), "%s", |
| 3088 | (opt_flags & OPT_LOCAL) ? "local" : "global"); |
| 3089 | set_vim_var_string(VV_OPTION_NEW, buf_new, -1); |
| 3090 | set_vim_var_string(VV_OPTION_OLD, buf_old, -1); |
| 3091 | set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
| 3092 | if (opt_flags & OPT_LOCAL) |
| 3093 | { |
| 3094 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
| 3095 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3096 | } |
| 3097 | if (opt_flags & OPT_GLOBAL) |
| 3098 | { |
| 3099 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
| 3100 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); |
| 3101 | } |
| 3102 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3103 | { |
| 3104 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
| 3105 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3106 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); |
| 3107 | } |
| 3108 | if (opt_flags & OPT_MODELINE) |
| 3109 | { |
| 3110 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
| 3111 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3112 | } |
| 3113 | apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, |
| 3114 | NULL, FALSE, NULL); |
| 3115 | reset_v_option_vars(); |
| 3116 | } |
| 3117 | #endif |
| 3118 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3119 | #if defined(FEAT_ARABIC) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3120 | /* |
| 3121 | * Process the updated 'arabic' option value. |
| 3122 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3123 | char * |
| 3124 | did_set_arabic(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3125 | { |
| 3126 | char *errmsg = NULL; |
| 3127 | |
| 3128 | if (curwin->w_p_arab) |
| 3129 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 3130 | // 'arabic' is set, handle various sub-settings. |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3131 | if (!p_tbidi) |
| 3132 | { |
| 3133 | // set rightleft mode |
| 3134 | if (!curwin->w_p_rl) |
| 3135 | { |
| 3136 | curwin->w_p_rl = TRUE; |
| 3137 | changed_window_setting(); |
| 3138 | } |
| 3139 | |
| 3140 | // Enable Arabic shaping (major part of what Arabic requires) |
| 3141 | if (!p_arshape) |
| 3142 | { |
| 3143 | p_arshape = TRUE; |
| 3144 | redraw_later_clear(); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | // Arabic requires a utf-8 encoding, inform the user if it's not |
| 3149 | // set. |
| 3150 | if (STRCMP(p_enc, "utf-8") != 0) |
| 3151 | { |
| 3152 | static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); |
| 3153 | |
| 3154 | msg_source(HL_ATTR(HLF_W)); |
| 3155 | msg_attr(_(w_arabic), HL_ATTR(HLF_W)); |
| 3156 | #ifdef FEAT_EVAL |
| 3157 | set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); |
| 3158 | #endif |
| 3159 | } |
| 3160 | |
| 3161 | // set 'delcombine' |
| 3162 | p_deco = TRUE; |
| 3163 | |
| 3164 | # ifdef FEAT_KEYMAP |
| 3165 | // Force-set the necessary keymap for arabic |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3166 | errmsg = set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", |
| 3167 | OPT_LOCAL); |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3168 | # endif |
| 3169 | } |
| 3170 | else |
| 3171 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 3172 | // 'arabic' is reset, handle various sub-settings. |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3173 | if (!p_tbidi) |
| 3174 | { |
| 3175 | // reset rightleft mode |
| 3176 | if (curwin->w_p_rl) |
| 3177 | { |
| 3178 | curwin->w_p_rl = FALSE; |
| 3179 | changed_window_setting(); |
| 3180 | } |
| 3181 | |
| 3182 | // 'arabicshape' isn't reset, it is a global option and |
| 3183 | // another window may still need it "on". |
| 3184 | } |
| 3185 | |
| 3186 | // 'delcombine' isn't reset, it is a global option and another |
| 3187 | // window may still want it "on". |
| 3188 | |
| 3189 | # ifdef FEAT_KEYMAP |
| 3190 | // Revert to the default keymap |
| 3191 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3192 | curbuf->b_p_imsearch = B_IMODE_USE_INSERT; |
| 3193 | # endif |
| 3194 | } |
| 3195 | |
| 3196 | return errmsg; |
| 3197 | } |
| 3198 | #endif |
| 3199 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3200 | #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
| 3201 | /* |
| 3202 | * Process the updated 'autochdir' option value. |
| 3203 | */ |
| 3204 | char * |
| 3205 | did_set_autochdir(optset_T *args UNUSED) |
| 3206 | { |
| 3207 | // Change directories when the 'acd' option is set now. |
| 3208 | DO_AUTOCHDIR; |
| 3209 | return NULL; |
| 3210 | } |
| 3211 | #endif |
| 3212 | |
| 3213 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
| 3214 | /* |
| 3215 | * Process the updated 'ballooneval' option value. |
| 3216 | */ |
| 3217 | char * |
| 3218 | did_set_ballooneval(optset_T *args) |
| 3219 | { |
| 3220 | if (balloonEvalForTerm) |
| 3221 | return NULL; |
| 3222 | |
| 3223 | if (p_beval && !args->os_oldval.boolean) |
| 3224 | gui_mch_enable_beval_area(balloonEval); |
| 3225 | else if (!p_beval && args->os_oldval.boolean) |
| 3226 | gui_mch_disable_beval_area(balloonEval); |
| 3227 | |
| 3228 | return NULL; |
| 3229 | } |
| 3230 | #endif |
| 3231 | |
| 3232 | #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
| 3233 | /* |
| 3234 | * Process the updated 'balloonevalterm' option value. |
| 3235 | */ |
| 3236 | char * |
| 3237 | did_set_balloonevalterm(optset_T *args UNUSED) |
| 3238 | { |
| 3239 | mch_bevalterm_changed(); |
| 3240 | return NULL; |
| 3241 | } |
| 3242 | #endif |
| 3243 | |
| 3244 | /* |
| 3245 | * Process the updated 'binary' option value. |
| 3246 | */ |
| 3247 | char * |
| 3248 | did_set_binary(optset_T *args) |
| 3249 | { |
| 3250 | // when 'bin' is set also set some other options |
| 3251 | set_options_bin(args->os_oldval.boolean, curbuf->b_p_bin, args->os_flags); |
| 3252 | redraw_titles(); |
| 3253 | |
| 3254 | return NULL; |
| 3255 | } |
| 3256 | |
| 3257 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 3258 | /* |
| 3259 | * Called when the 'breakat' option changes value. |
| 3260 | */ |
| 3261 | char * |
| 3262 | did_set_breakat(optset_T *args UNUSED) |
| 3263 | { |
| 3264 | char_u *p; |
| 3265 | int i; |
| 3266 | |
| 3267 | for (i = 0; i < 256; i++) |
| 3268 | breakat_flags[i] = FALSE; |
| 3269 | |
| 3270 | if (p_breakat != NULL) |
| 3271 | for (p = p_breakat; *p; p++) |
| 3272 | breakat_flags[*p] = TRUE; |
| 3273 | |
| 3274 | return NULL; |
| 3275 | } |
| 3276 | #endif |
| 3277 | |
| 3278 | /* |
| 3279 | * Process the updated 'buflisted' option value. |
| 3280 | */ |
| 3281 | char * |
| 3282 | did_set_buflisted(optset_T *args) |
| 3283 | { |
| 3284 | // when 'buflisted' changes, trigger autocommands |
| 3285 | if (args->os_oldval.boolean != curbuf->b_p_bl) |
| 3286 | apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, |
| 3287 | NULL, NULL, TRUE, curbuf); |
| 3288 | return NULL; |
| 3289 | } |
| 3290 | |
| 3291 | /* |
| 3292 | * Process the new 'cmdheight' option value. |
| 3293 | */ |
| 3294 | char * |
| 3295 | did_set_cmdheight(optset_T *args) |
| 3296 | { |
| 3297 | long old_value = args->os_oldval.number; |
| 3298 | char *errmsg = NULL; |
| 3299 | |
| 3300 | // if p_ch changed value, change the command line height |
| 3301 | if (p_ch < 1) |
| 3302 | { |
| 3303 | errmsg = e_argument_must_be_positive; |
| 3304 | p_ch = 1; |
| 3305 | } |
| 3306 | if (p_ch > Rows - min_rows() + 1) |
| 3307 | p_ch = Rows - min_rows() + 1; |
| 3308 | |
| 3309 | // Only compute the new window layout when startup has been |
| 3310 | // completed. Otherwise the frame sizes may be wrong. |
| 3311 | if ((p_ch != old_value |
| 3312 | || tabline_height() + topframe->fr_height != Rows - p_ch) |
| 3313 | && full_screen |
| 3314 | #ifdef FEAT_GUI |
| 3315 | && !gui.starting |
| 3316 | #endif |
| 3317 | ) |
| 3318 | command_height(); |
| 3319 | |
| 3320 | return errmsg; |
| 3321 | } |
| 3322 | |
| 3323 | /* |
| 3324 | * Process the updated 'compatible' option value. |
| 3325 | */ |
| 3326 | char * |
| 3327 | did_set_compatible(optset_T *args UNUSED) |
| 3328 | { |
| 3329 | compatible_set(); |
| 3330 | return NULL; |
| 3331 | } |
| 3332 | |
| 3333 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
| 3334 | /* |
| 3335 | * Process the new 'conceallevel' option value. |
| 3336 | */ |
| 3337 | char * |
| 3338 | did_set_conceallevel(optset_T *args UNUSED) |
| 3339 | { |
| 3340 | char *errmsg = NULL; |
| 3341 | |
| 3342 | if (curwin->w_p_cole < 0) |
| 3343 | { |
| 3344 | errmsg = e_argument_must_be_positive; |
| 3345 | curwin->w_p_cole = 0; |
| 3346 | } |
| 3347 | else if (curwin->w_p_cole > 3) |
| 3348 | { |
| 3349 | errmsg = e_invalid_argument; |
| 3350 | curwin->w_p_cole = 3; |
| 3351 | } |
| 3352 | |
| 3353 | return errmsg; |
| 3354 | } |
| 3355 | #endif |
| 3356 | |
| 3357 | #if defined(FEAT_DIFF) || defined(PROTO) |
| 3358 | /* |
| 3359 | * Process the updated 'diff' option value. |
| 3360 | */ |
| 3361 | char * |
| 3362 | did_set_diff(optset_T *args UNUSED) |
| 3363 | { |
| 3364 | // May add or remove the buffer from the list of diff buffers. |
| 3365 | diff_buf_adjust(curwin); |
| 3366 | # ifdef FEAT_FOLDING |
| 3367 | if (foldmethodIsDiff(curwin)) |
| 3368 | foldUpdateAll(curwin); |
| 3369 | # endif |
| 3370 | return NULL; |
| 3371 | } |
| 3372 | #endif |
| 3373 | |
| 3374 | /* |
| 3375 | * Process the updated 'endoffile' or 'endofline' or 'fixendofline' or 'bomb' |
| 3376 | * option value. |
| 3377 | */ |
| 3378 | char * |
| 3379 | did_set_eof_eol_fixeol_bomb(optset_T *args UNUSED) |
| 3380 | { |
| 3381 | // redraw the window title and tab page text |
| 3382 | redraw_titles(); |
| 3383 | return NULL; |
| 3384 | } |
| 3385 | |
| 3386 | /* |
| 3387 | * Process the updated 'equalalways' option value. |
| 3388 | */ |
| 3389 | char * |
| 3390 | did_set_equalalways(optset_T *args) |
| 3391 | { |
| 3392 | if (p_ea && !args->os_oldval.boolean) |
| 3393 | win_equal(curwin, FALSE, 0); |
| 3394 | |
| 3395 | return NULL; |
| 3396 | } |
| 3397 | |
| 3398 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 3399 | /* |
| 3400 | * Process the new 'foldcolumn' option value. |
| 3401 | */ |
| 3402 | char * |
| 3403 | did_set_foldcolumn(optset_T *args UNUSED) |
| 3404 | { |
| 3405 | char *errmsg = NULL; |
| 3406 | |
| 3407 | if (curwin->w_p_fdc < 0) |
| 3408 | { |
| 3409 | errmsg = e_argument_must_be_positive; |
| 3410 | curwin->w_p_fdc = 0; |
| 3411 | } |
| 3412 | else if (curwin->w_p_fdc > 12) |
| 3413 | { |
| 3414 | errmsg = e_invalid_argument; |
| 3415 | curwin->w_p_fdc = 12; |
| 3416 | } |
| 3417 | |
| 3418 | return errmsg; |
| 3419 | } |
| 3420 | |
| 3421 | /* |
| 3422 | * Process the new 'foldlevel' option value. |
| 3423 | */ |
| 3424 | char * |
| 3425 | did_set_foldlevel(optset_T *args UNUSED) |
| 3426 | { |
| 3427 | if (curwin->w_p_fdl < 0) |
| 3428 | curwin->w_p_fdl = 0; |
| 3429 | newFoldLevel(); |
| 3430 | return NULL; |
| 3431 | } |
| 3432 | |
| 3433 | /* |
| 3434 | * Process the new 'foldminlines' option value. |
| 3435 | */ |
| 3436 | char * |
| 3437 | did_set_foldminlines(optset_T *args UNUSED) |
| 3438 | { |
| 3439 | foldUpdateAll(curwin); |
| 3440 | return NULL; |
| 3441 | } |
| 3442 | |
| 3443 | /* |
| 3444 | * Process the new 'foldnestmax' option value. |
| 3445 | */ |
| 3446 | char * |
| 3447 | did_set_foldnestmax(optset_T *args UNUSED) |
| 3448 | { |
| 3449 | if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) |
| 3450 | foldUpdateAll(curwin); |
| 3451 | return NULL; |
| 3452 | } |
| 3453 | #endif |
| 3454 | |
| 3455 | #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) |
| 3456 | /* |
| 3457 | * Process the updated 'hlsearch' option value. |
| 3458 | */ |
| 3459 | char * |
| 3460 | did_set_hlsearch(optset_T *args UNUSED) |
| 3461 | { |
| 3462 | // when 'hlsearch' is set or reset: reset no_hlsearch |
| 3463 | set_no_hlsearch(FALSE); |
| 3464 | return NULL; |
| 3465 | } |
| 3466 | #endif |
| 3467 | |
| 3468 | /* |
| 3469 | * Process the updated 'ignorecase' option value. |
| 3470 | */ |
| 3471 | char * |
| 3472 | did_set_ignorecase(optset_T *args UNUSED) |
| 3473 | { |
| 3474 | // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw |
| 3475 | if (p_hls) |
| 3476 | redraw_all_later(UPD_SOME_VALID); |
| 3477 | return NULL; |
| 3478 | } |
| 3479 | |
| 3480 | #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
| 3481 | /* |
| 3482 | * Process the updated 'imdisable' option value. |
| 3483 | */ |
| 3484 | char * |
| 3485 | did_set_imdisable(optset_T *args UNUSED) |
| 3486 | { |
| 3487 | // Only de-activate it here, it will be enabled when changing mode. |
| 3488 | if (p_imdisable) |
| 3489 | im_set_active(FALSE); |
| 3490 | else if (State & MODE_INSERT) |
| 3491 | // When the option is set from an autocommand, it may need to take |
| 3492 | // effect right away. |
| 3493 | im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); |
| 3494 | return NULL; |
| 3495 | } |
| 3496 | #endif |
| 3497 | |
| 3498 | /* |
| 3499 | * Process the new 'iminsert' option value. |
| 3500 | */ |
| 3501 | char * |
| 3502 | did_set_iminsert(optset_T *args UNUSED) |
| 3503 | { |
| 3504 | char *errmsg = NULL; |
| 3505 | |
| 3506 | if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) |
| 3507 | { |
| 3508 | errmsg = e_invalid_argument; |
| 3509 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3510 | } |
| 3511 | p_iminsert = curbuf->b_p_iminsert; |
| 3512 | if (termcap_active) // don't do this in the alternate screen |
| 3513 | showmode(); |
| 3514 | #if defined(FEAT_KEYMAP) |
| 3515 | // Show/unshow value of 'keymap' in status lines. |
| 3516 | status_redraw_curbuf(); |
| 3517 | #endif |
| 3518 | |
| 3519 | return errmsg; |
| 3520 | } |
| 3521 | |
| 3522 | /* |
| 3523 | * Process the new 'imsearch' option value. |
| 3524 | */ |
| 3525 | char * |
| 3526 | did_set_imsearch(optset_T *args UNUSED) |
| 3527 | { |
| 3528 | char *errmsg = NULL; |
| 3529 | |
| 3530 | if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) |
| 3531 | { |
| 3532 | errmsg = e_invalid_argument; |
| 3533 | curbuf->b_p_imsearch = B_IMODE_NONE; |
| 3534 | } |
| 3535 | p_imsearch = curbuf->b_p_imsearch; |
| 3536 | |
| 3537 | return errmsg; |
| 3538 | } |
| 3539 | |
| 3540 | #if (defined(FEAT_XIM) && defined(FEAT_GUI_GTK)) || defined(PROTO) |
| 3541 | /* |
| 3542 | * Process the new 'imstyle' option value. |
| 3543 | */ |
| 3544 | char * |
| 3545 | did_set_imstyle(optset_T *args UNUSED) |
| 3546 | { |
| 3547 | char *errmsg = NULL; |
| 3548 | |
| 3549 | if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) |
| 3550 | errmsg = e_invalid_argument; |
| 3551 | |
| 3552 | return errmsg; |
| 3553 | } |
| 3554 | #endif |
| 3555 | |
| 3556 | /* |
| 3557 | * Process the updated 'insertmode' option value. |
| 3558 | */ |
| 3559 | char * |
| 3560 | did_set_insertmode(optset_T *args) |
| 3561 | { |
| 3562 | // when 'insertmode' is set from an autocommand need to do work here |
| 3563 | if (p_im) |
| 3564 | { |
| 3565 | if ((State & MODE_INSERT) == 0) |
| 3566 | need_start_insertmode = TRUE; |
| 3567 | stop_insert_mode = FALSE; |
| 3568 | } |
| 3569 | // only reset if it was set previously |
| 3570 | else if (args->os_oldval.boolean) |
| 3571 | { |
| 3572 | need_start_insertmode = FALSE; |
| 3573 | stop_insert_mode = TRUE; |
| 3574 | if (restart_edit != 0 && mode_displayed) |
| 3575 | clear_cmdline = TRUE; // remove "(insert)" |
| 3576 | restart_edit = 0; |
| 3577 | } |
| 3578 | |
| 3579 | return NULL; |
| 3580 | } |
| 3581 | |
| 3582 | #if defined(FEAT_LANGMAP) || defined(PROTO) |
| 3583 | /* |
| 3584 | * Process the updated 'langnoremap' option value. |
| 3585 | */ |
| 3586 | char * |
| 3587 | did_set_langnoremap(optset_T *args UNUSED) |
| 3588 | { |
| 3589 | // 'langnoremap' -> !'langremap' |
| 3590 | p_lrm = !p_lnr; |
| 3591 | return NULL; |
| 3592 | } |
| 3593 | |
| 3594 | /* |
| 3595 | * Process the updated 'langremap' option value. |
| 3596 | */ |
| 3597 | char * |
| 3598 | did_set_langremap(optset_T *args UNUSED) |
| 3599 | { |
| 3600 | // 'langremap' -> !'langnoremap' |
| 3601 | p_lnr = !p_lrm; |
| 3602 | return NULL; |
| 3603 | } |
| 3604 | #endif |
| 3605 | |
| 3606 | /* |
| 3607 | * Process the new 'laststatus' option value. |
| 3608 | */ |
| 3609 | char * |
| 3610 | did_set_laststatus(optset_T *args UNUSED) |
| 3611 | { |
| 3612 | last_status(FALSE); // (re)set last window status line |
| 3613 | return NULL; |
| 3614 | } |
| 3615 | |
| 3616 | #if defined(FEAT_GUI) || defined(PROTO) |
| 3617 | /* |
| 3618 | * Process the new 'linespace' option value. |
| 3619 | */ |
| 3620 | char * |
| 3621 | did_set_linespace(optset_T *args UNUSED) |
| 3622 | { |
| 3623 | // Recompute gui.char_height and resize the Vim window to keep the |
| 3624 | // same number of lines. |
| 3625 | if (gui.in_use && gui_mch_adjust_charheight() == OK) |
| 3626 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
| 3627 | return NULL; |
| 3628 | } |
| 3629 | #endif |
| 3630 | |
| 3631 | /* |
| 3632 | * Process the updated 'lisp' option value. |
| 3633 | */ |
| 3634 | char * |
| 3635 | did_set_lisp(optset_T *args UNUSED) |
| 3636 | { |
| 3637 | // When 'lisp' option changes include/exclude '-' in keyword characters. |
| 3638 | (void)buf_init_chartab(curbuf, FALSE); // ignore errors |
| 3639 | return NULL; |
| 3640 | } |
| 3641 | |
| 3642 | /* |
| 3643 | * Process the new 'maxcombine' option value. |
| 3644 | */ |
| 3645 | char * |
| 3646 | did_set_maxcombine(optset_T *args UNUSED) |
| 3647 | { |
| 3648 | if (p_mco > MAX_MCO) |
| 3649 | p_mco = MAX_MCO; |
| 3650 | else if (p_mco < 0) |
| 3651 | p_mco = 0; |
| 3652 | screenclear(); // will re-allocate the screen |
| 3653 | return NULL; |
| 3654 | } |
| 3655 | |
| 3656 | /* |
| 3657 | * Process the updated 'modifiable' option value. |
| 3658 | */ |
| 3659 | char * |
| 3660 | did_set_modifiable(optset_T *args UNUSED) |
| 3661 | { |
| 3662 | // when 'modifiable' is changed, redraw the window title |
| 3663 | |
| 3664 | # ifdef FEAT_TERMINAL |
| 3665 | // Cannot set 'modifiable' when in Terminal mode. |
| 3666 | if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) |
| 3667 | && curbuf->b_term != NULL && !term_is_finished(curbuf)))) |
| 3668 | { |
| 3669 | curbuf->b_p_ma = FALSE; |
| 3670 | args->os_doskip = TRUE; |
| 3671 | return e_cannot_make_terminal_with_running_job_modifiable; |
| 3672 | } |
| 3673 | # endif |
| 3674 | redraw_titles(); |
| 3675 | |
| 3676 | return NULL; |
| 3677 | } |
| 3678 | |
| 3679 | /* |
| 3680 | * Process the updated 'modified' option value. |
| 3681 | */ |
| 3682 | char * |
| 3683 | did_set_modified(optset_T *args) |
| 3684 | { |
| 3685 | if (!args->os_newval.boolean) |
| 3686 | save_file_ff(curbuf); // Buffer is unchanged |
| 3687 | redraw_titles(); |
| 3688 | modified_was_set = args->os_newval.boolean; |
| 3689 | return NULL; |
| 3690 | } |
| 3691 | |
| 3692 | #if defined(FEAT_GUI) || defined(PROTO) |
| 3693 | /* |
| 3694 | * Process the updated 'mousehide' option value. |
| 3695 | */ |
| 3696 | char * |
| 3697 | did_set_mousehide(optset_T *args UNUSED) |
| 3698 | { |
| 3699 | if (!p_mh) |
| 3700 | gui_mch_mousehide(FALSE); |
| 3701 | return NULL; |
| 3702 | } |
| 3703 | #endif |
| 3704 | |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3705 | /* |
| 3706 | * Process the updated 'number' or 'relativenumber' option value. |
| 3707 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3708 | char * |
| 3709 | did_set_number_relativenumber(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3710 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3711 | #if (defined(FEAT_SIGNS) && defined(FEAT_GUI)) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3712 | if (gui.in_use |
| 3713 | && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u') |
| 3714 | && curbuf->b_signlist != NULL) |
| 3715 | { |
| 3716 | // If the 'number' or 'relativenumber' options are modified and |
| 3717 | // 'signcolumn' is set to 'number', then clear the screen for a full |
| 3718 | // refresh. Otherwise the sign icons are not displayed properly in the |
| 3719 | // number column. If the 'number' option is set and only the |
| 3720 | // 'relativenumber' option is toggled, then don't refresh the screen |
| 3721 | // (optimization). |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3722 | 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] | 3723 | redraw_all_later(UPD_CLEAR); |
| 3724 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3725 | #endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3726 | return NULL; |
| 3727 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3728 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3729 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 3730 | /* |
| 3731 | * Process the new 'numberwidth' option value. |
| 3732 | */ |
| 3733 | char * |
| 3734 | did_set_numberwidth(optset_T *args UNUSED) |
| 3735 | { |
| 3736 | char *errmsg = NULL; |
| 3737 | |
| 3738 | // 'numberwidth' must be positive |
| 3739 | if (curwin->w_p_nuw < 1) |
| 3740 | { |
| 3741 | errmsg = e_argument_must_be_positive; |
| 3742 | curwin->w_p_nuw = 1; |
| 3743 | } |
| 3744 | if (curwin->w_p_nuw > 20) |
| 3745 | { |
| 3746 | errmsg = e_invalid_argument; |
| 3747 | curwin->w_p_nuw = 20; |
| 3748 | } |
| 3749 | curwin->w_nrwidth_line_count = 0; // trigger a redraw |
| 3750 | |
| 3751 | return errmsg; |
| 3752 | } |
| 3753 | #endif |
| 3754 | |
| 3755 | /* |
| 3756 | * Process the updated 'paste' option value. Called after p_paste was set or |
| 3757 | * reset. When 'paste' is set or reset also change other options. |
| 3758 | */ |
| 3759 | char * |
| 3760 | did_set_paste(optset_T *args UNUSED) |
| 3761 | { |
| 3762 | static int old_p_paste = FALSE; |
| 3763 | static int save_sm = 0; |
| 3764 | static int save_sta = 0; |
| 3765 | static int save_ru = 0; |
| 3766 | #ifdef FEAT_RIGHTLEFT |
| 3767 | static int save_ri = 0; |
| 3768 | static int save_hkmap = 0; |
| 3769 | #endif |
| 3770 | buf_T *buf; |
| 3771 | |
| 3772 | if (p_paste) |
| 3773 | { |
| 3774 | // Paste switched from off to on. |
| 3775 | // Save the current values, so they can be restored later. |
| 3776 | if (!old_p_paste) |
| 3777 | { |
| 3778 | // save options for each buffer |
| 3779 | FOR_ALL_BUFFERS(buf) |
| 3780 | { |
| 3781 | buf->b_p_tw_nopaste = buf->b_p_tw; |
| 3782 | buf->b_p_wm_nopaste = buf->b_p_wm; |
| 3783 | buf->b_p_sts_nopaste = buf->b_p_sts; |
| 3784 | buf->b_p_ai_nopaste = buf->b_p_ai; |
| 3785 | buf->b_p_et_nopaste = buf->b_p_et; |
| 3786 | #ifdef FEAT_VARTABS |
| 3787 | if (buf->b_p_vsts_nopaste) |
| 3788 | vim_free(buf->b_p_vsts_nopaste); |
| 3789 | buf->b_p_vsts_nopaste = |
| 3790 | buf->b_p_vsts && buf->b_p_vsts != empty_option |
| 3791 | ? vim_strsave(buf->b_p_vsts) : NULL; |
| 3792 | #endif |
| 3793 | } |
| 3794 | |
| 3795 | // save global options |
| 3796 | save_sm = p_sm; |
| 3797 | save_sta = p_sta; |
| 3798 | save_ru = p_ru; |
| 3799 | #ifdef FEAT_RIGHTLEFT |
| 3800 | save_ri = p_ri; |
| 3801 | save_hkmap = p_hkmap; |
| 3802 | #endif |
| 3803 | // save global values for local buffer options |
| 3804 | p_ai_nopaste = p_ai; |
| 3805 | p_et_nopaste = p_et; |
| 3806 | p_sts_nopaste = p_sts; |
| 3807 | p_tw_nopaste = p_tw; |
| 3808 | p_wm_nopaste = p_wm; |
| 3809 | #ifdef FEAT_VARTABS |
| 3810 | if (p_vsts_nopaste) |
| 3811 | vim_free(p_vsts_nopaste); |
| 3812 | p_vsts_nopaste = p_vsts && p_vsts != empty_option |
| 3813 | ? vim_strsave(p_vsts) : NULL; |
| 3814 | #endif |
| 3815 | } |
| 3816 | |
| 3817 | // Always set the option values, also when 'paste' is set when it is |
| 3818 | // already on. Set options for each buffer. |
| 3819 | FOR_ALL_BUFFERS(buf) |
| 3820 | { |
| 3821 | buf->b_p_tw = 0; // textwidth is 0 |
| 3822 | buf->b_p_wm = 0; // wrapmargin is 0 |
| 3823 | buf->b_p_sts = 0; // softtabstop is 0 |
| 3824 | buf->b_p_ai = 0; // no auto-indent |
| 3825 | buf->b_p_et = 0; // no expandtab |
| 3826 | #ifdef FEAT_VARTABS |
| 3827 | if (buf->b_p_vsts) |
| 3828 | free_string_option(buf->b_p_vsts); |
| 3829 | buf->b_p_vsts = empty_option; |
| 3830 | VIM_CLEAR(buf->b_p_vsts_array); |
| 3831 | #endif |
| 3832 | } |
| 3833 | |
| 3834 | // set global options |
| 3835 | p_sm = 0; // no showmatch |
| 3836 | p_sta = 0; // no smarttab |
| 3837 | if (p_ru) |
| 3838 | status_redraw_all(); // redraw to remove the ruler |
| 3839 | p_ru = 0; // no ruler |
| 3840 | #ifdef FEAT_RIGHTLEFT |
| 3841 | p_ri = 0; // no reverse insert |
| 3842 | p_hkmap = 0; // no Hebrew keyboard |
| 3843 | #endif |
| 3844 | // set global values for local buffer options |
| 3845 | p_tw = 0; |
| 3846 | p_wm = 0; |
| 3847 | p_sts = 0; |
| 3848 | p_ai = 0; |
| 3849 | #ifdef FEAT_VARTABS |
| 3850 | if (p_vsts) |
| 3851 | free_string_option(p_vsts); |
| 3852 | p_vsts = empty_option; |
| 3853 | #endif |
| 3854 | } |
| 3855 | |
| 3856 | // Paste switched from on to off: Restore saved values. |
| 3857 | else if (old_p_paste) |
| 3858 | { |
| 3859 | // restore options for each buffer |
| 3860 | FOR_ALL_BUFFERS(buf) |
| 3861 | { |
| 3862 | buf->b_p_tw = buf->b_p_tw_nopaste; |
| 3863 | buf->b_p_wm = buf->b_p_wm_nopaste; |
| 3864 | buf->b_p_sts = buf->b_p_sts_nopaste; |
| 3865 | buf->b_p_ai = buf->b_p_ai_nopaste; |
| 3866 | buf->b_p_et = buf->b_p_et_nopaste; |
| 3867 | #ifdef FEAT_VARTABS |
| 3868 | if (buf->b_p_vsts) |
| 3869 | free_string_option(buf->b_p_vsts); |
| 3870 | buf->b_p_vsts = buf->b_p_vsts_nopaste |
| 3871 | ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option; |
| 3872 | vim_free(buf->b_p_vsts_array); |
| 3873 | if (buf->b_p_vsts && buf->b_p_vsts != empty_option) |
| 3874 | (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); |
| 3875 | else |
| 3876 | buf->b_p_vsts_array = NULL; |
| 3877 | #endif |
| 3878 | } |
| 3879 | |
| 3880 | // restore global options |
| 3881 | p_sm = save_sm; |
| 3882 | p_sta = save_sta; |
| 3883 | if (p_ru != save_ru) |
| 3884 | status_redraw_all(); // redraw to draw the ruler |
| 3885 | p_ru = save_ru; |
| 3886 | #ifdef FEAT_RIGHTLEFT |
| 3887 | p_ri = save_ri; |
| 3888 | p_hkmap = save_hkmap; |
| 3889 | #endif |
| 3890 | // set global values for local buffer options |
| 3891 | p_ai = p_ai_nopaste; |
| 3892 | p_et = p_et_nopaste; |
| 3893 | p_sts = p_sts_nopaste; |
| 3894 | p_tw = p_tw_nopaste; |
| 3895 | p_wm = p_wm_nopaste; |
| 3896 | #ifdef FEAT_VARTABS |
| 3897 | if (p_vsts) |
| 3898 | free_string_option(p_vsts); |
| 3899 | p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; |
| 3900 | #endif |
| 3901 | } |
| 3902 | |
| 3903 | old_p_paste = p_paste; |
| 3904 | |
| 3905 | return NULL; |
| 3906 | } |
| 3907 | |
| 3908 | |
| 3909 | #ifdef FEAT_QUICKFIX |
| 3910 | /* |
| 3911 | * Process the updated 'previewwindow' option value. |
| 3912 | */ |
| 3913 | char * |
| 3914 | did_set_previewwindow(optset_T *args) |
| 3915 | { |
| 3916 | if (!curwin->w_p_pvw) |
| 3917 | return NULL; |
| 3918 | |
| 3919 | // There can be only one window with 'previewwindow' set. |
| 3920 | win_T *win; |
| 3921 | |
| 3922 | FOR_ALL_WINDOWS(win) |
| 3923 | if (win->w_p_pvw && win != curwin) |
| 3924 | { |
| 3925 | curwin->w_p_pvw = FALSE; |
| 3926 | args->os_doskip = TRUE; |
| 3927 | return e_preview_window_already_exists; |
| 3928 | } |
| 3929 | |
| 3930 | return NULL; |
| 3931 | } |
| 3932 | #endif |
| 3933 | |
| 3934 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
| 3935 | /* |
| 3936 | * Process the new 'pyxversion' option value. |
| 3937 | */ |
| 3938 | char * |
| 3939 | did_set_pyxversion(optset_T *args UNUSED) |
| 3940 | { |
| 3941 | char *errmsg = NULL; |
| 3942 | |
| 3943 | if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) |
| 3944 | errmsg = e_invalid_argument; |
| 3945 | |
| 3946 | return errmsg; |
| 3947 | } |
| 3948 | #endif |
| 3949 | |
| 3950 | /* |
| 3951 | * Process the updated 'readonly' option value. |
| 3952 | */ |
| 3953 | char * |
| 3954 | did_set_readonly(optset_T *args) |
| 3955 | { |
| 3956 | // when 'readonly' is reset globally, also reset readonlymode |
| 3957 | if (!curbuf->b_p_ro && (args->os_flags & OPT_LOCAL) == 0) |
| 3958 | readonlymode = FALSE; |
| 3959 | |
| 3960 | // when 'readonly' is set may give W10 again |
| 3961 | if (curbuf->b_p_ro) |
| 3962 | curbuf->b_did_warn = FALSE; |
| 3963 | |
| 3964 | redraw_titles(); |
| 3965 | |
| 3966 | return NULL; |
| 3967 | } |
| 3968 | |
| 3969 | /* |
| 3970 | * Process the updated 'scrollbind' option value. |
| 3971 | */ |
| 3972 | char * |
| 3973 | did_set_scrollbind(optset_T *args UNUSED) |
| 3974 | { |
| 3975 | // when 'scrollbind' is set: snapshot the current position to avoid a jump |
| 3976 | // at the end of normal_cmd() |
| 3977 | if (!curwin->w_p_scb) |
| 3978 | return NULL; |
| 3979 | |
| 3980 | do_check_scrollbind(FALSE); |
| 3981 | curwin->w_scbind_pos = curwin->w_topline; |
| 3982 | return NULL; |
| 3983 | } |
| 3984 | |
| 3985 | #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) |
| 3986 | /* |
| 3987 | * Process the updated 'shellslash' option value. |
| 3988 | */ |
| 3989 | char * |
| 3990 | did_set_shellslash(optset_T *args UNUSED) |
| 3991 | { |
| 3992 | if (p_ssl) |
| 3993 | { |
| 3994 | psepc = '/'; |
| 3995 | psepcN = '\\'; |
| 3996 | pseps[0] = '/'; |
| 3997 | } |
| 3998 | else |
| 3999 | { |
| 4000 | psepc = '\\'; |
| 4001 | psepcN = '/'; |
| 4002 | pseps[0] = '\\'; |
| 4003 | } |
| 4004 | |
| 4005 | // need to adjust the file name arguments and buffer names. |
| 4006 | buflist_slash_adjust(); |
| 4007 | alist_slash_adjust(); |
| 4008 | # ifdef FEAT_EVAL |
| 4009 | scriptnames_slash_adjust(); |
| 4010 | # endif |
| 4011 | return NULL; |
| 4012 | } |
| 4013 | #endif |
| 4014 | |
| 4015 | /* |
| 4016 | * Process the new 'shiftwidth' or the 'tabstop' option value. |
| 4017 | */ |
| 4018 | char * |
| 4019 | did_set_shiftwidth_tabstop(optset_T *args) |
| 4020 | { |
| 4021 | long *pp = (long *)args->os_varp; |
| 4022 | char *errmsg = NULL; |
| 4023 | |
| 4024 | if (curbuf->b_p_sw < 0) |
| 4025 | { |
| 4026 | errmsg = e_argument_must_be_positive; |
| 4027 | #ifdef FEAT_VARTABS |
| 4028 | // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. |
| 4029 | curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0 |
| 4030 | ? tabstop_first(curbuf->b_p_vts_array) |
| 4031 | : curbuf->b_p_ts; |
| 4032 | #else |
| 4033 | curbuf->b_p_sw = curbuf->b_p_ts; |
| 4034 | #endif |
| 4035 | } |
| 4036 | |
| 4037 | #ifdef FEAT_FOLDING |
| 4038 | if (foldmethodIsIndent(curwin)) |
| 4039 | foldUpdateAll(curwin); |
| 4040 | #endif |
| 4041 | // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: |
| 4042 | // parse 'cinoptions'. |
| 4043 | if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) |
| 4044 | parse_cino(curbuf); |
| 4045 | |
| 4046 | return errmsg; |
| 4047 | } |
| 4048 | |
| 4049 | /* |
| 4050 | * Process the new 'showtabline' option value. |
| 4051 | */ |
| 4052 | char * |
| 4053 | did_set_showtabline(optset_T *args UNUSED) |
| 4054 | { |
| 4055 | shell_new_rows(); // recompute window positions and heights |
| 4056 | return NULL; |
| 4057 | } |
| 4058 | |
| 4059 | /* |
| 4060 | * Process the updated 'smoothscroll' option value. |
| 4061 | */ |
| 4062 | char * |
| 4063 | did_set_smoothscroll(optset_T *args UNUSED) |
| 4064 | { |
| 4065 | if (curwin->w_p_sms) |
| 4066 | return NULL; |
| 4067 | |
| 4068 | curwin->w_skipcol = 0; |
| 4069 | changed_line_abv_curs(); |
| 4070 | return NULL; |
| 4071 | } |
| 4072 | |
| 4073 | #if defined(FEAT_SPELL) || defined(PROTO) |
| 4074 | /* |
| 4075 | * Process the updated 'spell' option value. |
| 4076 | */ |
| 4077 | char * |
| 4078 | did_set_spell(optset_T *args UNUSED) |
| 4079 | { |
| 4080 | if (curwin->w_p_spell) |
| 4081 | return parse_spelllang(curwin); |
| 4082 | |
| 4083 | return NULL; |
| 4084 | } |
| 4085 | #endif |
| 4086 | |
| 4087 | /* |
| 4088 | * Process the updated 'swapfile' option value. |
| 4089 | */ |
| 4090 | char * |
| 4091 | did_set_swapfile(optset_T *args UNUSED) |
| 4092 | { |
| 4093 | // when 'swf' is set, create swapfile, when reset remove swapfile |
| 4094 | if (curbuf->b_p_swf && p_uc) |
| 4095 | ml_open_file(curbuf); // create the swap file |
| 4096 | else |
| 4097 | // no need to reset curbuf->b_may_swap, ml_open_file() will check |
| 4098 | // buf->b_p_swf |
| 4099 | mf_close_file(curbuf, TRUE); // remove the swap file |
| 4100 | return NULL; |
| 4101 | } |
| 4102 | |
| 4103 | #if defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4104 | char * |
| 4105 | did_set_termguicolors(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 4106 | { |
| 4107 | # ifdef FEAT_VTP |
| 4108 | // Do not turn on 'tgc' when 24-bit colors are not supported. |
| 4109 | if ( |
| 4110 | # ifdef VIMDLL |
| 4111 | !gui.in_use && !gui.starting && |
| 4112 | # endif |
| 4113 | !has_vtp_working()) |
| 4114 | { |
| 4115 | p_tgc = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4116 | args->os_doskip = TRUE; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 4117 | return e_24_bit_colors_are_not_supported_on_this_environment; |
| 4118 | } |
| 4119 | if (is_term_win32()) |
| 4120 | swap_tcap(); |
| 4121 | # endif |
| 4122 | # ifdef FEAT_GUI |
| 4123 | if (!gui.in_use && !gui.starting) |
| 4124 | # endif |
| 4125 | highlight_gui_started(); |
| 4126 | # ifdef FEAT_VTP |
| 4127 | // reset t_Co |
| 4128 | if (is_term_win32()) |
| 4129 | { |
| 4130 | control_console_color_rgb(); |
| 4131 | set_termname(T_NAME); |
| 4132 | init_highlight(TRUE, FALSE); |
| 4133 | } |
| 4134 | # endif |
| 4135 | # ifdef FEAT_TERMINAL |
| 4136 | term_update_colors_all(); |
| 4137 | term_update_palette_all(); |
| 4138 | term_update_wincolor_all(); |
| 4139 | # endif |
| 4140 | |
| 4141 | return NULL; |
| 4142 | } |
| 4143 | #endif |
| 4144 | |
| 4145 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4146 | * Process the updated 'terse' option value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4147 | */ |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4148 | char * |
| 4149 | did_set_terse(optset_T *args UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4150 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4151 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4152 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4153 | // when 'terse' is set change 'shortmess' |
| 4154 | p = vim_strchr(p_shm, SHM_SEARCH); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4155 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4156 | // insert 's' in p_shm |
| 4157 | if (p_terse && p == NULL) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4158 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4159 | STRCPY(IObuff, p_shm); |
| 4160 | STRCAT(IObuff, "s"); |
| 4161 | set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4162 | } |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4163 | // remove 's' from p_shm |
| 4164 | else if (!p_terse && p != NULL) |
| 4165 | STRMOVE(p, p + 1); |
| 4166 | return NULL; |
| 4167 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4168 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4169 | /* |
| 4170 | * Process the updated 'textauto' option value. |
| 4171 | */ |
| 4172 | char * |
| 4173 | did_set_textauto(optset_T *args) |
| 4174 | { |
| 4175 | // when 'textauto' is set or reset also change 'fileformats' |
| 4176 | set_string_option_direct((char_u *)"ffs", -1, |
| 4177 | p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", |
| 4178 | OPT_FREE | args->os_flags, 0); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4179 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4180 | return NULL; |
| 4181 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4182 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4183 | /* |
| 4184 | * Process the updated 'textmode' option value. |
| 4185 | */ |
| 4186 | char * |
| 4187 | did_set_textmode(optset_T *args) |
| 4188 | { |
| 4189 | // when 'textmode' is set or reset also change 'fileformat' |
| 4190 | set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, args->os_flags); |
| 4191 | |
| 4192 | return NULL; |
| 4193 | } |
| 4194 | |
| 4195 | /* |
| 4196 | * Process the new 'textwidth' option value. |
| 4197 | */ |
| 4198 | char * |
| 4199 | did_set_textwidth(optset_T *args UNUSED) |
| 4200 | { |
| 4201 | char *errmsg = NULL; |
| 4202 | |
| 4203 | if (curbuf->b_p_tw < 0) |
| 4204 | { |
| 4205 | errmsg = e_argument_must_be_positive; |
| 4206 | curbuf->b_p_tw = 0; |
| 4207 | } |
| 4208 | #ifdef FEAT_SYN_HL |
| 4209 | { |
| 4210 | win_T *wp; |
| 4211 | tabpage_T *tp; |
| 4212 | |
| 4213 | FOR_ALL_TAB_WINDOWS(tp, wp) |
| 4214 | check_colorcolumn(wp); |
| 4215 | } |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4216 | #endif |
| 4217 | |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 4218 | return errmsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4222 | * Process the updated 'title' or the 'icon' option value. |
| 4223 | */ |
| 4224 | char * |
| 4225 | did_set_title_icon(optset_T *args UNUSED) |
| 4226 | { |
| 4227 | // when 'title' changed, may need to change the title; same for 'icon' |
| 4228 | did_set_title(); |
| 4229 | return NULL; |
| 4230 | } |
| 4231 | |
| 4232 | /* |
| 4233 | * Process the new 'titlelen' option value. |
| 4234 | */ |
| 4235 | char * |
| 4236 | did_set_titlelen(optset_T *args) |
| 4237 | { |
| 4238 | long old_value = args->os_oldval.number; |
| 4239 | char *errmsg = NULL; |
| 4240 | |
| 4241 | // if 'titlelen' has changed, redraw the title |
| 4242 | if (p_titlelen < 0) |
| 4243 | { |
| 4244 | errmsg = e_argument_must_be_positive; |
| 4245 | p_titlelen = 85; |
| 4246 | } |
| 4247 | if (starting != NO_SCREEN && old_value != p_titlelen) |
| 4248 | need_maketitle = TRUE; |
| 4249 | |
| 4250 | return errmsg; |
| 4251 | } |
| 4252 | |
| 4253 | #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
| 4254 | /* |
| 4255 | * Process the updated 'undofile' option value. |
| 4256 | */ |
| 4257 | char * |
| 4258 | did_set_undofile(optset_T *args) |
| 4259 | { |
| 4260 | // Only take action when the option was set. |
| 4261 | if (!curbuf->b_p_udf && !p_udf) |
| 4262 | return NULL; |
| 4263 | |
| 4264 | // When reset we do not delete the undo file, the option may be set again |
| 4265 | // without making any changes in between. |
| 4266 | char_u hash[UNDO_HASH_SIZE]; |
| 4267 | buf_T *save_curbuf = curbuf; |
| 4268 | |
| 4269 | FOR_ALL_BUFFERS(curbuf) |
| 4270 | { |
| 4271 | // When 'undofile' is set globally: for every buffer, otherwise |
| 4272 | // only for the current buffer: Try to read in the undofile, |
| 4273 | // if one exists, the buffer wasn't changed and the buffer was |
| 4274 | // loaded |
| 4275 | if ((curbuf == save_curbuf |
| 4276 | || (args->os_flags & OPT_GLOBAL) |
| 4277 | || args->os_flags == 0) |
| 4278 | && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) |
| 4279 | { |
| 4280 | #ifdef FEAT_CRYPT |
Christian Brabandt | aae5834 | 2023-04-23 17:50:22 +0100 | [diff] [blame] | 4281 | if (crypt_method_is_sodium(crypt_get_method_nr(curbuf))) |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4282 | continue; |
| 4283 | #endif |
| 4284 | u_compute_hash(hash); |
| 4285 | u_read_undo(NULL, hash, curbuf->b_fname); |
| 4286 | } |
| 4287 | } |
| 4288 | curbuf = save_curbuf; |
| 4289 | |
| 4290 | return NULL; |
| 4291 | } |
| 4292 | #endif |
| 4293 | |
| 4294 | /* |
| 4295 | * Process the new global 'undolevels' option value. |
| 4296 | */ |
| 4297 | static void |
| 4298 | update_global_undolevels(long value, long old_value) |
| 4299 | { |
| 4300 | // sync undo before 'undolevels' changes |
| 4301 | |
| 4302 | // use the old value, otherwise u_sync() may not work properly |
| 4303 | p_ul = old_value; |
| 4304 | u_sync(TRUE); |
| 4305 | p_ul = value; |
| 4306 | } |
| 4307 | |
| 4308 | /* |
| 4309 | * Process the new buffer local 'undolevels' option value. |
| 4310 | */ |
| 4311 | static void |
| 4312 | update_buflocal_undolevels(long value, long old_value) |
| 4313 | { |
| 4314 | // use the old value, otherwise u_sync() may not work properly |
| 4315 | curbuf->b_p_ul = old_value; |
| 4316 | u_sync(TRUE); |
| 4317 | curbuf->b_p_ul = value; |
| 4318 | } |
| 4319 | |
| 4320 | /* |
| 4321 | * Process the new 'undolevels' option value. |
| 4322 | */ |
| 4323 | char * |
| 4324 | did_set_undolevels(optset_T *args) |
| 4325 | { |
| 4326 | long *pp = (long *)args->os_varp; |
| 4327 | |
| 4328 | if (pp == &p_ul) // global 'undolevels' |
| 4329 | update_global_undolevels(args->os_newval.number, |
| 4330 | args->os_oldval.number); |
| 4331 | else if (pp == &curbuf->b_p_ul) // buffer local 'undolevels' |
| 4332 | update_buflocal_undolevels(args->os_newval.number, |
| 4333 | args->os_oldval.number); |
| 4334 | |
| 4335 | return NULL; |
| 4336 | } |
| 4337 | |
| 4338 | /* |
| 4339 | * Process the new 'updatecount' option value. |
| 4340 | */ |
| 4341 | char * |
| 4342 | did_set_updatecount(optset_T *args) |
| 4343 | { |
| 4344 | long old_value = args->os_oldval.number; |
| 4345 | char *errmsg = NULL; |
| 4346 | |
| 4347 | // when 'updatecount' changes from zero to non-zero, open swap files |
| 4348 | if (p_uc < 0) |
| 4349 | { |
| 4350 | errmsg = e_argument_must_be_positive; |
| 4351 | p_uc = 100; |
| 4352 | } |
| 4353 | if (p_uc && !old_value) |
| 4354 | ml_open_files(); |
| 4355 | |
| 4356 | return errmsg; |
| 4357 | } |
| 4358 | |
| 4359 | /* |
| 4360 | * Process the updated 'weirdinvert' option value. |
| 4361 | */ |
| 4362 | char * |
| 4363 | did_set_weirdinvert(optset_T *args) |
| 4364 | { |
| 4365 | // When 'weirdinvert' changed, set/reset 't_xs'. |
| 4366 | // Then set 'weirdinvert' according to value of 't_xs'. |
| 4367 | if (p_wiv && !args->os_oldval.boolean) |
| 4368 | T_XS = (char_u *)"y"; |
| 4369 | else if (!p_wiv && args->os_oldval.boolean) |
| 4370 | T_XS = empty_option; |
| 4371 | p_wiv = (*T_XS != NUL); |
| 4372 | |
| 4373 | return NULL; |
| 4374 | } |
| 4375 | |
| 4376 | /* |
| 4377 | * Process the new 'window' option value. |
| 4378 | */ |
| 4379 | char * |
| 4380 | did_set_window(optset_T *args UNUSED) |
| 4381 | { |
| 4382 | if (p_window < 1) |
| 4383 | p_window = 1; |
| 4384 | else if (p_window >= Rows) |
| 4385 | p_window = Rows - 1; |
| 4386 | return NULL; |
| 4387 | } |
| 4388 | |
| 4389 | /* |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4390 | * Process the new 'winheight' or the 'helpheight' option value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4391 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4392 | char * |
| 4393 | did_set_winheight_helpheight(optset_T *args) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4394 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4395 | long *pp = (long *)args->os_varp; |
| 4396 | char *errmsg = NULL; |
| 4397 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4398 | if (p_wh < 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4399 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4400 | errmsg = e_argument_must_be_positive; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4401 | p_wh = 1; |
| 4402 | } |
| 4403 | if (p_wmh > p_wh) |
| 4404 | { |
| 4405 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 4406 | p_wh = p_wmh; |
| 4407 | } |
| 4408 | if (p_hh < 0) |
| 4409 | { |
| 4410 | errmsg = e_argument_must_be_positive; |
| 4411 | p_hh = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4414 | // Change window height NOW |
| 4415 | if (!ONE_WINDOW) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4416 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4417 | if (pp == &p_wh && curwin->w_height < p_wh) |
| 4418 | win_setheight((int)p_wh); |
| 4419 | if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) |
| 4420 | win_setheight((int)p_hh); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4421 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4422 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4423 | return errmsg; |
| 4424 | } |
| 4425 | |
| 4426 | /* |
| 4427 | * Process the new 'winminheight' option value. |
| 4428 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4429 | char * |
| 4430 | did_set_winminheight(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4431 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4432 | char *errmsg = NULL; |
| 4433 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4434 | if (p_wmh < 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4435 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4436 | errmsg = e_argument_must_be_positive; |
| 4437 | p_wmh = 0; |
| 4438 | } |
| 4439 | if (p_wmh > p_wh) |
| 4440 | { |
| 4441 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 4442 | p_wmh = p_wh; |
| 4443 | } |
| 4444 | win_setminheight(); |
| 4445 | |
| 4446 | return errmsg; |
| 4447 | } |
| 4448 | |
| 4449 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4450 | * Process the new 'winminwidth' option value. |
| 4451 | */ |
| 4452 | char * |
| 4453 | did_set_winminwidth(optset_T *args UNUSED) |
| 4454 | { |
| 4455 | char *errmsg = NULL; |
| 4456 | |
| 4457 | if (p_wmw < 0) |
| 4458 | { |
| 4459 | errmsg = e_argument_must_be_positive; |
| 4460 | p_wmw = 0; |
| 4461 | } |
| 4462 | if (p_wmw > p_wiw) |
| 4463 | { |
| 4464 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4465 | p_wmw = p_wiw; |
| 4466 | } |
| 4467 | win_setminwidth(); |
| 4468 | |
| 4469 | return errmsg; |
| 4470 | } |
| 4471 | |
| 4472 | /* |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4473 | * Process the new 'winwidth' option value. |
| 4474 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4475 | char * |
| 4476 | did_set_winwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4477 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4478 | char *errmsg = NULL; |
| 4479 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4480 | if (p_wiw < 1) |
| 4481 | { |
| 4482 | errmsg = e_argument_must_be_positive; |
| 4483 | p_wiw = 1; |
| 4484 | } |
| 4485 | if (p_wmw > p_wiw) |
| 4486 | { |
| 4487 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4488 | p_wiw = p_wmw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4489 | } |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 4490 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4491 | // Change window width NOW |
| 4492 | if (!ONE_WINDOW && curwin->w_width < p_wiw) |
| 4493 | win_setwidth((int)p_wiw); |
| 4494 | |
| 4495 | return errmsg; |
| 4496 | } |
| 4497 | |
| 4498 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4499 | * Process the updated 'wrap' option value. |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4500 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4501 | char * |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4502 | did_set_wrap(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4503 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4504 | // If 'wrap' is set, set w_leftcol to zero. |
| 4505 | if (curwin->w_p_wrap) |
| 4506 | curwin->w_leftcol = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4507 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4511 | * Set the value of a boolean option, and take care of side effects. |
| 4512 | * Returns NULL for success, or an error message for an error. |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4513 | */ |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4514 | static char * |
| 4515 | set_bool_option( |
| 4516 | int opt_idx, // index in options[] table |
| 4517 | char_u *varp, // pointer to the option variable |
| 4518 | int value, // new value |
| 4519 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4520 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4521 | int old_value = *(int *)varp; |
| 4522 | #if defined(FEAT_EVAL) |
| 4523 | int old_global_value = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4524 | #endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4525 | char *errmsg = NULL; |
| 4526 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4527 | // Disallow changing some options from secure mode |
| 4528 | if ((secure |
| 4529 | #ifdef HAVE_SANDBOX |
| 4530 | || sandbox != 0 |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4531 | #endif |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4532 | ) && (options[opt_idx].flags & P_SECURE)) |
| 4533 | return e_not_allowed_here; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4534 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4535 | #if defined(FEAT_EVAL) |
| 4536 | // Save the global value before changing anything. This is needed as for |
| 4537 | // a global-only option setting the "local value" in fact sets the global |
| 4538 | // value (since there is only one value). |
| 4539 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4540 | old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), |
| 4541 | OPT_GLOBAL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4542 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4543 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4544 | *(int *)varp = value; // set the new value |
| 4545 | #ifdef FEAT_EVAL |
| 4546 | // Remember where the option was set. |
| 4547 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 5c6dbcb | 2017-08-30 22:00:20 +0200 | [diff] [blame] | 4548 | #endif |
| 4549 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4550 | #ifdef FEAT_GUI |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4551 | need_mouse_correct = TRUE; |
Bram Moolenaar | 325b7a2 | 2004-07-05 15:58:32 +0000 | [diff] [blame] | 4552 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4553 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4554 | // May set global value for local option. |
| 4555 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4556 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4557 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4558 | // Handle side effects of changing a bool option. |
| 4559 | if (options[opt_idx].opt_did_set_cb != NULL) |
| 4560 | { |
| 4561 | optset_T args; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4562 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4563 | CLEAR_FIELD(args); |
| 4564 | args.os_varp = varp; |
| 4565 | args.os_flags = opt_flags; |
| 4566 | args.os_oldval.boolean = old_value; |
| 4567 | args.os_newval.boolean = value; |
| 4568 | args.os_errbuf = NULL; |
| 4569 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
| 4570 | if (args.os_doskip) |
| 4571 | return errmsg; |
| 4572 | } |
| 4573 | |
| 4574 | // after handling side effects, call autocommand |
| 4575 | |
| 4576 | options[opt_idx].flags |= P_WAS_SET; |
| 4577 | |
| 4578 | #if defined(FEAT_EVAL) |
| 4579 | apply_optionset_autocmd(opt_idx, opt_flags, |
| 4580 | (long)(old_value ? TRUE : FALSE), |
| 4581 | (long)(old_global_value ? TRUE : FALSE), |
| 4582 | (long)(value ? TRUE : FALSE), NULL); |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 4583 | #endif |
| 4584 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4585 | comp_col(); // in case 'ruler' or 'showcmd' changed |
| 4586 | if (curwin->w_curswant != MAXCOL |
| 4587 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
| 4588 | curwin->w_set_curswant = TRUE; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4589 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4590 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 4591 | check_redraw(options[opt_idx].flags); |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4592 | |
| 4593 | return errmsg; |
| 4594 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4595 | |
| 4596 | /* |
| 4597 | * Check the bounds of numeric options. |
| 4598 | */ |
| 4599 | static char * |
| 4600 | check_num_option_bounds( |
| 4601 | long *pp, |
| 4602 | long old_value, |
| 4603 | long old_Rows, |
| 4604 | long old_Columns, |
| 4605 | char *errbuf, |
| 4606 | size_t errbuflen, |
| 4607 | char *errmsg) |
| 4608 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4609 | if (Rows < min_rows() && full_screen) |
| 4610 | { |
| 4611 | if (errbuf != NULL) |
| 4612 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4613 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4614 | _(e_need_at_least_nr_lines), min_rows()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4615 | errmsg = errbuf; |
| 4616 | } |
| 4617 | Rows = min_rows(); |
| 4618 | } |
| 4619 | if (Columns < MIN_COLUMNS && full_screen) |
| 4620 | { |
| 4621 | if (errbuf != NULL) |
| 4622 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4623 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4624 | _(e_need_at_least_nr_columns), MIN_COLUMNS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4625 | errmsg = errbuf; |
| 4626 | } |
| 4627 | Columns = MIN_COLUMNS; |
| 4628 | } |
Bram Moolenaar | e057d40 | 2013-06-30 17:51:51 +0200 | [diff] [blame] | 4629 | limit_screen_size(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4630 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4631 | // If the screen (shell) height has been changed, assume it is the |
| 4632 | // physical screenheight. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4633 | if (old_Rows != Rows || old_Columns != Columns) |
| 4634 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4635 | // Changing the screen size is not allowed while updating the screen. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4636 | if (updating_screen) |
| 4637 | *pp = old_value; |
| 4638 | else if (full_screen |
| 4639 | #ifdef FEAT_GUI |
| 4640 | && !gui.starting |
| 4641 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4642 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4643 | set_shellsize((int)Columns, (int)Rows, TRUE); |
| 4644 | else |
| 4645 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4646 | // Postpone the resizing; check the size and cmdline position for |
| 4647 | // messages. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4648 | check_shellsize(); |
| 4649 | if (cmdline_row > Rows - p_ch && Rows > p_ch) |
| 4650 | cmdline_row = Rows - p_ch; |
| 4651 | } |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4652 | if (p_window >= Rows || !option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 4653 | p_window = Rows - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4656 | if (curbuf->b_p_ts <= 0) |
| 4657 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4658 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4659 | curbuf->b_p_ts = 8; |
| 4660 | } |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 4661 | else if (curbuf->b_p_ts > TABSTOP_MAX) |
| 4662 | { |
| 4663 | errmsg = e_invalid_argument; |
| 4664 | curbuf->b_p_ts = 8; |
| 4665 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4666 | if (p_tm < 0) |
| 4667 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4668 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4669 | p_tm = 0; |
| 4670 | } |
| 4671 | if ((curwin->w_p_scr <= 0 |
| 4672 | || (curwin->w_p_scr > curwin->w_height |
| 4673 | && curwin->w_height > 0)) |
| 4674 | && full_screen) |
| 4675 | { |
| 4676 | if (pp == &(curwin->w_p_scr)) |
| 4677 | { |
| 4678 | if (curwin->w_p_scr != 0) |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4679 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4680 | win_comp_scroll(curwin); |
| 4681 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4682 | // If 'scroll' became invalid because of a side effect silently adjust |
| 4683 | // it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4684 | else if (curwin->w_p_scr <= 0) |
| 4685 | curwin->w_p_scr = 1; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4686 | else // curwin->w_p_scr > curwin->w_height |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4687 | curwin->w_p_scr = curwin->w_height; |
| 4688 | } |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4689 | if (p_hi < 0) |
| 4690 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4691 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4692 | p_hi = 0; |
| 4693 | } |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4694 | else if (p_hi > 10000) |
| 4695 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4696 | errmsg = e_invalid_argument; |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4697 | p_hi = 10000; |
| 4698 | } |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4699 | if (p_re < 0 || p_re > 2) |
| 4700 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4701 | errmsg = e_invalid_argument; |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4702 | p_re = 0; |
| 4703 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4704 | if (p_report < 0) |
| 4705 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4706 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4707 | p_report = 1; |
| 4708 | } |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 4709 | if ((p_sj < -100 || p_sj >= Rows) && full_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4710 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4711 | if (Rows != old_Rows) // Rows changed, just adjust p_sj |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4712 | p_sj = Rows / 2; |
| 4713 | else |
| 4714 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4715 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4716 | p_sj = 1; |
| 4717 | } |
| 4718 | } |
| 4719 | if (p_so < 0 && full_screen) |
| 4720 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4721 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4722 | p_so = 0; |
| 4723 | } |
| 4724 | if (p_siso < 0 && full_screen) |
| 4725 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4726 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4727 | p_siso = 0; |
| 4728 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4729 | if (p_cwh < 1) |
| 4730 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4731 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4732 | p_cwh = 1; |
| 4733 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4734 | if (p_ut < 0) |
| 4735 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4736 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4737 | p_ut = 2000; |
| 4738 | } |
| 4739 | if (p_ss < 0) |
| 4740 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4741 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4742 | p_ss = 0; |
| 4743 | } |
| 4744 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4745 | return errmsg; |
| 4746 | } |
| 4747 | |
| 4748 | /* |
| 4749 | * Set the value of a number option, and take care of side effects. |
| 4750 | * Returns NULL for success, or an error message for an error. |
| 4751 | */ |
| 4752 | static char * |
| 4753 | set_num_option( |
| 4754 | int opt_idx, // index in options[] table |
| 4755 | char_u *varp, // pointer to the option variable |
| 4756 | long value, // new value |
| 4757 | char *errbuf, // buffer for error messages |
| 4758 | size_t errbuflen, // length of "errbuf" |
| 4759 | int opt_flags) // OPT_LOCAL, OPT_GLOBAL, |
| 4760 | // OPT_MODELINE, etc. |
| 4761 | { |
| 4762 | char *errmsg = NULL; |
| 4763 | long old_value = *(long *)varp; |
| 4764 | #if defined(FEAT_EVAL) |
| 4765 | long old_global_value = 0; // only used when setting a local and |
| 4766 | // global option |
| 4767 | #endif |
| 4768 | long old_Rows = Rows; // remember old Rows |
| 4769 | long old_Columns = Columns; // remember old Columns |
| 4770 | long *pp = (long *)varp; |
| 4771 | |
| 4772 | // Disallow changing some options from secure mode. |
| 4773 | if ((secure |
| 4774 | #ifdef HAVE_SANDBOX |
| 4775 | || sandbox != 0 |
| 4776 | #endif |
| 4777 | ) && (options[opt_idx].flags & P_SECURE)) |
| 4778 | return e_not_allowed_here; |
| 4779 | |
| 4780 | #if defined(FEAT_EVAL) |
| 4781 | // Save the global value before changing anything. This is needed as for |
| 4782 | // a global-only option setting the "local value" in fact sets the global |
| 4783 | // value (since there is only one value). |
| 4784 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4785 | old_global_value = *(long *)get_varp_scope(&(options[opt_idx]), |
| 4786 | OPT_GLOBAL); |
| 4787 | #endif |
| 4788 | |
| 4789 | *pp = value; |
| 4790 | #ifdef FEAT_EVAL |
| 4791 | // Remember where the option was set. |
| 4792 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
| 4793 | #endif |
| 4794 | #ifdef FEAT_GUI |
| 4795 | need_mouse_correct = TRUE; |
| 4796 | #endif |
| 4797 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4798 | // Invoke the option specific callback function to validate and apply the |
| 4799 | // new value. |
| 4800 | if (options[opt_idx].opt_did_set_cb != NULL) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4801 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4802 | optset_T args; |
| 4803 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4804 | CLEAR_FIELD(args); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4805 | args.os_varp = varp; |
| 4806 | args.os_flags = opt_flags; |
| 4807 | args.os_oldval.number = old_value; |
| 4808 | args.os_newval.number = value; |
Yegappan Lakshmanan | 6d611de | 2023-02-25 11:59:33 +0000 | [diff] [blame] | 4809 | args.os_errbuf = NULL; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4810 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4813 | // Check the bounds for numeric options here |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4814 | errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns, |
| 4815 | errbuf, errbuflen, errmsg); |
| 4816 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4817 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4818 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4819 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; |
| 4820 | |
| 4821 | options[opt_idx].flags |= P_WAS_SET; |
| 4822 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 4823 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 4824 | apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value, |
| 4825 | value, errmsg); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4826 | #endif |
| 4827 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4828 | comp_col(); // in case 'columns' or 'ls' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4829 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 4830 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4831 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 4832 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 4833 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4834 | |
| 4835 | return errmsg; |
| 4836 | } |
| 4837 | |
| 4838 | /* |
| 4839 | * Called after an option changed: check if something needs to be redrawn. |
| 4840 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4841 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4842 | check_redraw(long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4843 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4844 | // 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] | 4845 | int doclear = (flags & P_RCLR) == P_RCLR; |
| 4846 | int all = ((flags & P_RALL) == P_RALL || doclear); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4847 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4848 | if ((flags & P_RSTAT) || all) // mark all status lines dirty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4849 | status_redraw_all(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4850 | |
| 4851 | if ((flags & P_RBUF) || (flags & P_RWIN) || all) |
| 4852 | changed_window_setting(); |
| 4853 | if (flags & P_RBUF) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4854 | redraw_curbuf_later(UPD_NOT_VALID); |
Bram Moolenaar | a2477fd | 2016-12-03 15:13:20 +0100 | [diff] [blame] | 4855 | if (flags & P_RWINONLY) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4856 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 4857 | if (doclear) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4858 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4859 | else if (all) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4860 | redraw_all_later(UPD_NOT_VALID); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | /* |
| 4864 | * Find index for option 'arg'. |
| 4865 | * Return -1 if not found. |
| 4866 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4867 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4868 | findoption(char_u *arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4869 | { |
| 4870 | int opt_idx; |
| 4871 | char *s, *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4872 | static short quick_tab[27] = {0, 0}; // quick access table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4873 | int is_term_opt; |
| 4874 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4875 | // For first call: Initialize the quick-access table. |
| 4876 | // It contains the index for the first option that starts with a certain |
| 4877 | // letter. There are 26 letters, plus the first "t_" option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4878 | if (quick_tab[1] == 0) |
| 4879 | { |
| 4880 | p = options[0].fullname; |
| 4881 | for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4882 | { |
| 4883 | if (s[0] != p[0]) |
| 4884 | { |
| 4885 | if (s[0] == 't' && s[1] == '_') |
| 4886 | quick_tab[26] = opt_idx; |
| 4887 | else |
| 4888 | quick_tab[CharOrdLow(s[0])] = opt_idx; |
| 4889 | } |
| 4890 | p = s; |
| 4891 | } |
| 4892 | } |
| 4893 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4894 | // Check for name starting with an illegal character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4895 | if (arg[0] < 'a' || arg[0] > 'z') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4896 | return -1; |
| 4897 | |
| 4898 | is_term_opt = (arg[0] == 't' && arg[1] == '_'); |
| 4899 | if (is_term_opt) |
| 4900 | opt_idx = quick_tab[26]; |
| 4901 | else |
| 4902 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4903 | for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4904 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4905 | if (STRCMP(arg, s) == 0) // match full name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4906 | break; |
| 4907 | } |
| 4908 | if (s == NULL && !is_term_opt) |
| 4909 | { |
| 4910 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4911 | for ( ; options[opt_idx].fullname != NULL; opt_idx++) |
| 4912 | { |
| 4913 | s = options[opt_idx].shortname; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4914 | if (s != NULL && STRCMP(arg, s) == 0) // match short name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4915 | break; |
| 4916 | s = NULL; |
| 4917 | } |
| 4918 | } |
| 4919 | if (s == NULL) |
| 4920 | opt_idx = -1; |
| 4921 | return opt_idx; |
| 4922 | } |
| 4923 | |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 4924 | #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME) \ |
| 4925 | || defined(FEAT_SPELL) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4926 | /* |
| 4927 | * Get the value for an option. |
| 4928 | * |
| 4929 | * Returns: |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4930 | * Number option: gov_number, *numval gets value. |
Bram Moolenaar | a725149 | 2021-01-02 16:53:13 +0100 | [diff] [blame] | 4931 | * Toggle option: gov_bool, *numval gets value. |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4932 | * String option: gov_string, *stringval gets allocated string. |
| 4933 | * Hidden Number option: gov_hidden_number. |
| 4934 | * Hidden Toggle option: gov_hidden_bool. |
| 4935 | * Hidden String option: gov_hidden_string. |
| 4936 | * Unknown option: gov_unknown. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4937 | * |
| 4938 | * "flagsp" (if not NULL) is set to the option flags (P_xxxx). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4939 | */ |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4940 | getoption_T |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4941 | get_option_value( |
| 4942 | char_u *name, |
| 4943 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4944 | char_u **stringval, // NULL when only checking existence |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4945 | int *flagsp, |
| 4946 | int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4947 | { |
| 4948 | int opt_idx; |
| 4949 | char_u *varp; |
| 4950 | |
| 4951 | opt_idx = findoption(name); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4952 | if (opt_idx < 0) // option not in the table |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4953 | { |
| 4954 | int key; |
| 4955 | |
| 4956 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4957 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4958 | { |
| 4959 | char_u key_name[2]; |
| 4960 | char_u *p; |
| 4961 | |
Bram Moolenaar | 10c75c4 | 2021-12-28 20:53:30 +0000 | [diff] [blame] | 4962 | if (flagsp != NULL) |
| 4963 | *flagsp = 0; // terminal option has no flags |
| 4964 | |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4965 | // check for a terminal option |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4966 | if (key < 0) |
| 4967 | { |
| 4968 | key_name[0] = KEY2TERMCAP0(key); |
| 4969 | key_name[1] = KEY2TERMCAP1(key); |
| 4970 | } |
| 4971 | else |
| 4972 | { |
| 4973 | key_name[0] = KS_KEY; |
| 4974 | key_name[1] = (key & 0xff); |
| 4975 | } |
| 4976 | p = find_termcode(key_name); |
| 4977 | if (p != NULL) |
| 4978 | { |
| 4979 | if (stringval != NULL) |
| 4980 | *stringval = vim_strsave(p); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4981 | return gov_string; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4982 | } |
| 4983 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4984 | return gov_unknown; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4985 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4986 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4987 | varp = get_varp_scope(&(options[opt_idx]), scope); |
| 4988 | |
| 4989 | if (flagsp != NULL) |
| 4990 | // Return the P_xxxx option flags. |
| 4991 | *flagsp = options[opt_idx].flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4992 | |
| 4993 | if (options[opt_idx].flags & P_STRING) |
| 4994 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4995 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4996 | return gov_hidden_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4997 | if (stringval != NULL) |
| 4998 | { |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 4999 | if ((char_u **)varp == &p_pt) // 'pastetoggle' |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 5000 | *stringval = str2special_save(*(char_u **)(varp), FALSE, |
| 5001 | FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5002 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5003 | // never return the value of the crypt key |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 5004 | else if ((char_u **)varp == &curbuf->b_p_key |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 5005 | && **(char_u **)(varp) != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5006 | *stringval = vim_strsave((char_u *)"*****"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5007 | #endif |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 5008 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5009 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 5010 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5011 | return gov_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5014 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5015 | return (options[opt_idx].flags & P_NUM) |
| 5016 | ? gov_hidden_number : gov_hidden_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5017 | if (options[opt_idx].flags & P_NUM) |
| 5018 | *numval = *(long *)varp; |
| 5019 | else |
| 5020 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5021 | // Special case: 'modified' is b_changed, but we also want to consider |
| 5022 | // it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5023 | if ((int *)varp == &curbuf->b_changed) |
| 5024 | *numval = curbufIsChanged(); |
| 5025 | else |
Bram Moolenaar | 2acfbed | 2016-07-01 23:14:02 +0200 | [diff] [blame] | 5026 | *numval = (long) *(int *)varp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5027 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5028 | return (options[opt_idx].flags & P_NUM) ? gov_number : gov_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5029 | } |
| 5030 | #endif |
| 5031 | |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5032 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5033 | /* |
| 5034 | * Returns the option attributes and its value. Unlike the above function it |
| 5035 | * will return either global value or local value of the option depending on |
| 5036 | * what was requested, but it will never return global value if it was |
| 5037 | * requested to return local one and vice versa. Neither it will return |
| 5038 | * buffer-local value if it was requested to return window-local one. |
| 5039 | * |
| 5040 | * Pretends that option is absent if it is not present in the requested scope |
| 5041 | * (i.e. has no global, window-local or buffer-local value depending on |
| 5042 | * opt_type). Uses |
| 5043 | * |
| 5044 | * Returned flags: |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 5045 | * 0 hidden or unknown option, also option that does not have requested |
| 5046 | * type (see SREQ_* in vim.h) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5047 | * see SOPT_* in vim.h for other flags |
| 5048 | * |
| 5049 | * Possible opt_type values: see SREQ_* in vim.h |
| 5050 | */ |
| 5051 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5052 | get_option_value_strict( |
| 5053 | char_u *name, |
| 5054 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5055 | char_u **stringval, // NULL when only obtaining attributes |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5056 | int opt_type, |
| 5057 | void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5058 | { |
| 5059 | int opt_idx; |
Bram Moolenaar | 6800186 | 2013-05-11 13:45:05 +0200 | [diff] [blame] | 5060 | char_u *varp = NULL; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5061 | struct vimoption *p; |
| 5062 | int r = 0; |
| 5063 | |
| 5064 | opt_idx = findoption(name); |
| 5065 | if (opt_idx < 0) |
| 5066 | return 0; |
| 5067 | |
| 5068 | p = &(options[opt_idx]); |
| 5069 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5070 | // Hidden option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5071 | if (p->var == NULL) |
| 5072 | return 0; |
| 5073 | |
| 5074 | if (p->flags & P_BOOL) |
| 5075 | r |= SOPT_BOOL; |
| 5076 | else if (p->flags & P_NUM) |
| 5077 | r |= SOPT_NUM; |
| 5078 | else if (p->flags & P_STRING) |
| 5079 | r |= SOPT_STRING; |
| 5080 | |
| 5081 | if (p->indir == PV_NONE) |
| 5082 | { |
| 5083 | if (opt_type == SREQ_GLOBAL) |
| 5084 | r |= SOPT_GLOBAL; |
| 5085 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5086 | return 0; // Did not request global-only option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5087 | } |
| 5088 | else |
| 5089 | { |
| 5090 | if (p->indir & PV_BOTH) |
| 5091 | r |= SOPT_GLOBAL; |
| 5092 | else if (opt_type == SREQ_GLOBAL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5093 | return 0; // Requested global option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5094 | |
| 5095 | if (p->indir & PV_WIN) |
| 5096 | { |
| 5097 | if (opt_type == SREQ_BUF) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5098 | return 0; // Did not request window-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5099 | else |
| 5100 | r |= SOPT_WIN; |
| 5101 | } |
| 5102 | else if (p->indir & PV_BUF) |
| 5103 | { |
| 5104 | if (opt_type == SREQ_WIN) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5105 | return 0; // Did not request buffer-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5106 | else |
| 5107 | r |= SOPT_BUF; |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | if (stringval == NULL) |
| 5112 | return r; |
| 5113 | |
| 5114 | if (opt_type == SREQ_GLOBAL) |
| 5115 | varp = p->var; |
| 5116 | else |
| 5117 | { |
| 5118 | if (opt_type == SREQ_BUF) |
| 5119 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5120 | // Special case: 'modified' is b_changed, but we also want to |
| 5121 | // consider it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5122 | if (p->indir == PV_MOD) |
| 5123 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5124 | *numval = bufIsChanged((buf_T *)from); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5125 | varp = NULL; |
| 5126 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 5127 | # ifdef FEAT_CRYPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5128 | else if (p->indir == PV_KEY) |
| 5129 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5130 | // never return the value of the crypt key |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5131 | *stringval = NULL; |
| 5132 | varp = NULL; |
| 5133 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 5134 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5135 | else |
| 5136 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5137 | buf_T *save_curbuf = curbuf; |
| 5138 | |
| 5139 | // only getting a pointer, no need to use aucmd_prepbuf() |
| 5140 | curbuf = (buf_T *)from; |
| 5141 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5142 | varp = get_varp(p); |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5143 | curbuf = save_curbuf; |
| 5144 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | else if (opt_type == SREQ_WIN) |
| 5148 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5149 | win_T *save_curwin = curwin; |
| 5150 | |
| 5151 | curwin = (win_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5152 | curbuf = curwin->w_buffer; |
| 5153 | varp = get_varp(p); |
| 5154 | curwin = save_curwin; |
| 5155 | curbuf = curwin->w_buffer; |
| 5156 | } |
| 5157 | if (varp == p->var) |
| 5158 | return (r | SOPT_UNSET); |
| 5159 | } |
| 5160 | |
| 5161 | if (varp != NULL) |
| 5162 | { |
| 5163 | if (p->flags & P_STRING) |
| 5164 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 5165 | else if (p->flags & P_NUM) |
| 5166 | *numval = *(long *) varp; |
| 5167 | else |
| 5168 | *numval = *(int *)varp; |
| 5169 | } |
| 5170 | |
| 5171 | return r; |
| 5172 | } |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5173 | |
| 5174 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5175 | * Iterate over options. First argument is a pointer to a pointer to a |
| 5176 | * structure inside options[] array, second is option type like in the above |
| 5177 | * function. |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5178 | * |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5179 | * 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] | 5180 | * and caller needs the very first value. |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5181 | * 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] | 5182 | * first argument to NULL. |
| 5183 | * |
| 5184 | * Returns full option name for current option on each call. |
| 5185 | */ |
| 5186 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5187 | option_iter_next(void **option, int opt_type) |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5188 | { |
| 5189 | struct vimoption *ret = NULL; |
| 5190 | do |
| 5191 | { |
| 5192 | if (*option == NULL) |
| 5193 | *option = (void *) options; |
| 5194 | else if (((struct vimoption *) (*option))->fullname == NULL) |
| 5195 | { |
| 5196 | *option = NULL; |
| 5197 | return NULL; |
| 5198 | } |
| 5199 | else |
| 5200 | *option = (void *) (((struct vimoption *) (*option)) + 1); |
| 5201 | |
| 5202 | ret = ((struct vimoption *) (*option)); |
| 5203 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5204 | // Hidden option |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5205 | if (ret->var == NULL) |
| 5206 | { |
| 5207 | ret = NULL; |
| 5208 | continue; |
| 5209 | } |
| 5210 | |
| 5211 | switch (opt_type) |
| 5212 | { |
| 5213 | case SREQ_GLOBAL: |
| 5214 | if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH)) |
| 5215 | ret = NULL; |
| 5216 | break; |
| 5217 | case SREQ_BUF: |
| 5218 | if (!(ret->indir & PV_BUF)) |
| 5219 | ret = NULL; |
| 5220 | break; |
| 5221 | case SREQ_WIN: |
| 5222 | if (!(ret->indir & PV_WIN)) |
| 5223 | ret = NULL; |
| 5224 | break; |
| 5225 | default: |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 5226 | internal_error("option_iter_next()"); |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5227 | return NULL; |
| 5228 | } |
| 5229 | } |
| 5230 | while (ret == NULL); |
| 5231 | |
| 5232 | return (char_u *)ret->fullname; |
| 5233 | } |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5234 | #endif |
| 5235 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5236 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5237 | * Return the flags for the option at 'opt_idx'. |
| 5238 | */ |
| 5239 | long_u |
| 5240 | get_option_flags(int opt_idx) |
| 5241 | { |
| 5242 | return options[opt_idx].flags; |
| 5243 | } |
| 5244 | |
| 5245 | /* |
| 5246 | * Set a flag for the option at 'opt_idx'. |
| 5247 | */ |
| 5248 | void |
| 5249 | set_option_flag(int opt_idx, long_u flag) |
| 5250 | { |
| 5251 | options[opt_idx].flags |= flag; |
| 5252 | } |
| 5253 | |
| 5254 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5255 | * Returns TRUE if the option at 'opt_idx' is a global option |
| 5256 | */ |
| 5257 | int |
| 5258 | is_global_option(int opt_idx) |
| 5259 | { |
| 5260 | return options[opt_idx].indir == PV_NONE; |
| 5261 | } |
| 5262 | |
| 5263 | /* |
| 5264 | * Returns TRUE if the option at 'opt_idx' is a global option which also has a |
| 5265 | * local value. |
| 5266 | */ |
| 5267 | int |
| 5268 | is_global_local_option(int opt_idx) |
| 5269 | { |
| 5270 | return options[opt_idx].indir & PV_BOTH; |
| 5271 | } |
| 5272 | |
| 5273 | /* |
| 5274 | * Returns TRUE if the option at 'opt_idx' is a window-local option |
| 5275 | */ |
| 5276 | int |
| 5277 | is_window_local_option(int opt_idx) |
| 5278 | { |
| 5279 | return options[opt_idx].var == VAR_WIN; |
| 5280 | } |
| 5281 | |
| 5282 | /* |
| 5283 | * Returns TRUE if the option at 'opt_idx' is a hidden option |
| 5284 | */ |
| 5285 | int |
| 5286 | is_hidden_option(int opt_idx) |
| 5287 | { |
| 5288 | return options[opt_idx].var == NULL; |
| 5289 | } |
| 5290 | |
| 5291 | #if defined(FEAT_CRYPT) || defined(PROTO) |
| 5292 | /* |
| 5293 | * Returns TRUE if the option at 'opt_idx' is a crypt key option |
| 5294 | */ |
| 5295 | int |
| 5296 | is_crypt_key_option(int opt_idx) |
| 5297 | { |
| 5298 | return options[opt_idx].indir == PV_KEY; |
| 5299 | } |
| 5300 | #endif |
| 5301 | |
| 5302 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5303 | * Set the value of option "name". |
| 5304 | * Use "string" for string options, use "number" for other options. |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5305 | * |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5306 | * Returns NULL on success or an untranslated error message on error. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5307 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 5308 | char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5309 | set_option_value( |
| 5310 | char_u *name, |
| 5311 | long number, |
| 5312 | char_u *string, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5313 | int opt_flags) // OPT_LOCAL or 0 (both) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5314 | { |
| 5315 | int opt_idx; |
| 5316 | char_u *varp; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 5317 | long_u flags; |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5318 | static char errbuf[80]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5319 | |
| 5320 | opt_idx = findoption(name); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 5321 | if (opt_idx < 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5322 | { |
| 5323 | int key; |
| 5324 | |
| 5325 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5326 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5327 | { |
| 5328 | char_u key_name[2]; |
| 5329 | |
| 5330 | if (key < 0) |
| 5331 | { |
| 5332 | key_name[0] = KEY2TERMCAP0(key); |
| 5333 | key_name[1] = KEY2TERMCAP1(key); |
| 5334 | } |
| 5335 | else |
| 5336 | { |
| 5337 | key_name[0] = KS_KEY; |
| 5338 | key_name[1] = (key & 0xff); |
| 5339 | } |
| 5340 | add_termcode(key_name, string, FALSE); |
| 5341 | if (full_screen) |
| 5342 | ttest(FALSE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 5343 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5344 | return NULL; |
| 5345 | } |
| 5346 | |
Bram Moolenaar | ac78dd4 | 2022-01-02 19:25:26 +0000 | [diff] [blame] | 5347 | semsg(_(e_unknown_option_str_2), name); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5348 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5349 | else |
| 5350 | { |
| 5351 | flags = options[opt_idx].flags; |
| 5352 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5353 | // Disallow changing some options in the sandbox |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5354 | if (sandbox > 0 && (flags & P_SECURE)) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5355 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 5356 | emsg(_(e_not_allowed_in_sandbox)); |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5357 | return NULL; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5358 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5359 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5360 | if (flags & P_STRING) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5361 | 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] | 5362 | |
| 5363 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 5364 | if (varp != NULL) // hidden option is not changed |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5365 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5366 | if (number == 0 && string != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5367 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5368 | int idx; |
| 5369 | |
| 5370 | // Either we are given a string or we are setting option |
| 5371 | // to zero. |
| 5372 | for (idx = 0; string[idx] == '0'; ++idx) |
| 5373 | ; |
| 5374 | if (string[idx] != NUL || idx == 0) |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5375 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5376 | // There's another character after zeros or the string |
| 5377 | // is empty. In both cases, we are trying to set a |
| 5378 | // num option using a string. |
| 5379 | semsg(_(e_number_required_after_str_equal_str), |
| 5380 | name, string); |
| 5381 | return NULL; // do nothing as we hit an error |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5382 | |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5383 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5384 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5385 | if (flags & P_NUM) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5386 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5387 | return set_num_option(opt_idx, varp, number, |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5388 | errbuf, sizeof(errbuf), opt_flags); |
| 5389 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5390 | else |
| 5391 | return set_bool_option(opt_idx, varp, (int)number, opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5392 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5393 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5394 | } |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5395 | return NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | /* |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5399 | * Call set_option_value() and when an error is returned report it. |
| 5400 | */ |
| 5401 | void |
| 5402 | set_option_value_give_err( |
| 5403 | char_u *name, |
| 5404 | long number, |
| 5405 | char_u *string, |
| 5406 | int opt_flags) // OPT_LOCAL or 0 (both) |
| 5407 | { |
| 5408 | char *errmsg = set_option_value(name, number, string, opt_flags); |
| 5409 | |
| 5410 | if (errmsg != NULL) |
| 5411 | emsg(_(errmsg)); |
| 5412 | } |
| 5413 | |
| 5414 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5415 | * Get the terminal code for a terminal option. |
| 5416 | * Returns NULL when not found. |
| 5417 | */ |
| 5418 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5419 | get_term_code(char_u *tname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5420 | { |
| 5421 | int opt_idx; |
| 5422 | char_u *varp; |
| 5423 | |
| 5424 | if (tname[0] != 't' || tname[1] != '_' || |
| 5425 | tname[2] == NUL || tname[3] == NUL) |
| 5426 | return NULL; |
| 5427 | if ((opt_idx = findoption(tname)) >= 0) |
| 5428 | { |
| 5429 | varp = get_varp(&(options[opt_idx])); |
| 5430 | if (varp != NULL) |
| 5431 | varp = *(char_u **)(varp); |
| 5432 | return varp; |
| 5433 | } |
| 5434 | return find_termcode(tname + 2); |
| 5435 | } |
| 5436 | |
| 5437 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5438 | get_highlight_default(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5439 | { |
| 5440 | int i; |
| 5441 | |
| 5442 | i = findoption((char_u *)"hl"); |
| 5443 | if (i >= 0) |
| 5444 | return options[i].def_val[VI_DEFAULT]; |
| 5445 | return (char_u *)NULL; |
| 5446 | } |
| 5447 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5448 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5449 | get_encoding_default(void) |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5450 | { |
| 5451 | int i; |
| 5452 | |
| 5453 | i = findoption((char_u *)"enc"); |
| 5454 | if (i >= 0) |
| 5455 | return options[i].def_val[VI_DEFAULT]; |
| 5456 | return (char_u *)NULL; |
| 5457 | } |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5458 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5459 | #if defined(FEAT_QUICKFIX) || defined(PROTO) |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5460 | int |
| 5461 | is_option_allocated(char *name) |
| 5462 | { |
| 5463 | int idx = findoption((char_u *)name); |
| 5464 | |
| 5465 | return idx >= 0 && (options[idx].flags & P_ALLOCED); |
| 5466 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5467 | #endif |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5468 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5469 | /* |
| 5470 | * 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] | 5471 | * When "has_lt" is true there is a '<' before "*arg_arg". |
| 5472 | * Returns 0 when the key is not recognized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5473 | */ |
| 5474 | static int |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5475 | find_key_option(char_u *arg_arg, int has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5476 | { |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5477 | int key = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5478 | int modifiers; |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5479 | char_u *arg = arg_arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5480 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5481 | // Don't use get_special_key_code() for t_xx, we don't want it to call |
| 5482 | // add_termcap_entry(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5483 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 5484 | key = TERMCAP2KEY(arg[2], arg[3]); |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5485 | else if (has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5486 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5487 | --arg; // put arg at the '<' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5488 | modifiers = 0; |
Bram Moolenaar | ebe9d34 | 2020-05-30 21:52:54 +0200 | [diff] [blame] | 5489 | key = find_special_key(&arg, &modifiers, |
| 5490 | FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5491 | if (modifiers) // can't handle modifiers here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5492 | key = 0; |
| 5493 | } |
| 5494 | return key; |
| 5495 | } |
| 5496 | |
| 5497 | /* |
| 5498 | * if 'all' == 0: show changed options |
| 5499 | * if 'all' == 1: show all normal options |
| 5500 | * if 'all' == 2: show all terminal options |
| 5501 | */ |
| 5502 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5503 | showoptions( |
| 5504 | int all, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5505 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5506 | { |
| 5507 | struct vimoption *p; |
| 5508 | int col; |
| 5509 | int isterm; |
| 5510 | char_u *varp; |
| 5511 | struct vimoption **items; |
| 5512 | int item_count; |
| 5513 | int run; |
| 5514 | int row, rows; |
| 5515 | int cols; |
| 5516 | int i; |
| 5517 | int len; |
| 5518 | |
| 5519 | #define INC 20 |
| 5520 | #define GAP 3 |
| 5521 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5522 | items = ALLOC_MULT(struct vimoption *, OPTION_COUNT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5523 | if (items == NULL) |
| 5524 | return; |
| 5525 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5526 | // Highlight title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5527 | if (all == 2) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5528 | msg_puts_title(_("\n--- Terminal codes ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5529 | else if (opt_flags & OPT_GLOBAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5530 | msg_puts_title(_("\n--- Global option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5531 | else if (opt_flags & OPT_LOCAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5532 | msg_puts_title(_("\n--- Local option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5533 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5534 | msg_puts_title(_("\n--- Options ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5535 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5536 | // Do the loop two times: |
| 5537 | // 1. display the short items |
| 5538 | // 2. display the long items (only strings and numbers) |
| 5539 | // When "opt_flags" has OPT_ONECOLUMN do everything in run 2. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5540 | for (run = 1; run <= 2 && !got_int; ++run) |
| 5541 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5542 | // collect the items in items[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5543 | item_count = 0; |
| 5544 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5545 | { |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5546 | // apply :filter /pat/ |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5547 | if (message_filtered((char_u *)p->fullname)) |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5548 | continue; |
| 5549 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5550 | varp = NULL; |
| 5551 | isterm = istermoption(p); |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5552 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5553 | { |
| 5554 | if (p->indir != PV_NONE && !isterm) |
| 5555 | varp = get_varp_scope(p, opt_flags); |
| 5556 | } |
| 5557 | else |
| 5558 | varp = get_varp(p); |
| 5559 | if (varp != NULL |
| 5560 | && ((all == 2 && isterm) |
| 5561 | || (all == 1 && !isterm) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5562 | || (all == 0 && !optval_default(p, varp, p_cp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5563 | { |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5564 | if (opt_flags & OPT_ONECOLUMN) |
| 5565 | len = Columns; |
| 5566 | else if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5567 | len = 1; // a toggle option fits always |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5568 | else |
| 5569 | { |
| 5570 | option_value2string(p, opt_flags); |
| 5571 | len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; |
| 5572 | } |
| 5573 | if ((len <= INC - GAP && run == 1) || |
| 5574 | (len > INC - GAP && run == 2)) |
| 5575 | items[item_count++] = p; |
| 5576 | } |
| 5577 | } |
| 5578 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5579 | // display the items |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5580 | if (run == 1) |
| 5581 | { |
| 5582 | cols = (Columns + GAP - 3) / INC; |
| 5583 | if (cols == 0) |
| 5584 | cols = 1; |
| 5585 | rows = (item_count + cols - 1) / cols; |
| 5586 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5587 | else // run == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5588 | rows = item_count; |
| 5589 | for (row = 0; row < rows && !got_int; ++row) |
| 5590 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5591 | msg_putchar('\n'); // go to next line |
| 5592 | if (got_int) // 'q' typed in more |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5593 | break; |
| 5594 | col = 0; |
| 5595 | for (i = row; i < item_count; i += rows) |
| 5596 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5597 | msg_col = col; // make columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5598 | showoneopt(items[i], opt_flags); |
| 5599 | col += INC; |
| 5600 | } |
| 5601 | out_flush(); |
| 5602 | ui_breakcheck(); |
| 5603 | } |
| 5604 | } |
| 5605 | vim_free(items); |
| 5606 | } |
| 5607 | |
| 5608 | /* |
| 5609 | * Return TRUE if option "p" has its default value. |
| 5610 | */ |
| 5611 | static int |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5612 | optval_default(struct vimoption *p, char_u *varp, int compatible) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5613 | { |
| 5614 | int dvi; |
| 5615 | |
| 5616 | if (varp == NULL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5617 | return TRUE; // hidden option is always at default |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5618 | dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5619 | if (p->flags & P_NUM) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5620 | return (*(long *)varp == (long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5621 | if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5622 | // the cast to long is required for Manx C, long_i is |
| 5623 | // needed for MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5624 | return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5625 | // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5626 | return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); |
| 5627 | } |
| 5628 | |
| 5629 | /* |
| 5630 | * showoneopt: show the value of one option |
| 5631 | * must not be called with a hidden option! |
| 5632 | */ |
| 5633 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5634 | showoneopt( |
| 5635 | struct vimoption *p, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5636 | int opt_flags) // OPT_LOCAL or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5637 | { |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5638 | char_u *varp; |
| 5639 | int save_silent = silent_mode; |
| 5640 | |
| 5641 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5642 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5643 | |
| 5644 | varp = get_varp_scope(p, opt_flags); |
| 5645 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5646 | // for 'modified' we also need to check if 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5647 | if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed |
| 5648 | ? !curbufIsChanged() : !*(int *)varp)) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5649 | msg_puts("no"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5650 | else if ((p->flags & P_BOOL) && *(int *)varp < 0) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5651 | msg_puts("--"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5652 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5653 | msg_puts(" "); |
| 5654 | msg_puts(p->fullname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5655 | if (!(p->flags & P_BOOL)) |
| 5656 | { |
| 5657 | msg_putchar('='); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5658 | // put value string in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5659 | option_value2string(p, opt_flags); |
| 5660 | msg_outtrans(NameBuff); |
| 5661 | } |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5662 | |
| 5663 | silent_mode = save_silent; |
| 5664 | info_message = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | /* |
| 5668 | * Write modified options as ":set" commands to a file. |
| 5669 | * |
| 5670 | * There are three values for "opt_flags": |
| 5671 | * OPT_GLOBAL: Write global option values and fresh values of |
| 5672 | * buffer-local options (used for start of a session |
| 5673 | * file). |
| 5674 | * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for |
| 5675 | * curwin (used for a vimrc file). |
| 5676 | * OPT_LOCAL: Write buffer-local option values for curbuf, fresh |
| 5677 | * and local values for window-local options of |
| 5678 | * curwin. Local values are also written when at the |
| 5679 | * default value, because a modeline or autocommand |
| 5680 | * may have set them when doing ":edit file" and the |
| 5681 | * user has set them back at the default or fresh |
| 5682 | * value. |
| 5683 | * When "local_only" is TRUE, don't write fresh |
| 5684 | * values, only local values (for ":mkview"). |
| 5685 | * (fresh value = value used for a new buffer or window for a local option). |
| 5686 | * |
| 5687 | * Return FAIL on error, OK otherwise. |
| 5688 | */ |
| 5689 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5690 | makeset(FILE *fd, int opt_flags, int local_only) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5691 | { |
| 5692 | struct vimoption *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5693 | char_u *varp; // currently used value |
| 5694 | char_u *varp_fresh; // local value |
| 5695 | char_u *varp_local = NULL; // fresh value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5696 | char *cmd; |
| 5697 | int round; |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5698 | int pri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5699 | |
| 5700 | /* |
| 5701 | * The options that don't have a default (terminal name, columns, lines) |
| 5702 | * are never written. Terminal options are also not written. |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5703 | * Do the loop over "options[]" twice: once for options with the |
| 5704 | * P_PRI_MKRC flag and once without. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5705 | */ |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5706 | for (pri = 1; pri >= 0; --pri) |
| 5707 | { |
| 5708 | for (p = &options[0]; !istermoption(p); p++) |
| 5709 | if (!(p->flags & P_NO_MKRC) |
| 5710 | && !istermoption(p) |
| 5711 | && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5712 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5713 | // skip global option when only doing locals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5714 | if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) |
| 5715 | continue; |
| 5716 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5717 | // Do not store options like 'bufhidden' and 'syntax' in a vimrc |
| 5718 | // file, they are always buffer-specific. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5719 | if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) |
| 5720 | continue; |
| 5721 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5722 | // Global values are only written when not at the default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5723 | varp = get_varp_scope(p, opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5724 | if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5725 | continue; |
| 5726 | |
Bram Moolenaar | d23b714 | 2021-04-17 21:04:34 +0200 | [diff] [blame] | 5727 | if ((opt_flags & OPT_SKIPRTP) && (p->var == (char_u *)&p_rtp |
| 5728 | || p->var == (char_u *)&p_pp)) |
Bram Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 5729 | continue; |
| 5730 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5731 | round = 2; |
| 5732 | if (p->indir != PV_NONE) |
| 5733 | { |
| 5734 | if (p->var == VAR_WIN) |
| 5735 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5736 | // skip window-local option when only doing globals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5737 | if (!(opt_flags & OPT_LOCAL)) |
| 5738 | continue; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5739 | // When fresh value of window-local option is not at the |
| 5740 | // default, need to write it too. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5741 | if (!(opt_flags & OPT_GLOBAL) && !local_only) |
| 5742 | { |
| 5743 | varp_fresh = get_varp_scope(p, OPT_GLOBAL); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5744 | if (!optval_default(p, varp_fresh, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5745 | { |
| 5746 | round = 1; |
| 5747 | varp_local = varp; |
| 5748 | varp = varp_fresh; |
| 5749 | } |
| 5750 | } |
| 5751 | } |
| 5752 | } |
| 5753 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5754 | // Round 1: fresh value for window-local options. |
| 5755 | // Round 2: other values |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5756 | for ( ; round <= 2; varp = varp_local, ++round) |
| 5757 | { |
| 5758 | if (round == 1 || (opt_flags & OPT_GLOBAL)) |
| 5759 | cmd = "set"; |
| 5760 | else |
| 5761 | cmd = "setlocal"; |
| 5762 | |
| 5763 | if (p->flags & P_BOOL) |
| 5764 | { |
| 5765 | if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) |
| 5766 | return FAIL; |
| 5767 | } |
| 5768 | else if (p->flags & P_NUM) |
| 5769 | { |
| 5770 | if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) |
| 5771 | return FAIL; |
| 5772 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5773 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5774 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5775 | int do_endif = FALSE; |
| 5776 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5777 | // Don't set 'syntax' and 'filetype' again if the value is |
| 5778 | // already right, avoids reloading the syntax file. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5779 | if ( |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 5780 | #if defined(FEAT_SYN_HL) |
| 5781 | p->indir == PV_SYN || |
| 5782 | #endif |
| 5783 | p->indir == PV_FT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5784 | { |
| 5785 | if (fprintf(fd, "if &%s != '%s'", p->fullname, |
| 5786 | *(char_u **)(varp)) < 0 |
| 5787 | || put_eol(fd) < 0) |
| 5788 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5789 | do_endif = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5790 | } |
| 5791 | if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5792 | p->flags) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5793 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5794 | if (do_endif) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5795 | { |
| 5796 | if (put_line(fd, "endif") == FAIL) |
| 5797 | return FAIL; |
| 5798 | } |
| 5799 | } |
| 5800 | } |
| 5801 | } |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5802 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5803 | return OK; |
| 5804 | } |
| 5805 | |
| 5806 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 5807 | /* |
| 5808 | * Generate set commands for the local fold options only. Used when |
| 5809 | * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". |
| 5810 | */ |
| 5811 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5812 | makefoldset(FILE *fd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5813 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5814 | if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5815 | # ifdef FEAT_EVAL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5816 | || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5817 | == FAIL |
| 5818 | # endif |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5819 | || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5820 | == FAIL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5821 | || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5822 | == FAIL |
| 5823 | || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL |
| 5824 | || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL |
| 5825 | || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL |
| 5826 | || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL |
| 5827 | ) |
| 5828 | return FAIL; |
| 5829 | |
| 5830 | return OK; |
| 5831 | } |
| 5832 | #endif |
| 5833 | |
| 5834 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5835 | put_setstring( |
| 5836 | FILE *fd, |
| 5837 | char *cmd, |
| 5838 | char *name, |
| 5839 | char_u **valuep, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5840 | long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5841 | { |
| 5842 | char_u *s; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5843 | char_u *buf = NULL; |
| 5844 | char_u *part = NULL; |
| 5845 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5846 | |
| 5847 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5848 | return FAIL; |
| 5849 | if (*valuep != NULL) |
| 5850 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5851 | // Output 'pastetoggle' as key names. For other |
| 5852 | // options some characters have to be escaped with |
| 5853 | // CTRL-V or backslash |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5854 | if (valuep == &p_pt) |
| 5855 | { |
| 5856 | s = *valuep; |
| 5857 | while (*s != NUL) |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 5858 | if (put_escstr(fd, str2special(&s, FALSE, FALSE), 2) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5859 | return FAIL; |
| 5860 | } |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5861 | // expand the option value, replace $HOME by ~ |
| 5862 | else if ((flags & P_EXPAND) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5863 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5864 | int size = (int)STRLEN(*valuep) + 1; |
| 5865 | |
| 5866 | // replace home directory in the whole option value into "buf" |
| 5867 | buf = alloc(size); |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5868 | if (buf == NULL) |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5869 | goto fail; |
| 5870 | home_replace(NULL, *valuep, buf, size, FALSE); |
| 5871 | |
| 5872 | // If the option value is longer than MAXPATHL, we need to append |
Bram Moolenaar | 32aa102 | 2019-11-02 22:54:41 +0100 | [diff] [blame] | 5873 | // each comma separated part of the option separately, so that it |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5874 | // can be expanded when read back. |
| 5875 | if (size >= MAXPATHL && (flags & P_COMMA) != 0 |
| 5876 | && vim_strchr(*valuep, ',') != NULL) |
| 5877 | { |
| 5878 | part = alloc(size); |
| 5879 | if (part == NULL) |
| 5880 | goto fail; |
| 5881 | |
| 5882 | // write line break to clear the option, e.g. ':set rtp=' |
| 5883 | if (put_eol(fd) == FAIL) |
| 5884 | goto fail; |
| 5885 | |
| 5886 | p = buf; |
| 5887 | while (*p != NUL) |
| 5888 | { |
| 5889 | // for each comma separated option part, append value to |
| 5890 | // the option, :set rtp+=value |
| 5891 | if (fprintf(fd, "%s %s+=", cmd, name) < 0) |
| 5892 | goto fail; |
| 5893 | (void)copy_option_part(&p, part, size, ","); |
| 5894 | if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) |
| 5895 | goto fail; |
| 5896 | } |
| 5897 | vim_free(buf); |
| 5898 | vim_free(part); |
| 5899 | return OK; |
| 5900 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5901 | if (put_escstr(fd, buf, 2) == FAIL) |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5902 | { |
| 5903 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5904 | return FAIL; |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5905 | } |
| 5906 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5907 | } |
| 5908 | else if (put_escstr(fd, *valuep, 2) == FAIL) |
| 5909 | return FAIL; |
| 5910 | } |
| 5911 | if (put_eol(fd) < 0) |
| 5912 | return FAIL; |
| 5913 | return OK; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5914 | fail: |
| 5915 | vim_free(buf); |
| 5916 | vim_free(part); |
| 5917 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5921 | put_setnum( |
| 5922 | FILE *fd, |
| 5923 | char *cmd, |
| 5924 | char *name, |
| 5925 | long *valuep) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5926 | { |
| 5927 | long wc; |
| 5928 | |
| 5929 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5930 | return FAIL; |
| 5931 | if (wc_use_keyname((char_u *)valuep, &wc)) |
| 5932 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5933 | // print 'wildchar' and 'wildcharm' as a key name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5934 | if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) |
| 5935 | return FAIL; |
| 5936 | } |
| 5937 | else if (fprintf(fd, "%ld", *valuep) < 0) |
| 5938 | return FAIL; |
| 5939 | if (put_eol(fd) < 0) |
| 5940 | return FAIL; |
| 5941 | return OK; |
| 5942 | } |
| 5943 | |
| 5944 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5945 | put_setbool( |
| 5946 | FILE *fd, |
| 5947 | char *cmd, |
| 5948 | char *name, |
| 5949 | int value) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5950 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5951 | if (value < 0) // global/local option using global value |
Bram Moolenaar | 893de92 | 2007-10-02 18:40:57 +0000 | [diff] [blame] | 5952 | return OK; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5953 | if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 |
| 5954 | || put_eol(fd) < 0) |
| 5955 | return FAIL; |
| 5956 | return OK; |
| 5957 | } |
| 5958 | |
| 5959 | /* |
| 5960 | * Clear all the terminal options. |
| 5961 | * If the option has been allocated, free the memory. |
| 5962 | * Terminal options are never hidden or indirect. |
| 5963 | */ |
| 5964 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5965 | clear_termoptions(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5966 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5967 | // Reset a few things before clearing the old options. This may cause |
| 5968 | // outputting a few things that the terminal doesn't understand, but the |
| 5969 | // screen will be cleared later, so this is OK. |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 5970 | mch_setmouse(FALSE); // switch mouse off |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5971 | mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5972 | #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5973 | // When starting the GUI close the display opened for the clipboard. |
| 5974 | // After restoring the title, because that will need the display. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5975 | if (gui.starting) |
| 5976 | clear_xterm_clip(); |
| 5977 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5978 | stoptermcap(); // stop termcap mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5979 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 5980 | free_termoptions(); |
| 5981 | } |
| 5982 | |
| 5983 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5984 | free_termoptions(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 5985 | { |
| 5986 | struct vimoption *p; |
| 5987 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 5988 | for (p = options; p->fullname != NULL; p++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5989 | if (istermoption(p)) |
| 5990 | { |
| 5991 | if (p->flags & P_ALLOCED) |
| 5992 | free_string_option(*(char_u **)(p->var)); |
| 5993 | if (p->flags & P_DEF_ALLOCED) |
| 5994 | free_string_option(p->def_val[VI_DEFAULT]); |
| 5995 | *(char_u **)(p->var) = empty_option; |
| 5996 | p->def_val[VI_DEFAULT] = empty_option; |
| 5997 | p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 5998 | #ifdef FEAT_EVAL |
| 5999 | // remember where the option was cleared |
| 6000 | set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx); |
| 6001 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6002 | } |
| 6003 | clear_termcodes(); |
| 6004 | } |
| 6005 | |
| 6006 | /* |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 6007 | * Free the string for one term option, if it was allocated. |
| 6008 | * Set the string to empty_option and clear allocated flag. |
| 6009 | * "var" points to the option value. |
| 6010 | */ |
| 6011 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6012 | free_one_termoption(char_u *var) |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 6013 | { |
| 6014 | struct vimoption *p; |
| 6015 | |
| 6016 | for (p = &options[0]; p->fullname != NULL; p++) |
| 6017 | if (p->var == var) |
| 6018 | { |
| 6019 | if (p->flags & P_ALLOCED) |
| 6020 | free_string_option(*(char_u **)(p->var)); |
| 6021 | *(char_u **)(p->var) = empty_option; |
| 6022 | p->flags &= ~P_ALLOCED; |
| 6023 | break; |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6028 | * Set the terminal option defaults to the current value. |
| 6029 | * Used after setting the terminal name. |
| 6030 | */ |
| 6031 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6032 | set_term_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6033 | { |
| 6034 | struct vimoption *p; |
| 6035 | |
| 6036 | for (p = &options[0]; p->fullname != NULL; p++) |
| 6037 | { |
| 6038 | if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) |
| 6039 | { |
| 6040 | if (p->flags & P_DEF_ALLOCED) |
| 6041 | { |
| 6042 | free_string_option(p->def_val[VI_DEFAULT]); |
| 6043 | p->flags &= ~P_DEF_ALLOCED; |
| 6044 | } |
| 6045 | p->def_val[VI_DEFAULT] = *(char_u **)(p->var); |
| 6046 | if (p->flags & P_ALLOCED) |
| 6047 | { |
| 6048 | p->flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6049 | p->flags &= ~P_ALLOCED; // don't free the value now |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6050 | } |
| 6051 | } |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | /* |
| 6056 | * return TRUE if 'p' starts with 't_' |
| 6057 | */ |
| 6058 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6059 | istermoption(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6060 | { |
| 6061 | return (p->fullname[0] == 't' && p->fullname[1] == '_'); |
| 6062 | } |
| 6063 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6064 | /* |
| 6065 | * Returns TRUE if the option at 'opt_idx' starts with 't_' |
| 6066 | */ |
| 6067 | int |
| 6068 | istermoption_idx(int opt_idx) |
| 6069 | { |
| 6070 | return istermoption(&options[opt_idx]); |
| 6071 | } |
| 6072 | |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 6073 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6074 | /* |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6075 | * Unset local option value, similar to ":set opt<". |
| 6076 | */ |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6077 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6078 | unset_global_local_option(char_u *name, void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6079 | { |
| 6080 | struct vimoption *p; |
| 6081 | int opt_idx; |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6082 | buf_T *buf = (buf_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6083 | |
| 6084 | opt_idx = findoption(name); |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 6085 | if (opt_idx < 0) |
| 6086 | return; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6087 | p = &(options[opt_idx]); |
| 6088 | |
| 6089 | switch ((int)p->indir) |
| 6090 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6091 | // 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] | 6092 | case PV_EP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6093 | clear_string_option(&buf->b_p_ep); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6094 | break; |
| 6095 | case PV_KP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6096 | clear_string_option(&buf->b_p_kp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6097 | break; |
| 6098 | case PV_PATH: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6099 | clear_string_option(&buf->b_p_path); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6100 | break; |
| 6101 | case PV_AR: |
| 6102 | buf->b_p_ar = -1; |
| 6103 | break; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6104 | case PV_BKC: |
| 6105 | clear_string_option(&buf->b_p_bkc); |
| 6106 | buf->b_bkc_flags = 0; |
| 6107 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6108 | case PV_TAGS: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6109 | clear_string_option(&buf->b_p_tags); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6110 | break; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6111 | case PV_TC: |
| 6112 | clear_string_option(&buf->b_p_tc); |
| 6113 | buf->b_tc_flags = 0; |
| 6114 | break; |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6115 | case PV_SISO: |
| 6116 | curwin->w_p_siso = -1; |
| 6117 | break; |
| 6118 | case PV_SO: |
| 6119 | curwin->w_p_so = -1; |
| 6120 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6121 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6122 | case PV_DEF: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6123 | clear_string_option(&buf->b_p_def); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6124 | break; |
| 6125 | case PV_INC: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6126 | clear_string_option(&buf->b_p_inc); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6127 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6128 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6129 | case PV_DICT: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6130 | clear_string_option(&buf->b_p_dict); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6131 | break; |
| 6132 | case PV_TSR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6133 | clear_string_option(&buf->b_p_tsr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6134 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6135 | # ifdef FEAT_COMPL_FUNC |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6136 | case PV_TSRFU: |
| 6137 | clear_string_option(&buf->b_p_tsrfu); |
| 6138 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6139 | # endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6140 | case PV_FP: |
| 6141 | clear_string_option(&buf->b_p_fp); |
| 6142 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6143 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6144 | case PV_EFM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6145 | clear_string_option(&buf->b_p_efm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6146 | break; |
| 6147 | case PV_GP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6148 | clear_string_option(&buf->b_p_gp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6149 | break; |
| 6150 | case PV_MP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6151 | clear_string_option(&buf->b_p_mp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6152 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6153 | # endif |
| 6154 | # if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6155 | case PV_BEXPR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6156 | clear_string_option(&buf->b_p_bexpr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6157 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6158 | # endif |
| 6159 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6160 | case PV_CM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6161 | clear_string_option(&buf->b_p_cm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6162 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6163 | # endif |
| 6164 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6165 | case PV_SBR: |
| 6166 | clear_string_option(&((win_T *)from)->w_p_sbr); |
| 6167 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6168 | # endif |
| 6169 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6170 | case PV_STL: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6171 | clear_string_option(&((win_T *)from)->w_p_stl); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6172 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6173 | # endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6174 | case PV_UL: |
| 6175 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
| 6176 | break; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6177 | case PV_LW: |
| 6178 | clear_string_option(&buf->b_p_lw); |
| 6179 | break; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6180 | case PV_MENC: |
| 6181 | clear_string_option(&buf->b_p_menc); |
| 6182 | break; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6183 | case PV_LCS: |
| 6184 | clear_string_option(&((win_T *)from)->w_p_lcs); |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6185 | set_listchars_option((win_T *)from, ((win_T *)from)->w_p_lcs, TRUE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 6186 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6187 | break; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6188 | case PV_FCS: |
| 6189 | clear_string_option(&((win_T *)from)->w_p_fcs); |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6190 | set_fillchars_option((win_T *)from, ((win_T *)from)->w_p_fcs, TRUE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 6191 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6192 | break; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6193 | case PV_VE: |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6194 | clear_string_option(&((win_T *)from)->w_p_ve); |
| 6195 | ((win_T *)from)->w_ve_flags = 0; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6196 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6197 | } |
| 6198 | } |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 6199 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6200 | |
| 6201 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6202 | * Get pointer to option variable, depending on local or global scope. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6203 | * "scope" can be OPT_LOCAL, OPT_GLOBAL or a combination. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6204 | */ |
| 6205 | static char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6206 | get_varp_scope(struct vimoption *p, int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6207 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6208 | if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6209 | { |
| 6210 | if (p->var == VAR_WIN) |
| 6211 | return (char_u *)GLOBAL_WO(get_varp(p)); |
| 6212 | return p->var; |
| 6213 | } |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6214 | if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6215 | { |
| 6216 | switch ((int)p->indir) |
| 6217 | { |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6218 | case PV_FP: return (char_u *)&(curbuf->b_p_fp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6219 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6220 | case PV_EFM: return (char_u *)&(curbuf->b_p_efm); |
| 6221 | case PV_GP: return (char_u *)&(curbuf->b_p_gp); |
| 6222 | case PV_MP: return (char_u *)&(curbuf->b_p_mp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6223 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6224 | case PV_EP: return (char_u *)&(curbuf->b_p_ep); |
| 6225 | case PV_KP: return (char_u *)&(curbuf->b_p_kp); |
| 6226 | case PV_PATH: return (char_u *)&(curbuf->b_p_path); |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6227 | case PV_AR: return (char_u *)&(curbuf->b_p_ar); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6228 | case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6229 | case PV_TC: return (char_u *)&(curbuf->b_p_tc); |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6230 | case PV_SISO: return (char_u *)&(curwin->w_p_siso); |
| 6231 | case PV_SO: return (char_u *)&(curwin->w_p_so); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6232 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6233 | case PV_DEF: return (char_u *)&(curbuf->b_p_def); |
| 6234 | case PV_INC: return (char_u *)&(curbuf->b_p_inc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6235 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6236 | case PV_DICT: return (char_u *)&(curbuf->b_p_dict); |
| 6237 | case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6238 | #ifdef FEAT_COMPL_FUNC |
| 6239 | case PV_TSRFU: return (char_u *)&(curbuf->b_p_tsrfu); |
| 6240 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6241 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6242 | case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr); |
| 6243 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6244 | #if defined(FEAT_CRYPT) |
| 6245 | case PV_CM: return (char_u *)&(curbuf->b_p_cm); |
| 6246 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6247 | #ifdef FEAT_LINEBREAK |
| 6248 | case PV_SBR: return (char_u *)&(curwin->w_p_sbr); |
| 6249 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6250 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6251 | case PV_STL: return (char_u *)&(curwin->w_p_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6252 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6253 | case PV_UL: return (char_u *)&(curbuf->b_p_ul); |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6254 | case PV_LW: return (char_u *)&(curbuf->b_p_lw); |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6255 | case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6256 | case PV_MENC: return (char_u *)&(curbuf->b_p_menc); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6257 | case PV_LCS: return (char_u *)&(curwin->w_p_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6258 | case PV_FCS: return (char_u *)&(curwin->w_p_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6259 | case PV_VE: return (char_u *)&(curwin->w_p_ve); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6260 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6261 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6262 | return NULL; // "cannot happen" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6263 | } |
| 6264 | return get_varp(p); |
| 6265 | } |
| 6266 | |
| 6267 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6268 | * Get pointer to option variable at 'opt_idx', depending on local or global |
| 6269 | * scope. |
| 6270 | */ |
| 6271 | char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6272 | get_option_varp_scope(int opt_idx, int scope) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6273 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6274 | return get_varp_scope(&(options[opt_idx]), scope); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6275 | } |
| 6276 | |
| 6277 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6278 | * Get pointer to option variable. |
| 6279 | */ |
| 6280 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6281 | get_varp(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6282 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6283 | // hidden option, always return NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6284 | if (p->var == NULL) |
| 6285 | return NULL; |
| 6286 | |
| 6287 | switch ((int)p->indir) |
| 6288 | { |
| 6289 | case PV_NONE: return p->var; |
| 6290 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6291 | // 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] | 6292 | case PV_EP: return *curbuf->b_p_ep != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6293 | ? (char_u *)&curbuf->b_p_ep : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6294 | case PV_KP: return *curbuf->b_p_kp != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6295 | ? (char_u *)&curbuf->b_p_kp : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6296 | case PV_PATH: return *curbuf->b_p_path != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6297 | ? (char_u *)&(curbuf->b_p_path) : p->var; |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6298 | case PV_AR: return curbuf->b_p_ar >= 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6299 | ? (char_u *)&(curbuf->b_p_ar) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6300 | case PV_TAGS: return *curbuf->b_p_tags != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | ? (char_u *)&(curbuf->b_p_tags) : p->var; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6302 | case PV_TC: return *curbuf->b_p_tc != NUL |
| 6303 | ? (char_u *)&(curbuf->b_p_tc) : p->var; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6304 | case PV_BKC: return *curbuf->b_p_bkc != NUL |
| 6305 | ? (char_u *)&(curbuf->b_p_bkc) : p->var; |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 6306 | case PV_SISO: return curwin->w_p_siso >= 0 |
| 6307 | ? (char_u *)&(curwin->w_p_siso) : p->var; |
| 6308 | case PV_SO: return curwin->w_p_so >= 0 |
| 6309 | ? (char_u *)&(curwin->w_p_so) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6310 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6311 | case PV_DEF: return *curbuf->b_p_def != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6312 | ? (char_u *)&(curbuf->b_p_def) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6313 | case PV_INC: return *curbuf->b_p_inc != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6314 | ? (char_u *)&(curbuf->b_p_inc) : p->var; |
| 6315 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6316 | case PV_DICT: return *curbuf->b_p_dict != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6317 | ? (char_u *)&(curbuf->b_p_dict) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6318 | case PV_TSR: return *curbuf->b_p_tsr != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6319 | ? (char_u *)&(curbuf->b_p_tsr) : p->var; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6320 | #ifdef FEAT_COMPL_FUNC |
| 6321 | case PV_TSRFU: return *curbuf->b_p_tsrfu != NUL |
| 6322 | ? (char_u *)&(curbuf->b_p_tsrfu) : p->var; |
| 6323 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6324 | case PV_FP: return *curbuf->b_p_fp != NUL |
| 6325 | ? (char_u *)&(curbuf->b_p_fp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6326 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6327 | case PV_EFM: return *curbuf->b_p_efm != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6328 | ? (char_u *)&(curbuf->b_p_efm) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6329 | case PV_GP: return *curbuf->b_p_gp != NUL |
| 6330 | ? (char_u *)&(curbuf->b_p_gp) : p->var; |
| 6331 | case PV_MP: return *curbuf->b_p_mp != NUL |
| 6332 | ? (char_u *)&(curbuf->b_p_mp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6333 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6334 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6335 | case PV_BEXPR: return *curbuf->b_p_bexpr != NUL |
| 6336 | ? (char_u *)&(curbuf->b_p_bexpr) : p->var; |
| 6337 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6338 | #if defined(FEAT_CRYPT) |
| 6339 | case PV_CM: return *curbuf->b_p_cm != NUL |
| 6340 | ? (char_u *)&(curbuf->b_p_cm) : p->var; |
| 6341 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6342 | #ifdef FEAT_LINEBREAK |
| 6343 | case PV_SBR: return *curwin->w_p_sbr != NUL |
| 6344 | ? (char_u *)&(curwin->w_p_sbr) : p->var; |
| 6345 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6346 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6347 | case PV_STL: return *curwin->w_p_stl != NUL |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6348 | ? (char_u *)&(curwin->w_p_stl) : p->var; |
| 6349 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6350 | case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL |
| 6351 | ? (char_u *)&(curbuf->b_p_ul) : p->var; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6352 | case PV_LW: return *curbuf->b_p_lw != NUL |
| 6353 | ? (char_u *)&(curbuf->b_p_lw) : p->var; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6354 | case PV_MENC: return *curbuf->b_p_menc != NUL |
| 6355 | ? (char_u *)&(curbuf->b_p_menc) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6356 | #ifdef FEAT_ARABIC |
| 6357 | case PV_ARAB: return (char_u *)&(curwin->w_p_arab); |
| 6358 | #endif |
| 6359 | case PV_LIST: return (char_u *)&(curwin->w_p_list); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6360 | case PV_LCS: return *curwin->w_p_lcs != NUL |
| 6361 | ? (char_u *)&(curwin->w_p_lcs) : p->var; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6362 | case PV_FCS: return *curwin->w_p_fcs != NUL |
| 6363 | ? (char_u *)&(curwin->w_p_fcs) : p->var; |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6364 | case PV_VE: return *curwin->w_p_ve != NUL |
| 6365 | ? (char_u *)&(curwin->w_p_ve) : p->var; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6366 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6367 | case PV_SPELL: return (char_u *)&(curwin->w_p_spell); |
| 6368 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6369 | #ifdef FEAT_SYN_HL |
| 6370 | case PV_CUC: return (char_u *)&(curwin->w_p_cuc); |
| 6371 | case PV_CUL: return (char_u *)&(curwin->w_p_cul); |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6372 | case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6373 | case PV_CC: return (char_u *)&(curwin->w_p_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6374 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6375 | #ifdef FEAT_DIFF |
| 6376 | case PV_DIFF: return (char_u *)&(curwin->w_p_diff); |
| 6377 | #endif |
| 6378 | #ifdef FEAT_FOLDING |
| 6379 | case PV_FDC: return (char_u *)&(curwin->w_p_fdc); |
| 6380 | case PV_FEN: return (char_u *)&(curwin->w_p_fen); |
| 6381 | case PV_FDI: return (char_u *)&(curwin->w_p_fdi); |
| 6382 | case PV_FDL: return (char_u *)&(curwin->w_p_fdl); |
| 6383 | case PV_FDM: return (char_u *)&(curwin->w_p_fdm); |
| 6384 | case PV_FML: return (char_u *)&(curwin->w_p_fml); |
| 6385 | case PV_FDN: return (char_u *)&(curwin->w_p_fdn); |
| 6386 | # ifdef FEAT_EVAL |
| 6387 | case PV_FDE: return (char_u *)&(curwin->w_p_fde); |
| 6388 | case PV_FDT: return (char_u *)&(curwin->w_p_fdt); |
| 6389 | # endif |
| 6390 | case PV_FMR: return (char_u *)&(curwin->w_p_fmr); |
| 6391 | #endif |
| 6392 | case PV_NU: return (char_u *)&(curwin->w_p_nu); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6393 | case PV_RNU: return (char_u *)&(curwin->w_p_rnu); |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6394 | #ifdef FEAT_LINEBREAK |
| 6395 | case PV_NUW: return (char_u *)&(curwin->w_p_nuw); |
| 6396 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6397 | case PV_WFH: return (char_u *)&(curwin->w_p_wfh); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 6398 | case PV_WFW: return (char_u *)&(curwin->w_p_wfw); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 6399 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6400 | case PV_PVW: return (char_u *)&(curwin->w_p_pvw); |
| 6401 | #endif |
| 6402 | #ifdef FEAT_RIGHTLEFT |
| 6403 | case PV_RL: return (char_u *)&(curwin->w_p_rl); |
| 6404 | case PV_RLC: return (char_u *)&(curwin->w_p_rlc); |
| 6405 | #endif |
| 6406 | case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 6407 | case PV_SMS: return (char_u *)&(curwin->w_p_sms); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6408 | case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); |
| 6409 | #ifdef FEAT_LINEBREAK |
| 6410 | case PV_LBR: return (char_u *)&(curwin->w_p_lbr); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6411 | case PV_BRI: return (char_u *)&(curwin->w_p_bri); |
| 6412 | case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6413 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6414 | case PV_WCR: return (char_u *)&(curwin->w_p_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6415 | case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6416 | case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6417 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6418 | case PV_COCU: return (char_u *)&(curwin->w_p_cocu); |
| 6419 | case PV_COLE: return (char_u *)&(curwin->w_p_cole); |
| 6420 | #endif |
| 6421 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6422 | case PV_TWK: return (char_u *)&(curwin->w_p_twk); |
| 6423 | case PV_TWS: return (char_u *)&(curwin->w_p_tws); |
| 6424 | case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6425 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6426 | |
| 6427 | case PV_AI: return (char_u *)&(curbuf->b_p_ai); |
| 6428 | case PV_BIN: return (char_u *)&(curbuf->b_p_bin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6429 | case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6430 | case PV_BH: return (char_u *)&(curbuf->b_p_bh); |
| 6431 | case PV_BT: return (char_u *)&(curbuf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6432 | case PV_BL: return (char_u *)&(curbuf->b_p_bl); |
| 6433 | case PV_CI: return (char_u *)&(curbuf->b_p_ci); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6434 | case PV_CIN: return (char_u *)&(curbuf->b_p_cin); |
| 6435 | case PV_CINK: return (char_u *)&(curbuf->b_p_cink); |
| 6436 | case PV_CINO: return (char_u *)&(curbuf->b_p_cino); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 6437 | case PV_CINSD: return (char_u *)&(curbuf->b_p_cinsd); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6438 | case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6439 | case PV_COM: return (char_u *)&(curbuf->b_p_com); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6440 | #ifdef FEAT_FOLDING |
| 6441 | case PV_CMS: return (char_u *)&(curbuf->b_p_cms); |
| 6442 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6443 | case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6444 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6445 | case PV_CSL: return (char_u *)&(curbuf->b_p_csl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6446 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6447 | #ifdef FEAT_COMPL_FUNC |
| 6448 | case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6449 | case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6450 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6451 | #ifdef FEAT_EVAL |
| 6452 | case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); |
| 6453 | #endif |
Bram Moolenaar | 3f68a41 | 2022-10-28 17:04:21 +0100 | [diff] [blame] | 6454 | case PV_EOF: return (char_u *)&(curbuf->b_p_eof); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6455 | case PV_EOL: return (char_u *)&(curbuf->b_p_eol); |
Bram Moolenaar | 34d72d4 | 2015-07-17 14:18:08 +0200 | [diff] [blame] | 6456 | case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6457 | case PV_ET: return (char_u *)&(curbuf->b_p_et); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6458 | case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6459 | case PV_FF: return (char_u *)&(curbuf->b_p_ff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6460 | case PV_FT: return (char_u *)&(curbuf->b_p_ft); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6461 | case PV_FO: return (char_u *)&(curbuf->b_p_fo); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 6462 | case PV_FLP: return (char_u *)&(curbuf->b_p_flp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6463 | case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); |
| 6464 | case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); |
| 6465 | case PV_INF: return (char_u *)&(curbuf->b_p_inf); |
| 6466 | case PV_ISK: return (char_u *)&(curbuf->b_p_isk); |
| 6467 | #ifdef FEAT_FIND_ID |
| 6468 | # ifdef FEAT_EVAL |
| 6469 | case PV_INEX: return (char_u *)&(curbuf->b_p_inex); |
| 6470 | # endif |
| 6471 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6472 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6473 | case PV_INDE: return (char_u *)&(curbuf->b_p_inde); |
| 6474 | case PV_INDK: return (char_u *)&(curbuf->b_p_indk); |
| 6475 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6476 | #ifdef FEAT_EVAL |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6477 | case PV_FEX: return (char_u *)&(curbuf->b_p_fex); |
| 6478 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6479 | #ifdef FEAT_CRYPT |
| 6480 | case PV_KEY: return (char_u *)&(curbuf->b_p_key); |
| 6481 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6482 | case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 6483 | case PV_LOP: return (char_u *)&(curbuf->b_p_lop); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6484 | case PV_ML: return (char_u *)&(curbuf->b_p_ml); |
| 6485 | case PV_MPS: return (char_u *)&(curbuf->b_p_mps); |
| 6486 | case PV_MA: return (char_u *)&(curbuf->b_p_ma); |
| 6487 | case PV_MOD: return (char_u *)&(curbuf->b_changed); |
| 6488 | case PV_NF: return (char_u *)&(curbuf->b_p_nf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6489 | case PV_PI: return (char_u *)&(curbuf->b_p_pi); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6490 | case PV_QE: return (char_u *)&(curbuf->b_p_qe); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6491 | case PV_RO: return (char_u *)&(curbuf->b_p_ro); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6492 | case PV_SI: return (char_u *)&(curbuf->b_p_si); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6493 | case PV_SN: return (char_u *)&(curbuf->b_p_sn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6494 | case PV_STS: return (char_u *)&(curbuf->b_p_sts); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6495 | case PV_SUA: return (char_u *)&(curbuf->b_p_sua); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6496 | case PV_SWF: return (char_u *)&(curbuf->b_p_swf); |
| 6497 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 6498 | case PV_SMC: return (char_u *)&(curbuf->b_p_smc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6499 | case PV_SYN: return (char_u *)&(curbuf->b_p_syn); |
| 6500 | #endif |
| 6501 | #ifdef FEAT_SPELL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6502 | case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); |
| 6503 | case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); |
| 6504 | case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 6505 | case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6506 | #endif |
| 6507 | case PV_SW: return (char_u *)&(curbuf->b_p_sw); |
| 6508 | case PV_TS: return (char_u *)&(curbuf->b_p_ts); |
| 6509 | case PV_TW: return (char_u *)&(curbuf->b_p_tw); |
| 6510 | case PV_TX: return (char_u *)&(curbuf->b_p_tx); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 6511 | #ifdef FEAT_PERSISTENT_UNDO |
| 6512 | case PV_UDF: return (char_u *)&(curbuf->b_p_udf); |
| 6513 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6514 | case PV_WM: return (char_u *)&(curbuf->b_p_wm); |
| 6515 | #ifdef FEAT_KEYMAP |
| 6516 | case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); |
| 6517 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6518 | #ifdef FEAT_SIGNS |
| 6519 | case PV_SCL: return (char_u *)&(curwin->w_p_scl); |
| 6520 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6521 | #ifdef FEAT_VARTABS |
| 6522 | case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); |
| 6523 | case PV_VTS: return (char_u *)&(curbuf->b_p_vts); |
| 6524 | #endif |
RestorerZ | 68ebcee | 2023-05-31 17:12:14 +0100 | [diff] [blame] | 6525 | default: iemsg(e_get_varp_error); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6526 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6527 | // always return a valid pointer to avoid a crash! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6528 | return (char_u *)&(curbuf->b_p_wm); |
| 6529 | } |
| 6530 | |
| 6531 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6532 | * Return a pointer to the variable for option at 'opt_idx' |
| 6533 | */ |
| 6534 | char_u * |
| 6535 | get_option_var(int opt_idx) |
| 6536 | { |
| 6537 | return options[opt_idx].var; |
| 6538 | } |
| 6539 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6540 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6541 | /* |
| 6542 | * Return the full name of the option at 'opt_idx' |
| 6543 | */ |
| 6544 | char_u * |
| 6545 | get_option_fullname(int opt_idx) |
| 6546 | { |
| 6547 | return (char_u *)options[opt_idx].fullname; |
| 6548 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6549 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6550 | |
| 6551 | /* |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 6552 | * Return the did_set callback function for the option at 'opt_idx' |
| 6553 | */ |
| 6554 | opt_did_set_cb_T |
| 6555 | get_option_did_set_cb(int opt_idx) |
| 6556 | { |
| 6557 | return options[opt_idx].opt_did_set_cb; |
| 6558 | } |
| 6559 | |
| 6560 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6561 | * Get the value of 'equalprg', either the buffer-local one or the global one. |
| 6562 | */ |
| 6563 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6564 | get_equalprg(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6565 | { |
| 6566 | if (*curbuf->b_p_ep == NUL) |
| 6567 | return p_ep; |
| 6568 | return curbuf->b_p_ep; |
| 6569 | } |
| 6570 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6571 | /* |
| 6572 | * Copy options from one window to another. |
| 6573 | * Used when splitting a window. |
| 6574 | */ |
| 6575 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6576 | win_copy_options(win_T *wp_from, win_T *wp_to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6577 | { |
| 6578 | copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); |
| 6579 | copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6580 | after_copy_winopt(wp_to); |
| 6581 | } |
| 6582 | |
| 6583 | /* |
| 6584 | * After copying window options: update variables depending on options. |
| 6585 | */ |
| 6586 | void |
Sean Dewar | 0f7ff85 | 2022-02-12 11:51:25 +0000 | [diff] [blame] | 6587 | after_copy_winopt(win_T *wp) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6588 | { |
| 6589 | #ifdef FEAT_LINEBREAK |
| 6590 | briopt_check(wp); |
Bram Moolenaar | 285ed7e | 2014-08-24 21:39:49 +0200 | [diff] [blame] | 6591 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6592 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6593 | fill_culopt_flags(NULL, wp); |
| 6594 | check_colorcolumn(wp); |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6595 | #endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6596 | set_listchars_option(wp, wp->w_p_lcs, TRUE); |
| 6597 | set_fillchars_option(wp, wp->w_p_fcs, TRUE); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | static char_u * |
| 6601 | copy_option_val(char_u *val) |
| 6602 | { |
| 6603 | if (val == empty_option) |
| 6604 | return empty_option; // no need to allocate memory |
| 6605 | return vim_strsave(val); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6606 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6607 | |
| 6608 | /* |
| 6609 | * Copy the options from one winopt_T to another. |
| 6610 | * Doesn't free the old option values in "to", use clear_winopt() for that. |
| 6611 | * The 'scroll' option is not copied, because it depends on the window height. |
| 6612 | * The 'previewwindow' option is reset, there can be only one preview window. |
| 6613 | */ |
| 6614 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6615 | copy_winopt(winopt_T *from, winopt_T *to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6616 | { |
| 6617 | #ifdef FEAT_ARABIC |
| 6618 | to->wo_arab = from->wo_arab; |
| 6619 | #endif |
| 6620 | to->wo_list = from->wo_list; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6621 | to->wo_lcs = copy_option_val(from->wo_lcs); |
| 6622 | to->wo_fcs = copy_option_val(from->wo_fcs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6623 | to->wo_nu = from->wo_nu; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6624 | to->wo_rnu = from->wo_rnu; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6625 | to->wo_ve = copy_option_val(from->wo_ve); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6626 | to->wo_ve_flags = from->wo_ve_flags; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6627 | #ifdef FEAT_LINEBREAK |
| 6628 | to->wo_nuw = from->wo_nuw; |
| 6629 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6630 | #ifdef FEAT_RIGHTLEFT |
| 6631 | to->wo_rl = from->wo_rl; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6632 | to->wo_rlc = copy_option_val(from->wo_rlc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6633 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6634 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6635 | to->wo_sbr = copy_option_val(from->wo_sbr); |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6636 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6637 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6638 | to->wo_stl = copy_option_val(from->wo_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6639 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6640 | to->wo_wrap = from->wo_wrap; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6641 | #ifdef FEAT_DIFF |
| 6642 | to->wo_wrap_save = from->wo_wrap_save; |
| 6643 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6644 | #ifdef FEAT_LINEBREAK |
| 6645 | to->wo_lbr = from->wo_lbr; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6646 | to->wo_bri = from->wo_bri; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6647 | to->wo_briopt = copy_option_val(from->wo_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | #endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6649 | to->wo_wcr = copy_option_val(from->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6650 | to->wo_scb = from->wo_scb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6651 | to->wo_scb_save = from->wo_scb_save; |
Bram Moolenaar | b1fd26d | 2022-10-03 11:23:02 +0100 | [diff] [blame] | 6652 | to->wo_sms = from->wo_sms; |
Bram Moolenaar | 4161dcc | 2010-12-02 15:33:21 +0100 | [diff] [blame] | 6653 | to->wo_crb = from->wo_crb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6654 | to->wo_crb_save = from->wo_crb_save; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6655 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6656 | to->wo_spell = from->wo_spell; |
| 6657 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6658 | #ifdef FEAT_SYN_HL |
| 6659 | to->wo_cuc = from->wo_cuc; |
| 6660 | to->wo_cul = from->wo_cul; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6661 | to->wo_culopt = copy_option_val(from->wo_culopt); |
| 6662 | to->wo_cc = copy_option_val(from->wo_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6663 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6664 | #ifdef FEAT_DIFF |
| 6665 | to->wo_diff = from->wo_diff; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6666 | to->wo_diff_saved = from->wo_diff_saved; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6667 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6668 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6669 | to->wo_cocu = copy_option_val(from->wo_cocu); |
Bram Moolenaar | d497a30 | 2010-07-23 22:27:03 +0200 | [diff] [blame] | 6670 | to->wo_cole = from->wo_cole; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6671 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6672 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6673 | to->wo_twk = copy_option_val(from->wo_twk); |
| 6674 | to->wo_tws = copy_option_val(from->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6675 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6676 | #ifdef FEAT_FOLDING |
| 6677 | to->wo_fdc = from->wo_fdc; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6678 | to->wo_fdc_save = from->wo_fdc_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6679 | to->wo_fen = from->wo_fen; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6680 | to->wo_fen_save = from->wo_fen_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6681 | to->wo_fdi = copy_option_val(from->wo_fdi); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6682 | to->wo_fml = from->wo_fml; |
| 6683 | to->wo_fdl = from->wo_fdl; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6684 | to->wo_fdl_save = from->wo_fdl_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6685 | to->wo_fdm = copy_option_val(from->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6686 | to->wo_fdm_save = from->wo_diff_saved |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6687 | ? vim_strsave(from->wo_fdm_save) : empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6688 | to->wo_fdn = from->wo_fdn; |
| 6689 | # ifdef FEAT_EVAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6690 | to->wo_fde = copy_option_val(from->wo_fde); |
| 6691 | to->wo_fdt = copy_option_val(from->wo_fdt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6692 | # endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6693 | to->wo_fmr = copy_option_val(from->wo_fmr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6694 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6695 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6696 | to->wo_scl = copy_option_val(from->wo_scl); |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6697 | #endif |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6698 | |
| 6699 | #ifdef FEAT_EVAL |
| 6700 | // Copy the script context so that we know where the value was last set. |
| 6701 | mch_memmove(to->wo_script_ctx, from->wo_script_ctx, |
| 6702 | sizeof(to->wo_script_ctx)); |
| 6703 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6704 | check_winopt(to); // don't want NULL pointers |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | /* |
| 6708 | * Check string options in a window for a NULL value. |
| 6709 | */ |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 6710 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6711 | check_win_options(win_T *win) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6712 | { |
| 6713 | check_winopt(&win->w_onebuf_opt); |
| 6714 | check_winopt(&win->w_allbuf_opt); |
| 6715 | } |
| 6716 | |
| 6717 | /* |
| 6718 | * Check for NULL pointers in a winopt_T and replace them with empty_option. |
| 6719 | */ |
Bram Moolenaar | 8dc907d | 2014-06-25 14:44:10 +0200 | [diff] [blame] | 6720 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6721 | check_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6722 | { |
| 6723 | #ifdef FEAT_FOLDING |
| 6724 | check_string_option(&wop->wo_fdi); |
| 6725 | check_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6726 | check_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6727 | # ifdef FEAT_EVAL |
| 6728 | check_string_option(&wop->wo_fde); |
| 6729 | check_string_option(&wop->wo_fdt); |
| 6730 | # endif |
| 6731 | check_string_option(&wop->wo_fmr); |
| 6732 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6733 | #ifdef FEAT_SIGNS |
| 6734 | check_string_option(&wop->wo_scl); |
| 6735 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6736 | #ifdef FEAT_RIGHTLEFT |
| 6737 | check_string_option(&wop->wo_rlc); |
| 6738 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6739 | #ifdef FEAT_LINEBREAK |
| 6740 | check_string_option(&wop->wo_sbr); |
| 6741 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6742 | #ifdef FEAT_STL_OPT |
| 6743 | check_string_option(&wop->wo_stl); |
| 6744 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6745 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6746 | check_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6747 | check_string_option(&wop->wo_cc); |
| 6748 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6749 | #ifdef FEAT_CONCEAL |
| 6750 | check_string_option(&wop->wo_cocu); |
| 6751 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6752 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6753 | check_string_option(&wop->wo_twk); |
| 6754 | check_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6755 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6756 | #ifdef FEAT_LINEBREAK |
| 6757 | check_string_option(&wop->wo_briopt); |
| 6758 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6759 | check_string_option(&wop->wo_wcr); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6760 | check_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6761 | check_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6762 | check_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | /* |
| 6766 | * Free the allocated memory inside a winopt_T. |
| 6767 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6768 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6769 | clear_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6770 | { |
| 6771 | #ifdef FEAT_FOLDING |
| 6772 | clear_string_option(&wop->wo_fdi); |
| 6773 | clear_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6774 | clear_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6775 | # ifdef FEAT_EVAL |
| 6776 | clear_string_option(&wop->wo_fde); |
| 6777 | clear_string_option(&wop->wo_fdt); |
| 6778 | # endif |
| 6779 | clear_string_option(&wop->wo_fmr); |
| 6780 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6781 | #ifdef FEAT_SIGNS |
| 6782 | clear_string_option(&wop->wo_scl); |
| 6783 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6784 | #ifdef FEAT_LINEBREAK |
| 6785 | clear_string_option(&wop->wo_briopt); |
| 6786 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6787 | clear_string_option(&wop->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6788 | #ifdef FEAT_RIGHTLEFT |
| 6789 | clear_string_option(&wop->wo_rlc); |
| 6790 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6791 | #ifdef FEAT_LINEBREAK |
| 6792 | clear_string_option(&wop->wo_sbr); |
| 6793 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6794 | #ifdef FEAT_STL_OPT |
| 6795 | clear_string_option(&wop->wo_stl); |
| 6796 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6797 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6798 | clear_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6799 | clear_string_option(&wop->wo_cc); |
| 6800 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6801 | #ifdef FEAT_CONCEAL |
| 6802 | clear_string_option(&wop->wo_cocu); |
| 6803 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6804 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6805 | clear_string_option(&wop->wo_twk); |
| 6806 | clear_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6807 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6808 | clear_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6809 | clear_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6810 | clear_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6811 | } |
| 6812 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6813 | #ifdef FEAT_EVAL |
| 6814 | // Index into the options table for a buffer-local option enum. |
| 6815 | static int buf_opt_idx[BV_COUNT]; |
| 6816 | # define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].script_ctx |
| 6817 | |
| 6818 | /* |
| 6819 | * Initialize buf_opt_idx[] if not done already. |
| 6820 | */ |
| 6821 | static void |
| 6822 | init_buf_opt_idx(void) |
| 6823 | { |
| 6824 | static int did_init_buf_opt_idx = FALSE; |
| 6825 | int i; |
| 6826 | |
| 6827 | if (did_init_buf_opt_idx) |
| 6828 | return; |
| 6829 | did_init_buf_opt_idx = TRUE; |
| 6830 | for (i = 0; !istermoption_idx(i); i++) |
| 6831 | if (options[i].indir & PV_BUF) |
| 6832 | buf_opt_idx[options[i].indir & PV_MASK] = i; |
| 6833 | } |
| 6834 | #else |
| 6835 | # define COPY_OPT_SCTX(buf, bv) |
| 6836 | #endif |
| 6837 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6838 | /* |
| 6839 | * Copy global option values to local options for one buffer. |
| 6840 | * Used when creating a new buffer and sometimes when entering a buffer. |
| 6841 | * flags: |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6842 | * BCO_ENTER We will enter the buffer "buf". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6843 | * BCO_ALWAYS Always copy the options, but only set b_p_initialized when |
| 6844 | * appropriate. |
| 6845 | * BCO_NOHELP Don't copy the values to a help buffer. |
| 6846 | */ |
| 6847 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6848 | buf_copy_options(buf_T *buf, int flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6849 | { |
| 6850 | int should_copy = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6851 | char_u *save_p_isk = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6852 | int dont_do_help; |
| 6853 | int did_isk = FALSE; |
| 6854 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6855 | // Skip this when the option defaults have not been set yet. Happens when |
| 6856 | // main() allocates the first buffer. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6857 | if (p_cpo != NULL) |
| 6858 | { |
| 6859 | /* |
| 6860 | * Always copy when entering and 'cpo' contains 'S'. |
| 6861 | * Don't copy when already initialized. |
| 6862 | * Don't copy when 'cpo' contains 's' and not entering. |
| 6863 | * 'S' BCO_ENTER initialized 's' should_copy |
| 6864 | * yes yes X X TRUE |
| 6865 | * yes no yes X FALSE |
| 6866 | * no X yes X FALSE |
| 6867 | * X no no yes FALSE |
| 6868 | * X no no no TRUE |
| 6869 | * no yes no X TRUE |
| 6870 | */ |
| 6871 | if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) |
| 6872 | && (buf->b_p_initialized |
| 6873 | || (!(flags & BCO_ENTER) |
| 6874 | && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) |
| 6875 | should_copy = FALSE; |
| 6876 | |
| 6877 | if (should_copy || (flags & BCO_ALWAYS)) |
| 6878 | { |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6879 | #ifdef FEAT_EVAL |
Bram Moolenaar | a80faa8 | 2020-04-12 19:37:17 +0200 | [diff] [blame] | 6880 | CLEAR_FIELD(buf->b_p_script_ctx); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6881 | init_buf_opt_idx(); |
| 6882 | #endif |
| 6883 | // Don't copy the options specific to a help buffer when |
| 6884 | // BCO_NOHELP is given or the options were initialized already |
| 6885 | // (jumping back to a help file with CTRL-T or CTRL-O) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6886 | dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) |
| 6887 | || buf->b_p_initialized; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6888 | if (dont_do_help) // don't free b_p_isk |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6889 | { |
| 6890 | save_p_isk = buf->b_p_isk; |
| 6891 | buf->b_p_isk = NULL; |
| 6892 | } |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6893 | // Always free the allocated strings. If not already initialized, |
| 6894 | // reset 'readonly' and copy 'fileformat'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6895 | if (!buf->b_p_initialized) |
| 6896 | { |
| 6897 | free_buf_options(buf, TRUE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6898 | buf->b_p_ro = FALSE; // don't copy readonly |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6899 | buf->b_p_tx = p_tx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6900 | buf->b_p_fenc = vim_strsave(p_fenc); |
Bram Moolenaar | e8ef3a0 | 2016-10-12 17:45:29 +0200 | [diff] [blame] | 6901 | switch (*p_ffs) |
| 6902 | { |
| 6903 | case 'm': |
| 6904 | buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break; |
| 6905 | case 'd': |
| 6906 | buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break; |
| 6907 | case 'u': |
| 6908 | buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break; |
| 6909 | default: |
| 6910 | buf->b_p_ff = vim_strsave(p_ff); |
| 6911 | } |
| 6912 | if (buf->b_p_ff != NULL) |
| 6913 | buf->b_start_ffc = *buf->b_p_ff; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6914 | buf->b_p_bh = empty_option; |
| 6915 | buf->b_p_bt = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6916 | } |
| 6917 | else |
| 6918 | free_buf_options(buf, FALSE); |
| 6919 | |
| 6920 | buf->b_p_ai = p_ai; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6921 | COPY_OPT_SCTX(buf, BV_AI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6922 | buf->b_p_ai_nopaste = p_ai_nopaste; |
| 6923 | buf->b_p_sw = p_sw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6924 | COPY_OPT_SCTX(buf, BV_SW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6925 | buf->b_p_tw = p_tw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6926 | COPY_OPT_SCTX(buf, BV_TW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6927 | buf->b_p_tw_nopaste = p_tw_nopaste; |
| 6928 | buf->b_p_tw_nobin = p_tw_nobin; |
| 6929 | buf->b_p_wm = p_wm; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6930 | COPY_OPT_SCTX(buf, BV_WM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6931 | buf->b_p_wm_nopaste = p_wm_nopaste; |
| 6932 | buf->b_p_wm_nobin = p_wm_nobin; |
| 6933 | buf->b_p_bin = p_bin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6934 | COPY_OPT_SCTX(buf, BV_BIN); |
Bram Moolenaar | e8bb255 | 2005-07-08 22:26:47 +0000 | [diff] [blame] | 6935 | buf->b_p_bomb = p_bomb; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6936 | COPY_OPT_SCTX(buf, BV_BOMB); |
Bram Moolenaar | b388be0 | 2015-07-22 22:19:38 +0200 | [diff] [blame] | 6937 | buf->b_p_fixeol = p_fixeol; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6938 | COPY_OPT_SCTX(buf, BV_FIXEOL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6939 | buf->b_p_et = p_et; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6940 | COPY_OPT_SCTX(buf, BV_ET); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6941 | buf->b_p_et_nobin = p_et_nobin; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6942 | buf->b_p_et_nopaste = p_et_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6943 | buf->b_p_ml = p_ml; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6944 | COPY_OPT_SCTX(buf, BV_ML); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6945 | buf->b_p_ml_nobin = p_ml_nobin; |
| 6946 | buf->b_p_inf = p_inf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6947 | COPY_OPT_SCTX(buf, BV_INF); |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 6948 | if (cmdmod.cmod_flags & CMOD_NOSWAPFILE) |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6949 | buf->b_p_swf = FALSE; |
| 6950 | else |
| 6951 | { |
| 6952 | buf->b_p_swf = p_swf; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 6953 | COPY_OPT_SCTX(buf, BV_SWF); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6954 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6955 | buf->b_p_cpt = vim_strsave(p_cpt); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6956 | COPY_OPT_SCTX(buf, BV_CPT); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6957 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6958 | buf->b_p_csl = vim_strsave(p_csl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6959 | COPY_OPT_SCTX(buf, BV_CSL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6960 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6961 | #ifdef FEAT_COMPL_FUNC |
| 6962 | buf->b_p_cfu = vim_strsave(p_cfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6963 | COPY_OPT_SCTX(buf, BV_CFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6964 | set_buflocal_cfu_callback(buf); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6965 | buf->b_p_ofu = vim_strsave(p_ofu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6966 | COPY_OPT_SCTX(buf, BV_OFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6967 | set_buflocal_ofu_callback(buf); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6968 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6969 | #ifdef FEAT_EVAL |
| 6970 | buf->b_p_tfu = vim_strsave(p_tfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6971 | COPY_OPT_SCTX(buf, BV_TFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6972 | set_buflocal_tfu_callback(buf); |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6973 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6974 | buf->b_p_sts = p_sts; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6975 | COPY_OPT_SCTX(buf, BV_STS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6976 | buf->b_p_sts_nopaste = p_sts_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6977 | #ifdef FEAT_VARTABS |
| 6978 | buf->b_p_vsts = vim_strsave(p_vsts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6979 | COPY_OPT_SCTX(buf, BV_VSTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6980 | if (p_vsts && p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 6981 | (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6982 | else |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 6983 | buf->b_p_vsts_array = NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6984 | buf->b_p_vsts_nopaste = p_vsts_nopaste |
| 6985 | ? vim_strsave(p_vsts_nopaste) : NULL; |
| 6986 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6987 | buf->b_p_sn = p_sn; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6988 | COPY_OPT_SCTX(buf, BV_SN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6989 | buf->b_p_com = vim_strsave(p_com); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6990 | COPY_OPT_SCTX(buf, BV_COM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6991 | #ifdef FEAT_FOLDING |
| 6992 | buf->b_p_cms = vim_strsave(p_cms); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6993 | COPY_OPT_SCTX(buf, BV_CMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6994 | #endif |
| 6995 | buf->b_p_fo = vim_strsave(p_fo); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6996 | COPY_OPT_SCTX(buf, BV_FO); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 6997 | buf->b_p_flp = vim_strsave(p_flp); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6998 | COPY_OPT_SCTX(buf, BV_FLP); |
Bram Moolenaar | 473952e | 2019-09-28 16:30:04 +0200 | [diff] [blame] | 6999 | // NOTE: Valgrind may report a bogus memory leak for 'nrformats' |
| 7000 | // when it is set to 8 bytes in defaults.vim. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7001 | buf->b_p_nf = vim_strsave(p_nf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7002 | COPY_OPT_SCTX(buf, BV_NF); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7003 | buf->b_p_mps = vim_strsave(p_mps); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7004 | COPY_OPT_SCTX(buf, BV_MPS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7005 | buf->b_p_si = p_si; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7006 | COPY_OPT_SCTX(buf, BV_SI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7007 | buf->b_p_ci = p_ci; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7008 | COPY_OPT_SCTX(buf, BV_CI); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7009 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7010 | buf->b_p_cin = p_cin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7011 | COPY_OPT_SCTX(buf, BV_CIN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7012 | buf->b_p_cink = vim_strsave(p_cink); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7013 | COPY_OPT_SCTX(buf, BV_CINK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7014 | buf->b_p_cino = vim_strsave(p_cino); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7015 | COPY_OPT_SCTX(buf, BV_CINO); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 7016 | buf->b_p_cinsd = vim_strsave(p_cinsd); |
| 7017 | COPY_OPT_SCTX(buf, BV_CINSD); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 7018 | buf->b_p_lop = vim_strsave(p_lop); |
| 7019 | COPY_OPT_SCTX(buf, BV_LOP); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7020 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7021 | // Don't copy 'filetype', it must be detected |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7022 | buf->b_p_ft = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7023 | buf->b_p_pi = p_pi; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7024 | COPY_OPT_SCTX(buf, BV_PI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7025 | buf->b_p_cinw = vim_strsave(p_cinw); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7026 | COPY_OPT_SCTX(buf, BV_CINW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7027 | buf->b_p_lisp = p_lisp; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7028 | COPY_OPT_SCTX(buf, BV_LISP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7029 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7030 | // Don't copy 'syntax', it must be set |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7031 | buf->b_p_syn = empty_option; |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 7032 | buf->b_p_smc = p_smc; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7033 | COPY_OPT_SCTX(buf, BV_SMC); |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 7034 | buf->b_s.b_syn_isk = empty_option; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 7035 | #endif |
| 7036 | #ifdef FEAT_SPELL |
Bram Moolenaar | d5784f9 | 2010-10-13 14:05:35 +0200 | [diff] [blame] | 7037 | buf->b_s.b_p_spc = vim_strsave(p_spc); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7038 | COPY_OPT_SCTX(buf, BV_SPC); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 7039 | (void)compile_cap_prog(&buf->b_s); |
| 7040 | buf->b_s.b_p_spf = vim_strsave(p_spf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7041 | COPY_OPT_SCTX(buf, BV_SPF); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 7042 | buf->b_s.b_p_spl = vim_strsave(p_spl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7043 | COPY_OPT_SCTX(buf, BV_SPL); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 7044 | buf->b_s.b_p_spo = vim_strsave(p_spo); |
| 7045 | COPY_OPT_SCTX(buf, BV_SPO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7046 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7047 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7048 | buf->b_p_inde = vim_strsave(p_inde); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7049 | COPY_OPT_SCTX(buf, BV_INDE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7050 | buf->b_p_indk = vim_strsave(p_indk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7051 | COPY_OPT_SCTX(buf, BV_INDK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7052 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 7053 | buf->b_p_fp = empty_option; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 7054 | #if defined(FEAT_EVAL) |
| 7055 | buf->b_p_fex = vim_strsave(p_fex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7056 | COPY_OPT_SCTX(buf, BV_FEX); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 7057 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7058 | #ifdef FEAT_CRYPT |
| 7059 | buf->b_p_key = vim_strsave(p_key); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7060 | COPY_OPT_SCTX(buf, BV_KEY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7061 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7062 | buf->b_p_sua = vim_strsave(p_sua); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7063 | COPY_OPT_SCTX(buf, BV_SUA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7064 | #ifdef FEAT_KEYMAP |
| 7065 | buf->b_p_keymap = vim_strsave(p_keymap); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7066 | COPY_OPT_SCTX(buf, BV_KMAP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7067 | buf->b_kmap_state |= KEYMAP_INIT; |
| 7068 | #endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 7069 | #ifdef FEAT_TERMINAL |
| 7070 | buf->b_p_twsl = p_twsl; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7071 | COPY_OPT_SCTX(buf, BV_TWSL); |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 7072 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7073 | // This isn't really an option, but copying the langmap and IME |
| 7074 | // state from the current buffer is better than resetting it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7075 | buf->b_p_iminsert = p_iminsert; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7076 | COPY_OPT_SCTX(buf, BV_IMI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7077 | buf->b_p_imsearch = p_imsearch; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7078 | COPY_OPT_SCTX(buf, BV_IMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7079 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7080 | // options that are normally global but also have a local value |
| 7081 | // are not copied, start using the global value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7082 | buf->b_p_ar = -1; |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 7083 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7084 | buf->b_p_bkc = empty_option; |
| 7085 | buf->b_bkc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7086 | #ifdef FEAT_QUICKFIX |
| 7087 | buf->b_p_gp = empty_option; |
| 7088 | buf->b_p_mp = empty_option; |
| 7089 | buf->b_p_efm = empty_option; |
| 7090 | #endif |
| 7091 | buf->b_p_ep = empty_option; |
| 7092 | buf->b_p_kp = empty_option; |
| 7093 | buf->b_p_path = empty_option; |
| 7094 | buf->b_p_tags = empty_option; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 7095 | buf->b_p_tc = empty_option; |
| 7096 | buf->b_tc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7097 | #ifdef FEAT_FIND_ID |
| 7098 | buf->b_p_def = empty_option; |
| 7099 | buf->b_p_inc = empty_option; |
| 7100 | # ifdef FEAT_EVAL |
| 7101 | buf->b_p_inex = vim_strsave(p_inex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7102 | COPY_OPT_SCTX(buf, BV_INEX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7103 | # endif |
| 7104 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7105 | buf->b_p_dict = empty_option; |
| 7106 | buf->b_p_tsr = empty_option; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 7107 | #ifdef FEAT_COMPL_FUNC |
| 7108 | buf->b_p_tsrfu = empty_option; |
| 7109 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 7110 | buf->b_p_qe = vim_strsave(p_qe); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7111 | COPY_OPT_SCTX(buf, BV_QE); |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 7112 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 7113 | buf->b_p_bexpr = empty_option; |
| 7114 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 7115 | #if defined(FEAT_CRYPT) |
| 7116 | buf->b_p_cm = empty_option; |
| 7117 | #endif |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7118 | #ifdef FEAT_PERSISTENT_UNDO |
| 7119 | buf->b_p_udf = p_udf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7120 | COPY_OPT_SCTX(buf, BV_UDF); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7121 | #endif |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 7122 | buf->b_p_lw = empty_option; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 7123 | buf->b_p_menc = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7124 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7125 | // Don't copy the options set by ex_help(), use the saved values, |
| 7126 | // when going from a help buffer to a non-help buffer. |
| 7127 | // Don't touch these at all when BCO_NOHELP is used and going from |
| 7128 | // or to a help buffer. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7129 | if (dont_do_help) |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7130 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7131 | buf->b_p_isk = save_p_isk; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7132 | #ifdef FEAT_VARTABS |
Yegappan Lakshmanan | 960dcbd | 2023-03-07 17:45:11 +0000 | [diff] [blame] | 7133 | if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7134 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7135 | else |
| 7136 | buf->b_p_vts_array = NULL; |
| 7137 | #endif |
| 7138 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7139 | else |
| 7140 | { |
| 7141 | buf->b_p_isk = vim_strsave(p_isk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7142 | COPY_OPT_SCTX(buf, BV_ISK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7143 | did_isk = TRUE; |
| 7144 | buf->b_p_ts = p_ts; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 7145 | COPY_OPT_SCTX(buf, BV_TS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7146 | #ifdef FEAT_VARTABS |
| 7147 | buf->b_p_vts = vim_strsave(p_vts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7148 | COPY_OPT_SCTX(buf, BV_VTS); |
Yegappan Lakshmanan | 960dcbd | 2023-03-07 17:45:11 +0000 | [diff] [blame] | 7149 | if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7150 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7151 | else |
| 7152 | buf->b_p_vts_array = NULL; |
| 7153 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7154 | buf->b_help = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7155 | if (buf->b_p_bt[0] == 'h') |
| 7156 | clear_string_option(&buf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7157 | buf->b_p_ma = p_ma; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7158 | COPY_OPT_SCTX(buf, BV_MA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7159 | } |
| 7160 | } |
| 7161 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7162 | // When the options should be copied (ignoring BCO_ALWAYS), set the |
| 7163 | // flag that indicates that the options have been initialized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7164 | if (should_copy) |
| 7165 | buf->b_p_initialized = TRUE; |
| 7166 | } |
| 7167 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7168 | check_buf_options(buf); // make sure we don't have NULLs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7169 | if (did_isk) |
| 7170 | (void)buf_init_chartab(buf, FALSE); |
| 7171 | } |
| 7172 | |
| 7173 | /* |
| 7174 | * Reset the 'modifiable' option and its default value. |
| 7175 | */ |
| 7176 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7177 | reset_modifiable(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7178 | { |
| 7179 | int opt_idx; |
| 7180 | |
| 7181 | curbuf->b_p_ma = FALSE; |
| 7182 | p_ma = FALSE; |
| 7183 | opt_idx = findoption((char_u *)"ma"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7184 | if (opt_idx >= 0) |
| 7185 | options[opt_idx].def_val[VI_DEFAULT] = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | /* |
| 7189 | * Set the global value for 'iminsert' to the local value. |
| 7190 | */ |
| 7191 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7192 | set_iminsert_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7193 | { |
| 7194 | p_iminsert = curbuf->b_p_iminsert; |
| 7195 | } |
| 7196 | |
| 7197 | /* |
| 7198 | * Set the global value for 'imsearch' to the local value. |
| 7199 | */ |
| 7200 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7201 | set_imsearch_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7202 | { |
| 7203 | p_imsearch = curbuf->b_p_imsearch; |
| 7204 | } |
| 7205 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7206 | static int expand_option_idx = -1; |
| 7207 | static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; |
| 7208 | static int expand_option_flags = 0; |
| 7209 | |
| 7210 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7211 | set_context_in_set_cmd( |
| 7212 | expand_T *xp, |
| 7213 | char_u *arg, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7214 | int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7215 | { |
| 7216 | int nextchar; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7217 | long_u flags = 0; // init for GCC |
| 7218 | int opt_idx = 0; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7219 | char_u *p; |
| 7220 | char_u *s; |
| 7221 | int is_term_option = FALSE; |
| 7222 | int key; |
| 7223 | |
| 7224 | expand_option_flags = opt_flags; |
| 7225 | |
| 7226 | xp->xp_context = EXPAND_SETTINGS; |
| 7227 | if (*arg == NUL) |
| 7228 | { |
| 7229 | xp->xp_pattern = arg; |
| 7230 | return; |
| 7231 | } |
| 7232 | p = arg + STRLEN(arg) - 1; |
| 7233 | if (*p == ' ' && *(p - 1) != '\\') |
| 7234 | { |
| 7235 | xp->xp_pattern = p + 1; |
| 7236 | return; |
| 7237 | } |
| 7238 | while (p > arg) |
| 7239 | { |
| 7240 | s = p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7241 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7242 | if (*p == ' ' || *p == ',') |
| 7243 | { |
| 7244 | while (s > arg && *(s - 1) == '\\') |
| 7245 | --s; |
| 7246 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7247 | // break at a space with an even number of backslashes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7248 | if (*p == ' ' && ((p - s) & 1) == 0) |
| 7249 | { |
| 7250 | ++p; |
| 7251 | break; |
| 7252 | } |
| 7253 | --p; |
| 7254 | } |
Bram Moolenaar | 2a7b9ee | 2009-06-16 15:50:33 +0000 | [diff] [blame] | 7255 | if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7256 | { |
| 7257 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7258 | xp->xp_prefix = XP_PREFIX_NO; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7259 | p += 2; |
| 7260 | } |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7261 | else if (STRNCMP(p, "inv", 3) == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7262 | { |
| 7263 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7264 | xp->xp_prefix = XP_PREFIX_INV; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7265 | p += 3; |
| 7266 | } |
| 7267 | xp->xp_pattern = arg = p; |
| 7268 | if (*arg == '<') |
| 7269 | { |
| 7270 | while (*p != '>') |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7271 | if (*p++ == NUL) // expand terminal option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7272 | return; |
| 7273 | key = get_special_key_code(arg + 1); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7274 | if (key == 0) // unknown name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7275 | { |
| 7276 | xp->xp_context = EXPAND_NOTHING; |
| 7277 | return; |
| 7278 | } |
| 7279 | nextchar = *++p; |
| 7280 | is_term_option = TRUE; |
| 7281 | expand_option_name[2] = KEY2TERMCAP0(key); |
| 7282 | expand_option_name[3] = KEY2TERMCAP1(key); |
| 7283 | } |
| 7284 | else |
| 7285 | { |
| 7286 | if (p[0] == 't' && p[1] == '_') |
| 7287 | { |
| 7288 | p += 2; |
| 7289 | if (*p != NUL) |
| 7290 | ++p; |
| 7291 | if (*p == NUL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7292 | return; // expand option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7293 | nextchar = *++p; |
| 7294 | is_term_option = TRUE; |
| 7295 | expand_option_name[2] = p[-2]; |
| 7296 | expand_option_name[3] = p[-1]; |
| 7297 | } |
| 7298 | else |
| 7299 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7300 | // Allow * wildcard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7301 | while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') |
| 7302 | p++; |
| 7303 | if (*p == NUL) |
| 7304 | return; |
| 7305 | nextchar = *p; |
| 7306 | *p = NUL; |
| 7307 | opt_idx = findoption(arg); |
| 7308 | *p = nextchar; |
| 7309 | if (opt_idx == -1 || options[opt_idx].var == NULL) |
| 7310 | { |
| 7311 | xp->xp_context = EXPAND_NOTHING; |
| 7312 | return; |
| 7313 | } |
| 7314 | flags = options[opt_idx].flags; |
| 7315 | if (flags & P_BOOL) |
| 7316 | { |
| 7317 | xp->xp_context = EXPAND_NOTHING; |
| 7318 | return; |
| 7319 | } |
| 7320 | } |
| 7321 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7322 | // handle "-=" and "+=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7323 | if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') |
| 7324 | { |
| 7325 | ++p; |
| 7326 | nextchar = '='; |
| 7327 | } |
| 7328 | if ((nextchar != '=' && nextchar != ':') |
| 7329 | || xp->xp_context == EXPAND_BOOL_SETTINGS) |
| 7330 | { |
| 7331 | xp->xp_context = EXPAND_UNSUCCESSFUL; |
| 7332 | return; |
| 7333 | } |
| 7334 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL) |
| 7335 | { |
| 7336 | xp->xp_context = EXPAND_OLD_SETTING; |
| 7337 | if (is_term_option) |
| 7338 | expand_option_idx = -1; |
| 7339 | else |
| 7340 | expand_option_idx = opt_idx; |
| 7341 | xp->xp_pattern = p + 1; |
| 7342 | return; |
| 7343 | } |
| 7344 | xp->xp_context = EXPAND_NOTHING; |
| 7345 | if (is_term_option || (flags & P_NUM)) |
| 7346 | return; |
| 7347 | |
| 7348 | xp->xp_pattern = p + 1; |
| 7349 | |
| 7350 | if (flags & P_EXPAND) |
| 7351 | { |
| 7352 | p = options[opt_idx].var; |
| 7353 | if (p == (char_u *)&p_bdir |
| 7354 | || p == (char_u *)&p_dir |
| 7355 | || p == (char_u *)&p_path |
Bram Moolenaar | f6fee0e | 2016-02-21 23:02:49 +0100 | [diff] [blame] | 7356 | || p == (char_u *)&p_pp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7357 | || p == (char_u *)&p_rtp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7358 | || p == (char_u *)&p_cdpath |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7359 | #ifdef FEAT_SESSION |
| 7360 | || p == (char_u *)&p_vdir |
| 7361 | #endif |
| 7362 | ) |
| 7363 | { |
| 7364 | xp->xp_context = EXPAND_DIRECTORIES; |
Bram Moolenaar | f80f40a | 2022-08-25 16:02:23 +0100 | [diff] [blame] | 7365 | if (p == (char_u *)&p_path || p == (char_u *)&p_cdpath) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7366 | xp->xp_backslash = XP_BS_THREE; |
| 7367 | else |
| 7368 | xp->xp_backslash = XP_BS_ONE; |
| 7369 | } |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 7370 | else if (p == (char_u *)&p_ft) |
| 7371 | { |
| 7372 | xp->xp_context = EXPAND_FILETYPE; |
| 7373 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7374 | else |
| 7375 | { |
| 7376 | xp->xp_context = EXPAND_FILES; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7377 | // for 'tags' need three backslashes for a space |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7378 | if (p == (char_u *)&p_tags) |
| 7379 | xp->xp_backslash = XP_BS_THREE; |
| 7380 | else |
| 7381 | xp->xp_backslash = XP_BS_ONE; |
| 7382 | } |
| 7383 | } |
| 7384 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7385 | // For an option that is a list of file names, find the start of the |
| 7386 | // last file name. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7387 | for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) |
| 7388 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7389 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7390 | if (*p == ' ' || *p == ',') |
| 7391 | { |
| 7392 | s = p; |
| 7393 | while (s > xp->xp_pattern && *(s - 1) == '\\') |
| 7394 | --s; |
| 7395 | if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) |
| 7396 | || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) |
| 7397 | { |
| 7398 | xp->xp_pattern = p + 1; |
| 7399 | break; |
| 7400 | } |
| 7401 | } |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 7402 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 7403 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7404 | // for 'spellsuggest' start at "file:" |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 7405 | if (options[opt_idx].var == (char_u *)&p_sps |
| 7406 | && STRNCMP(p, "file:", 5) == 0) |
| 7407 | { |
| 7408 | xp->xp_pattern = p + 5; |
| 7409 | break; |
| 7410 | } |
| 7411 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7412 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7413 | } |
| 7414 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7415 | /* |
| 7416 | * Returns TRUE if 'str' either matches 'regmatch' or fuzzy matches 'pat'. |
| 7417 | * |
| 7418 | * If 'test_only' is TRUE and 'fuzzy' is FALSE and if 'str' matches the regular |
| 7419 | * expression 'regmatch', then returns TRUE. Otherwise returns FALSE. |
| 7420 | * |
| 7421 | * If 'test_only' is FALSE and 'fuzzy' is FALSE and if 'str' matches the |
| 7422 | * regular expression 'regmatch', then stores the match in matches[idx] and |
| 7423 | * returns TRUE. |
| 7424 | * |
| 7425 | * If 'test_only' is TRUE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7426 | * 'fuzzystr', then returns TRUE. Otherwise returns FALSE. |
| 7427 | * |
| 7428 | * If 'test_only' is FALSE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7429 | * 'fuzzystr', then stores the match details in fuzmatch[idx] and returns TRUE. |
| 7430 | */ |
| 7431 | static int |
| 7432 | match_str( |
| 7433 | char_u *str, |
| 7434 | regmatch_T *regmatch, |
| 7435 | char_u **matches, |
| 7436 | int idx, |
| 7437 | int test_only, |
| 7438 | int fuzzy, |
| 7439 | char_u *fuzzystr, |
| 7440 | fuzmatch_str_T *fuzmatch) |
| 7441 | { |
| 7442 | if (!fuzzy) |
| 7443 | { |
| 7444 | if (vim_regexec(regmatch, str, (colnr_T)0)) |
| 7445 | { |
| 7446 | if (!test_only) |
| 7447 | matches[idx] = vim_strsave(str); |
| 7448 | return TRUE; |
| 7449 | } |
| 7450 | } |
| 7451 | else |
| 7452 | { |
| 7453 | int score; |
| 7454 | |
| 7455 | score = fuzzy_match_str(str, fuzzystr); |
| 7456 | if (score != 0) |
| 7457 | { |
| 7458 | if (!test_only) |
| 7459 | { |
| 7460 | fuzmatch[idx].idx = idx; |
| 7461 | fuzmatch[idx].str = vim_strsave(str); |
| 7462 | fuzmatch[idx].score = score; |
| 7463 | } |
| 7464 | |
| 7465 | return TRUE; |
| 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | return FALSE; |
| 7470 | } |
| 7471 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7472 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7473 | ExpandSettings( |
| 7474 | expand_T *xp, |
| 7475 | regmatch_T *regmatch, |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7476 | char_u *fuzzystr, |
| 7477 | int *numMatches, |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7478 | char_u ***matches, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7479 | int can_fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7480 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7481 | int num_normal = 0; // Nr of matching non-term-code settings |
| 7482 | int num_term = 0; // Nr of matching terminal code settings |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7483 | int opt_idx; |
| 7484 | int match; |
| 7485 | int count = 0; |
| 7486 | char_u *str; |
| 7487 | int loop; |
| 7488 | int is_term_opt; |
| 7489 | char_u name_buf[MAX_KEY_NAME_LEN]; |
| 7490 | static char *(names[]) = {"all", "termcap"}; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7491 | int ic = regmatch->rm_ic; // remember the ignore-case flag |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7492 | int fuzzy; |
| 7493 | fuzmatch_str_T *fuzmatch = NULL; |
| 7494 | |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7495 | fuzzy = can_fuzzy && cmdline_fuzzy_complete(fuzzystr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7496 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7497 | // do this loop twice: |
| 7498 | // loop == 0: count the number of matching options |
| 7499 | // loop == 1: copy the matching options into allocated memory |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7500 | for (loop = 0; loop <= 1; ++loop) |
| 7501 | { |
| 7502 | regmatch->rm_ic = ic; |
| 7503 | if (xp->xp_context != EXPAND_BOOL_SETTINGS) |
| 7504 | { |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 7505 | for (match = 0; match < (int)ARRAY_LENGTH(names); ++match) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7506 | { |
| 7507 | if (match_str((char_u *)names[match], regmatch, *matches, |
| 7508 | count, (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7509 | { |
| 7510 | if (loop == 0) |
| 7511 | num_normal++; |
| 7512 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7513 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7514 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7515 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7516 | } |
| 7517 | for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; |
| 7518 | opt_idx++) |
| 7519 | { |
| 7520 | if (options[opt_idx].var == NULL) |
| 7521 | continue; |
| 7522 | if (xp->xp_context == EXPAND_BOOL_SETTINGS |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7523 | && !(options[opt_idx].flags & P_BOOL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7524 | continue; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7525 | is_term_opt = istermoption_idx(opt_idx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7526 | if (is_term_opt && num_normal > 0) |
| 7527 | continue; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7528 | |
| 7529 | if (match_str(str, regmatch, *matches, count, (loop == 0), |
| 7530 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7531 | { |
| 7532 | if (loop == 0) |
| 7533 | { |
| 7534 | if (is_term_opt) |
| 7535 | num_term++; |
| 7536 | else |
| 7537 | num_normal++; |
| 7538 | } |
| 7539 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7540 | count++; |
| 7541 | } |
| 7542 | else if (!fuzzy && options[opt_idx].shortname != NULL |
| 7543 | && vim_regexec(regmatch, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7544 | (char_u *)options[opt_idx].shortname, (colnr_T)0)) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7545 | { |
| 7546 | // Compare against the abbreviated option name (for regular |
| 7547 | // expression match). Fuzzy matching (previous if) already |
| 7548 | // matches against both the expanded and abbreviated names. |
| 7549 | if (loop == 0) |
| 7550 | { |
| 7551 | if (is_term_opt) |
| 7552 | num_term++; |
| 7553 | else |
| 7554 | num_normal++; |
| 7555 | } |
| 7556 | else |
| 7557 | (*matches)[count++] = vim_strsave(str); |
| 7558 | } |
| 7559 | else if (is_term_opt) |
| 7560 | { |
| 7561 | name_buf[0] = '<'; |
| 7562 | name_buf[1] = 't'; |
| 7563 | name_buf[2] = '_'; |
| 7564 | name_buf[3] = str[2]; |
| 7565 | name_buf[4] = str[3]; |
| 7566 | name_buf[5] = '>'; |
| 7567 | name_buf[6] = NUL; |
| 7568 | |
| 7569 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7570 | fuzzy, fuzzystr, fuzmatch)) |
| 7571 | { |
| 7572 | if (loop == 0) |
| 7573 | num_term++; |
| 7574 | else |
| 7575 | count++; |
| 7576 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7577 | } |
| 7578 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7579 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7580 | // Check terminal key codes, these are not in the option table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7581 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) |
| 7582 | { |
| 7583 | for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) |
| 7584 | { |
| 7585 | if (!isprint(str[0]) || !isprint(str[1])) |
| 7586 | continue; |
| 7587 | |
| 7588 | name_buf[0] = 't'; |
| 7589 | name_buf[1] = '_'; |
| 7590 | name_buf[2] = str[0]; |
| 7591 | name_buf[3] = str[1]; |
| 7592 | name_buf[4] = NUL; |
| 7593 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7594 | if (match_str(name_buf, regmatch, *matches, count, |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7595 | (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7596 | { |
| 7597 | if (loop == 0) |
| 7598 | num_term++; |
| 7599 | else |
| 7600 | count++; |
| 7601 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7602 | else |
| 7603 | { |
| 7604 | name_buf[0] = '<'; |
| 7605 | name_buf[1] = 't'; |
| 7606 | name_buf[2] = '_'; |
| 7607 | name_buf[3] = str[0]; |
| 7608 | name_buf[4] = str[1]; |
| 7609 | name_buf[5] = '>'; |
| 7610 | name_buf[6] = NUL; |
| 7611 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7612 | if (match_str(name_buf, regmatch, *matches, count, |
| 7613 | (loop == 0), fuzzy, fuzzystr, |
| 7614 | fuzmatch)) |
| 7615 | { |
| 7616 | if (loop == 0) |
| 7617 | num_term++; |
| 7618 | else |
| 7619 | count++; |
| 7620 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7621 | } |
| 7622 | } |
| 7623 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7624 | // Check special key names. |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7625 | regmatch->rm_ic = TRUE; // ignore case here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7626 | for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) |
| 7627 | { |
| 7628 | name_buf[0] = '<'; |
| 7629 | STRCPY(name_buf + 1, str); |
| 7630 | STRCAT(name_buf, ">"); |
| 7631 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7632 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7633 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7634 | { |
| 7635 | if (loop == 0) |
| 7636 | num_term++; |
| 7637 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7638 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7639 | } |
| 7640 | } |
| 7641 | } |
| 7642 | if (loop == 0) |
| 7643 | { |
| 7644 | if (num_normal > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7645 | *numMatches = num_normal; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7646 | else if (num_term > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7647 | *numMatches = num_term; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7648 | else |
| 7649 | return OK; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7650 | if (!fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7651 | { |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7652 | *matches = ALLOC_MULT(char_u *, *numMatches); |
| 7653 | if (*matches == NULL) |
| 7654 | { |
| 7655 | *matches = (char_u **)""; |
| 7656 | return FAIL; |
| 7657 | } |
| 7658 | } |
| 7659 | else |
| 7660 | { |
| 7661 | fuzmatch = ALLOC_MULT(fuzmatch_str_T, *numMatches); |
| 7662 | if (fuzmatch == NULL) |
| 7663 | { |
| 7664 | *matches = (char_u **)""; |
| 7665 | return FAIL; |
| 7666 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7667 | } |
| 7668 | } |
| 7669 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7670 | |
| 7671 | if (fuzzy && |
| 7672 | fuzzymatches_to_strmatches(fuzmatch, matches, count, FALSE) == FAIL) |
| 7673 | return FAIL; |
| 7674 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7675 | return OK; |
| 7676 | } |
| 7677 | |
| 7678 | int |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7679 | ExpandOldSetting(int *numMatches, char_u ***matches) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7680 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7681 | char_u *var = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7682 | char_u *buf; |
| 7683 | |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7684 | *numMatches = 0; |
| 7685 | *matches = ALLOC_ONE(char_u *); |
| 7686 | if (*matches == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7687 | return FAIL; |
| 7688 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7689 | // For a terminal key code expand_option_idx is < 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7690 | if (expand_option_idx < 0) |
| 7691 | { |
| 7692 | var = find_termcode(expand_option_name + 2); |
| 7693 | if (var == NULL) |
| 7694 | expand_option_idx = findoption(expand_option_name); |
| 7695 | } |
| 7696 | |
| 7697 | if (expand_option_idx >= 0) |
| 7698 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7699 | // put string of option value in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7700 | option_value2string(&options[expand_option_idx], expand_option_flags); |
| 7701 | var = NameBuff; |
| 7702 | } |
| 7703 | else if (var == NULL) |
| 7704 | var = (char_u *)""; |
| 7705 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7706 | // A backslash is required before some characters. This is the reverse of |
| 7707 | // what happens in do_set(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7708 | buf = vim_strsave_escaped(var, escape_chars); |
| 7709 | |
| 7710 | if (buf == NULL) |
| 7711 | { |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7712 | VIM_CLEAR(*matches); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7713 | return FAIL; |
| 7714 | } |
| 7715 | |
| 7716 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7717 | // For MS-Windows et al. we don't double backslashes at the start and |
| 7718 | // before a file name character. |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 7719 | for (var = buf; *var != NUL; MB_PTR_ADV(var)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7720 | if (var[0] == '\\' && var[1] == '\\' |
| 7721 | && expand_option_idx >= 0 |
| 7722 | && (options[expand_option_idx].flags & P_EXPAND) |
| 7723 | && vim_isfilec(var[2]) |
| 7724 | && (var[2] != '\\' || (var == buf && var[4] != '\\'))) |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 7725 | STRMOVE(var, var + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7726 | #endif |
| 7727 | |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7728 | *matches[0] = buf; |
| 7729 | *numMatches = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7730 | return OK; |
| 7731 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7732 | |
| 7733 | /* |
| 7734 | * Get the value for the numeric or string option *opp in a nice format into |
| 7735 | * NameBuff[]. Must not be called with a hidden option! |
| 7736 | */ |
| 7737 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7738 | option_value2string( |
| 7739 | struct vimoption *opp, |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 7740 | int scope) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7741 | { |
| 7742 | char_u *varp; |
| 7743 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 7744 | varp = get_varp_scope(opp, scope); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7745 | |
| 7746 | if (opp->flags & P_NUM) |
| 7747 | { |
| 7748 | long wc = 0; |
| 7749 | |
| 7750 | if (wc_use_keyname(varp, &wc)) |
| 7751 | STRCPY(NameBuff, get_special_key_name((int)wc, 0)); |
| 7752 | else if (wc != 0) |
| 7753 | STRCPY(NameBuff, transchar((int)wc)); |
| 7754 | else |
| 7755 | sprintf((char *)NameBuff, "%ld", *(long *)varp); |
| 7756 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7757 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7758 | { |
| 7759 | varp = *(char_u **)(varp); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7760 | if (varp == NULL) // just in case |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7761 | NameBuff[0] = NUL; |
| 7762 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7763 | // 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] | 7764 | else if (opp->var == (char_u *)&p_key && *varp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7765 | STRCPY(NameBuff, "*****"); |
| 7766 | #endif |
| 7767 | else if (opp->flags & P_EXPAND) |
| 7768 | home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7769 | // Translate 'pastetoggle' into special key names |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7770 | else if ((char_u **)opp->var == &p_pt) |
| 7771 | str2specialbuf(p_pt, NameBuff, MAXPATHL); |
| 7772 | else |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 7773 | vim_strncpy(NameBuff, varp, MAXPATHL - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7774 | } |
| 7775 | } |
| 7776 | |
| 7777 | /* |
| 7778 | * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be |
| 7779 | * printed as a keyname. |
| 7780 | * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. |
| 7781 | */ |
| 7782 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7783 | wc_use_keyname(char_u *varp, long *wcp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7784 | { |
| 7785 | if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) |
| 7786 | { |
| 7787 | *wcp = *(long *)varp; |
| 7788 | if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) |
| 7789 | return TRUE; |
| 7790 | } |
| 7791 | return FALSE; |
| 7792 | } |
| 7793 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7794 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7795 | * Return TRUE if "x" is present in 'shortmess' option, or |
| 7796 | * 'shortmess' contains 'a' and "x" is present in SHM_A. |
| 7797 | */ |
| 7798 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7799 | shortmess(int x) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7800 | { |
Bram Moolenaar | 7f29f7a | 2012-02-29 13:51:37 +0100 | [diff] [blame] | 7801 | return p_shm != NULL && |
| 7802 | ( vim_strchr(p_shm, x) != NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7803 | || (vim_strchr(p_shm, 'a') != NULL |
| 7804 | && vim_strchr((char_u *)SHM_A, x) != NULL)); |
| 7805 | } |
| 7806 | |
| 7807 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7808 | * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. |
| 7809 | * |
| 7810 | * Reset 'compatible' and set the values for options that didn't get set yet |
| 7811 | * to the Vim defaults. |
| 7812 | * 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] | 7813 | * 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] | 7814 | */ |
| 7815 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7816 | vimrc_found(char_u *fname, char_u *envname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7817 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7818 | int opt_idx; |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 7819 | int dofree = FALSE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7820 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7821 | |
| 7822 | if (!option_was_set((char_u *)"cp")) |
| 7823 | { |
| 7824 | p_cp = FALSE; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7825 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7826 | if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) |
| 7827 | set_option_default(opt_idx, OPT_FREE, FALSE); |
| 7828 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 7829 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7830 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7831 | |
| 7832 | if (fname != NULL) |
| 7833 | { |
| 7834 | p = vim_getenv(envname, &dofree); |
| 7835 | if (p == NULL) |
| 7836 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7837 | // Set $MYVIMRC to the first vimrc file found. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7838 | p = FullName_save(fname, FALSE); |
| 7839 | if (p != NULL) |
| 7840 | { |
| 7841 | vim_setenv(envname, p); |
| 7842 | vim_free(p); |
| 7843 | } |
| 7844 | } |
| 7845 | else if (dofree) |
| 7846 | vim_free(p); |
| 7847 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | /* |
| 7851 | * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. |
| 7852 | */ |
| 7853 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7854 | change_compatible(int on) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7855 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7856 | int opt_idx; |
| 7857 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7858 | if (p_cp != on) |
| 7859 | { |
| 7860 | p_cp = on; |
| 7861 | compatible_set(); |
| 7862 | } |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7863 | opt_idx = findoption((char_u *)"cp"); |
| 7864 | if (opt_idx >= 0) |
| 7865 | options[opt_idx].flags |= P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7866 | } |
| 7867 | |
| 7868 | /* |
| 7869 | * Return TRUE when option "name" has been set. |
Bram Moolenaar | 1a4a75c | 2013-07-28 16:03:06 +0200 | [diff] [blame] | 7870 | * Only works correctly for global options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7871 | */ |
| 7872 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7873 | option_was_set(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7874 | { |
| 7875 | int idx; |
| 7876 | |
| 7877 | idx = findoption(name); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7878 | if (idx < 0) // unknown option |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7879 | return FALSE; |
| 7880 | if (options[idx].flags & P_WAS_SET) |
| 7881 | return TRUE; |
| 7882 | return FALSE; |
| 7883 | } |
| 7884 | |
| 7885 | /* |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7886 | * Reset the flag indicating option "name" was set. |
| 7887 | */ |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 7888 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7889 | reset_option_was_set(char_u *name) |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7890 | { |
| 7891 | int idx = findoption(name); |
| 7892 | |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 7893 | if (idx < 0) |
| 7894 | return FAIL; |
| 7895 | |
| 7896 | options[idx].flags &= ~P_WAS_SET; |
| 7897 | return OK; |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7901 | * compatible_set() - Called when 'compatible' has been set or unset. |
| 7902 | * |
| 7903 | * When 'compatible' set: Set all relevant options (those that have the P_VIM) |
| 7904 | * flag) to a Vi compatible value. |
| 7905 | * When 'compatible' is unset: Set all options that have a different default |
| 7906 | * for Vim (without the P_VI_DEF flag) to that default. |
| 7907 | */ |
| 7908 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7909 | compatible_set(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7910 | { |
| 7911 | int opt_idx; |
| 7912 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7913 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7914 | if ( ((options[opt_idx].flags & P_VIM) && p_cp) |
| 7915 | || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) |
| 7916 | set_option_default(opt_idx, OPT_FREE, p_cp); |
| 7917 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 7918 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7921 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7922 | * Check if backspacing over something is allowed. |
| 7923 | */ |
| 7924 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7925 | can_bs( |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 7926 | int what) // BS_INDENT, BS_EOL, BS_START or BS_NOSTOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7927 | { |
Bram Moolenaar | 6b810d9 | 2018-06-04 17:28:44 +0200 | [diff] [blame] | 7928 | #ifdef FEAT_JOB_CHANNEL |
| 7929 | if (what == BS_START && bt_prompt(curbuf)) |
| 7930 | return FALSE; |
| 7931 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7932 | switch (*p_bs) |
| 7933 | { |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 7934 | case '3': return TRUE; |
| 7935 | case '2': return (what != BS_NOSTOP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7936 | case '1': return (what != BS_START); |
| 7937 | case '0': return FALSE; |
| 7938 | } |
| 7939 | return vim_strchr(p_bs, what) != NULL; |
| 7940 | } |
| 7941 | |
| 7942 | /* |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 7943 | * Return the effective 'scrolloff' value for the current window, using the |
| 7944 | * global value when appropriate. |
| 7945 | */ |
| 7946 | long |
| 7947 | get_scrolloff_value(void) |
| 7948 | { |
| 7949 | return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; |
| 7950 | } |
| 7951 | |
| 7952 | /* |
| 7953 | * Return the effective 'sidescrolloff' value for the current window, using the |
| 7954 | * global value when appropriate. |
| 7955 | */ |
| 7956 | long |
| 7957 | get_sidescrolloff_value(void) |
| 7958 | { |
| 7959 | return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; |
| 7960 | } |
| 7961 | |
| 7962 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7963 | * Get the local or global value of 'backupcopy'. |
| 7964 | */ |
| 7965 | unsigned int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7966 | get_bkc_value(buf_T *buf) |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7967 | { |
| 7968 | return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; |
| 7969 | } |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 7970 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 7971 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 7972 | /* |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 7973 | * Get the local or global value of 'formatlistpat'. |
| 7974 | */ |
| 7975 | char_u * |
| 7976 | get_flp_value(buf_T *buf) |
| 7977 | { |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 7978 | if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL) |
| 7979 | return p_flp; |
| 7980 | return buf->b_p_flp; |
| 7981 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 7982 | #endif |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 7983 | |
| 7984 | /* |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 7985 | * Get the local or global value of the 'virtualedit' flags. |
| 7986 | */ |
| 7987 | unsigned int |
| 7988 | get_ve_flags(void) |
| 7989 | { |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 7990 | return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) |
| 7991 | & ~(VE_NONE | VE_NONEU); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 7992 | } |
| 7993 | |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 7994 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 7995 | /* |
| 7996 | * Get the local or global value of 'showbreak'. |
| 7997 | */ |
| 7998 | char_u * |
| 7999 | get_showbreak_value(win_T *win) |
| 8000 | { |
| 8001 | if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) |
| 8002 | return p_sbr; |
| 8003 | if (STRCMP(win->w_p_sbr, "NONE") == 0) |
| 8004 | return empty_option; |
| 8005 | return win->w_p_sbr; |
| 8006 | } |
| 8007 | #endif |
| 8008 | |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8009 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 8010 | /* |
| 8011 | * Get window or buffer local options. |
| 8012 | */ |
| 8013 | dict_T * |
| 8014 | get_winbuf_options(int bufopt) |
| 8015 | { |
| 8016 | dict_T *d; |
| 8017 | int opt_idx; |
| 8018 | |
| 8019 | d = dict_alloc(); |
| 8020 | if (d == NULL) |
| 8021 | return NULL; |
| 8022 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8023 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8024 | { |
| 8025 | struct vimoption *opt = &options[opt_idx]; |
| 8026 | |
| 8027 | if ((bufopt && (opt->indir & PV_BUF)) |
| 8028 | || (!bufopt && (opt->indir & PV_WIN))) |
| 8029 | { |
| 8030 | char_u *varp = get_varp(opt); |
| 8031 | |
| 8032 | if (varp != NULL) |
| 8033 | { |
| 8034 | if (opt->flags & P_STRING) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8035 | dict_add_string(d, opt->fullname, *(char_u **)varp); |
Bram Moolenaar | 789a5c0 | 2016-09-12 19:51:11 +0200 | [diff] [blame] | 8036 | else if (opt->flags & P_NUM) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8037 | dict_add_number(d, opt->fullname, *(long *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8038 | else |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8039 | dict_add_number(d, opt->fullname, *(int *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8040 | } |
| 8041 | } |
| 8042 | } |
| 8043 | |
| 8044 | return d; |
| 8045 | } |
| 8046 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8047 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8048 | #if defined(FEAT_SYN_HL) || defined(PROTO) |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8049 | /* |
| 8050 | * This is called when 'culopt' is changed |
| 8051 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8052 | int |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8053 | fill_culopt_flags(char_u *val, win_T *wp) |
| 8054 | { |
| 8055 | char_u *p; |
| 8056 | char_u culopt_flags_new = 0; |
| 8057 | |
| 8058 | if (val == NULL) |
| 8059 | p = wp->w_p_culopt; |
| 8060 | else |
| 8061 | p = val; |
| 8062 | while (*p != NUL) |
| 8063 | { |
| 8064 | if (STRNCMP(p, "line", 4) == 0) |
| 8065 | { |
| 8066 | p += 4; |
| 8067 | culopt_flags_new |= CULOPT_LINE; |
| 8068 | } |
| 8069 | else if (STRNCMP(p, "both", 4) == 0) |
| 8070 | { |
| 8071 | p += 4; |
| 8072 | culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; |
| 8073 | } |
| 8074 | else if (STRNCMP(p, "number", 6) == 0) |
| 8075 | { |
| 8076 | p += 6; |
| 8077 | culopt_flags_new |= CULOPT_NBR; |
| 8078 | } |
| 8079 | else if (STRNCMP(p, "screenline", 10) == 0) |
| 8080 | { |
| 8081 | p += 10; |
| 8082 | culopt_flags_new |= CULOPT_SCRLINE; |
| 8083 | } |
| 8084 | |
| 8085 | if (*p != ',' && *p != NUL) |
| 8086 | return FAIL; |
| 8087 | if (*p == ',') |
| 8088 | ++p; |
| 8089 | } |
| 8090 | |
| 8091 | // Can't have both "line" and "screenline". |
| 8092 | if ((culopt_flags_new & CULOPT_LINE) && (culopt_flags_new & CULOPT_SCRLINE)) |
| 8093 | return FAIL; |
| 8094 | wp->w_p_culopt_flags = culopt_flags_new; |
| 8095 | |
| 8096 | return OK; |
| 8097 | } |
| 8098 | #endif |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8099 | |
| 8100 | /* |
| 8101 | * Get the value of 'magic' adjusted for Vim9 script. |
| 8102 | */ |
| 8103 | int |
| 8104 | magic_isset(void) |
| 8105 | { |
| 8106 | switch (magic_overruled) |
| 8107 | { |
Bram Moolenaar | d93a7fc | 2021-01-04 12:42:13 +0100 | [diff] [blame] | 8108 | case OPTION_MAGIC_ON: return TRUE; |
| 8109 | case OPTION_MAGIC_OFF: return FALSE; |
| 8110 | case OPTION_MAGIC_NOT_SET: break; |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8111 | } |
| 8112 | #ifdef FEAT_EVAL |
| 8113 | if (in_vim9script()) |
| 8114 | return TRUE; |
| 8115 | #endif |
| 8116 | return p_magic; |
| 8117 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8118 | |
| 8119 | /* |
| 8120 | * Set the callback function value for an option that accepts a function name, |
| 8121 | * lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.) |
| 8122 | * Returns OK if the option is successfully set to a function, otherwise |
| 8123 | * returns FAIL. |
| 8124 | */ |
| 8125 | int |
| 8126 | option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED) |
| 8127 | { |
| 8128 | #ifdef FEAT_EVAL |
| 8129 | typval_T *tv; |
| 8130 | callback_T cb; |
| 8131 | |
| 8132 | if (optval == NULL || *optval == NUL) |
| 8133 | { |
| 8134 | free_callback(optcb); |
| 8135 | return OK; |
| 8136 | } |
| 8137 | |
Yegappan Lakshmanan | 05e59e3 | 2021-12-01 10:30:07 +0000 | [diff] [blame] | 8138 | if (*optval == '{' || (in_vim9script() && *optval == '(') |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8139 | || (STRNCMP(optval, "function(", 9) == 0) |
| 8140 | || (STRNCMP(optval, "funcref(", 8) == 0)) |
| 8141 | // Lambda expression or a funcref |
| 8142 | tv = eval_expr(optval, NULL); |
| 8143 | else |
| 8144 | // treat everything else as a function name string |
Yegappan Lakshmanan | e7f4abd | 2021-12-24 20:47:38 +0000 | [diff] [blame] | 8145 | tv = alloc_string_tv(vim_strsave(optval)); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8146 | if (tv == NULL) |
| 8147 | return FAIL; |
| 8148 | |
| 8149 | cb = get_callback(tv); |
Yegappan Lakshmanan | 4dc24eb | 2021-12-07 12:23:57 +0000 | [diff] [blame] | 8150 | if (cb.cb_name == NULL || *cb.cb_name == NUL) |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8151 | { |
| 8152 | free_tv(tv); |
| 8153 | return FAIL; |
| 8154 | } |
| 8155 | |
| 8156 | free_callback(optcb); |
| 8157 | set_callback(optcb, &cb); |
Bram Moolenaar | c96b7f5 | 2022-12-02 15:58:38 +0000 | [diff] [blame] | 8158 | if (cb.cb_free_name) |
| 8159 | vim_free(cb.cb_name); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8160 | free_tv(tv); |
Bram Moolenaar | f0e7e63 | 2022-01-21 13:29:56 +0000 | [diff] [blame] | 8161 | |
| 8162 | // when using Vim9 style "import.funcname" it needs to be expanded to |
| 8163 | // "import#funcname". |
| 8164 | expand_autload_callback(optcb); |
| 8165 | |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8166 | return OK; |
| 8167 | #else |
| 8168 | return FAIL; |
| 8169 | #endif |
| 8170 | } |