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 | |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 71 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 72 | static char *(p_bin_dep_opts[]) = {"textwidth", "wrapmargin", "modeline", "expandtab", NULL}; |
| 73 | static char *(p_paste_dep_opts[]) = {"autoindent", "expandtab", "ruler", "showmatch", "smarttab", |
| 74 | "softtabstop", "textwidth", "wrapmargin", |
| 75 | #ifdef FEAT_RIGHTLEFT |
| 76 | "hkmap", "revins", |
| 77 | #endif |
| 78 | #ifdef FEAT_VARTABS |
| 79 | "varsofttabstop", |
| 80 | #endif |
| 81 | NULL}; |
| 82 | static void didset_options_sctx(int opt_flags, char **buf); |
| 83 | #endif |
| 84 | |
| 85 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 86 | /* |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 87 | * Initialize the 'shell' option to a default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 88 | */ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 89 | static void |
| 90 | set_init_default_shell(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | { |
| 92 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 94 | // Find default value for 'shell' option. |
| 95 | // Don't use it if it is empty. |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 96 | if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 97 | #if defined(MSWIN) |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 98 | || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) |
Bram Moolenaar | 6aa2cd4 | 2016-02-16 15:06:59 +0100 | [diff] [blame] | 99 | || ((p = (char_u *)default_shell()) != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 100 | #endif |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 101 | ) |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 102 | #if defined(MSWIN) |
| 103 | { |
| 104 | // For MS-Windows put the path in quotes instead of escaping spaces. |
| 105 | char_u *cmd; |
| 106 | size_t len; |
| 107 | |
| 108 | if (vim_strchr(p, ' ') != NULL) |
| 109 | { |
| 110 | len = STRLEN(p) + 3; // two quotes and a trailing NUL |
| 111 | cmd = alloc(len); |
Bram Moolenaar | 1671de3 | 2019-10-05 21:35:16 +0200 | [diff] [blame] | 112 | if (cmd != NULL) |
| 113 | { |
| 114 | vim_snprintf((char *)cmd, len, "\"%s\"", p); |
| 115 | set_string_default("sh", cmd); |
| 116 | vim_free(cmd); |
| 117 | } |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 118 | } |
| 119 | else |
| 120 | set_string_default("sh", p); |
| 121 | } |
| 122 | #else |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 123 | set_string_default_esc("sh", p, TRUE); |
Bram Moolenaar | 2efc44b | 2019-10-05 12:09:32 +0200 | [diff] [blame] | 124 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 125 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 127 | /* |
| 128 | * Set the default for 'backupskip' to include environment variables for |
| 129 | * temp files. |
| 130 | */ |
| 131 | static void |
| 132 | set_init_default_backupskip(void) |
| 133 | { |
| 134 | int opt_idx; |
| 135 | long_u n; |
| 136 | char_u *p; |
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 | static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 139 | #else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 140 | static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 141 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 142 | int len; |
| 143 | garray_T ga; |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 144 | char_u *item; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 145 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 146 | opt_idx = findoption((char_u *)"backupskip"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 147 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 148 | ga_init2(&ga, 1, 100); |
| 149 | for (n = 0; n < (long)ARRAY_LENGTH(names); ++n) |
| 150 | { |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 151 | int mustfree = FALSE; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 152 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 153 | if (*names[n] == NUL) |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 154 | # ifdef MACOS_X |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 155 | p = (char_u *)"/private/tmp"; |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 156 | # else |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 157 | p = (char_u *)"/tmp"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 159 | else |
Bram Moolenaar | 074fbd4 | 2022-08-26 16:41:14 +0100 | [diff] [blame] | 160 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 161 | p = vim_getenv((char_u *)names[n], &mustfree); |
| 162 | if (p != NULL && *p != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 163 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 164 | // First time count the NUL, otherwise count the ','. |
| 165 | len = (int)STRLEN(p) + 3; |
| 166 | item = alloc(len); |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 167 | if (item != NULL) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 168 | { |
Bram Moolenaar | 1433802 | 2023-03-15 22:05:44 +0000 | [diff] [blame] | 169 | STRCPY(item, p); |
| 170 | add_pathsep(item); |
| 171 | STRCAT(item, "*"); |
| 172 | if (find_dup_item(ga.ga_data, item, options[opt_idx].flags) |
| 173 | == NULL |
| 174 | && ga_grow(&ga, len) == OK) |
| 175 | { |
| 176 | if (ga.ga_len > 0) |
| 177 | STRCAT(ga.ga_data, ","); |
| 178 | STRCAT(ga.ga_data, item); |
| 179 | ga.ga_len += len; |
| 180 | } |
| 181 | vim_free(item); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 182 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 183 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 184 | if (mustfree) |
| 185 | vim_free(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 186 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 187 | if (ga.ga_data != NULL) |
| 188 | { |
| 189 | set_string_default("bsk", ga.ga_data); |
| 190 | vim_free(ga.ga_data); |
| 191 | } |
| 192 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 193 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 194 | /* |
| 195 | * Initialize the 'maxmemtot' and 'maxmem' options to a default value. |
| 196 | * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory. |
| 197 | */ |
| 198 | static void |
| 199 | set_init_default_maxmemtot(void) |
| 200 | { |
| 201 | int opt_idx; |
| 202 | long_u n; |
| 203 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 204 | opt_idx = findoption((char_u *)"maxmemtot"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 205 | if (opt_idx < 0) |
| 206 | return; |
| 207 | |
| 208 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
| 209 | if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) |
| 210 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 211 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 212 | #if defined(HAVE_AVAIL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 213 | // Use amount of memory available at this moment. |
| 214 | n = (mch_avail_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 215 | #elif defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 216 | // Use amount of memory available to Vim. |
| 217 | n = (mch_total_mem(FALSE) >> 1); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 218 | #else |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 219 | n = (0x7fffffff >> 11); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 221 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
| 222 | opt_idx = findoption((char_u *)"maxmem"); |
| 223 | if (opt_idx >= 0) |
| 224 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 225 | #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 226 | if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n |
| 227 | || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L) |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 228 | #endif |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 229 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 230 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 231 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 232 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 233 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 234 | /* |
| 235 | * Initialize the 'cdpath' option to a default value. |
| 236 | */ |
| 237 | static void |
| 238 | set_init_default_cdpath(void) |
| 239 | { |
| 240 | int opt_idx; |
| 241 | char_u *cdpath; |
| 242 | char_u *buf; |
| 243 | int i; |
| 244 | int j; |
| 245 | int mustfree = FALSE; |
| 246 | |
| 247 | cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); |
| 248 | if (cdpath == NULL) |
| 249 | return; |
| 250 | |
| 251 | buf = alloc((STRLEN(cdpath) << 1) + 2); |
| 252 | if (buf != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 253 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 254 | buf[0] = ','; // start with ",", current dir first |
| 255 | j = 1; |
| 256 | for (i = 0; cdpath[i] != NUL; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 257 | { |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 258 | if (vim_ispathlistsep(cdpath[i])) |
| 259 | buf[j++] = ','; |
| 260 | else |
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 (cdpath[i] == ' ' || cdpath[i] == ',') |
| 263 | buf[j++] = '\\'; |
| 264 | buf[j++] = cdpath[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 267 | buf[j] = NUL; |
| 268 | opt_idx = findoption((char_u *)"cdpath"); |
| 269 | if (opt_idx >= 0) |
| 270 | { |
| 271 | options[opt_idx].def_val[VI_DEFAULT] = buf; |
| 272 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 273 | } |
| 274 | else |
| 275 | vim_free(buf); // cannot happen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 276 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 277 | if (mustfree) |
| 278 | vim_free(cdpath); |
| 279 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 280 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 281 | /* |
| 282 | * Initialize the 'printencoding' option to a default value. |
| 283 | */ |
| 284 | static void |
| 285 | set_init_default_printencoding(void) |
| 286 | { |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 287 | #if defined(FEAT_POSTSCRIPT) && \ |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 288 | (defined(MSWIN) || defined(VMS) || defined(MAC) || defined(hpux)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 289 | // Set print encoding on platforms that don't default to latin1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 290 | set_string_default("penc", |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 291 | # if defined(MSWIN) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 292 | (char_u *)"cp1252" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 293 | # elif defined(VMS) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 294 | (char_u *)"dec-mcs" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 295 | # elif defined(MAC) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 296 | (char_u *)"mac-roman" |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 297 | # else // HPUX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 298 | (char_u *)"hp-roman8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 299 | # endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 300 | ); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 301 | #endif |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 302 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 303 | |
| 304 | #ifdef FEAT_POSTSCRIPT |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 305 | /* |
| 306 | * Initialize the 'printexpr' option to a default value. |
| 307 | */ |
| 308 | static void |
| 309 | set_init_default_printexpr(void) |
| 310 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 311 | // 'printexpr' must be allocated to be able to evaluate it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 312 | set_string_default("pexpr", |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 313 | # if defined(MSWIN) |
Bram Moolenaar | ed20346 | 2004-06-16 11:19:22 +0000 | [diff] [blame] | 314 | (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] | 315 | # elif defined(VMS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 316 | (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" |
| 317 | |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 318 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 319 | (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] | 320 | # endif |
| 321 | ); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 322 | } |
| 323 | #endif |
| 324 | |
| 325 | #ifdef UNIX |
| 326 | /* |
| 327 | * Force restricted-mode on for "nologin" or "false" $SHELL |
| 328 | */ |
| 329 | static void |
| 330 | set_init_restricted_mode(void) |
| 331 | { |
| 332 | char_u *p; |
| 333 | |
| 334 | p = get_isolated_shell_name(); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 335 | if (p == NULL) |
| 336 | return; |
| 337 | if (fnamecmp(p, "nologin") == 0 || fnamecmp(p, "false") == 0) |
| 338 | restricted = TRUE; |
| 339 | vim_free(p); |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 340 | } |
| 341 | #endif |
| 342 | |
| 343 | #ifdef CLEAN_RUNTIMEPATH |
| 344 | /* |
| 345 | * When Vim is started with the "--clean" argument, set the default value |
| 346 | * for the 'runtimepath' and 'packpath' options. |
| 347 | */ |
| 348 | static void |
| 349 | set_init_clean_rtp(void) |
| 350 | { |
| 351 | int opt_idx; |
| 352 | |
| 353 | opt_idx = findoption((char_u *)"runtimepath"); |
| 354 | if (opt_idx >= 0) |
| 355 | { |
| 356 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 357 | p_rtp = (char_u *)CLEAN_RUNTIMEPATH; |
| 358 | } |
| 359 | opt_idx = findoption((char_u *)"packpath"); |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 360 | if (opt_idx < 0) |
| 361 | return; |
| 362 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; |
| 363 | p_pp = (char_u *)CLEAN_RUNTIMEPATH; |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 364 | } |
| 365 | #endif |
| 366 | |
| 367 | /* |
| 368 | * Expand environment variables and things like "~" for the defaults. |
| 369 | * If option_expand() returns non-NULL the variable is expanded. This can |
| 370 | * only happen for non-indirect options. |
| 371 | * Also set the default to the expanded value, so ":set" does not list |
| 372 | * them. |
| 373 | * Don't set the P_ALLOCED flag, because we don't want to free the |
| 374 | * default. |
| 375 | */ |
| 376 | static void |
| 377 | set_init_expand_env(void) |
| 378 | { |
| 379 | int opt_idx; |
| 380 | char_u *p; |
| 381 | |
| 382 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
| 383 | { |
| 384 | if ((options[opt_idx].flags & P_GETTEXT) |
| 385 | && options[opt_idx].var != NULL) |
| 386 | p = (char_u *)_(*(char **)options[opt_idx].var); |
| 387 | else |
| 388 | p = option_expand(opt_idx, NULL); |
| 389 | if (p != NULL && (p = vim_strsave(p)) != NULL) |
| 390 | { |
| 391 | *(char_u **)options[opt_idx].var = p; |
| 392 | // VIMEXP |
| 393 | // Defaults for all expanded options are currently the same for Vi |
| 394 | // and Vim. When this changes, add some code here! Also need to |
| 395 | // split P_DEF_ALLOCED in two. |
| 396 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 397 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 398 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 399 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * Initialize the 'LANG' environment variable to a default value. |
| 406 | */ |
| 407 | static void |
| 408 | set_init_lang_env(void) |
| 409 | { |
| 410 | #if defined(MSWIN) && defined(FEAT_GETTEXT) |
| 411 | // If $LANG isn't set, try to get a good value for it. This makes the |
| 412 | // right language be used automatically. Don't do this for English. |
| 413 | if (mch_getenv((char_u *)"LANG") == NULL) |
| 414 | { |
| 415 | char buf[20]; |
| 416 | long_u n; |
| 417 | |
| 418 | // Could use LOCALE_SISO639LANGNAME, but it's not in Win95. |
| 419 | // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use |
| 420 | // only the first two. |
| 421 | n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, |
| 422 | (LPTSTR)buf, 20); |
| 423 | if (n >= 2 && STRNICMP(buf, "en", 2) != 0) |
| 424 | { |
| 425 | // There are a few exceptions (probably more) |
| 426 | if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) |
| 427 | STRCPY(buf, "zh_TW"); |
| 428 | else if (STRNICMP(buf, "chs", 3) == 0 |
| 429 | || STRNICMP(buf, "zhc", 3) == 0) |
| 430 | STRCPY(buf, "zh_CN"); |
| 431 | else if (STRNICMP(buf, "jp", 2) == 0) |
| 432 | STRCPY(buf, "ja"); |
| 433 | else |
| 434 | buf[2] = NUL; // truncate to two-letter code |
| 435 | vim_setenv((char_u *)"LANG", (char_u *)buf); |
| 436 | } |
| 437 | } |
| 438 | #elif defined(MACOS_CONVERT) |
| 439 | // Moved to os_mac_conv.c to avoid dependency problems. |
| 440 | mac_lang_init(); |
| 441 | #endif |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * Initialize the 'encoding' option to a default value. |
| 446 | */ |
| 447 | static void |
| 448 | set_init_default_encoding(void) |
| 449 | { |
| 450 | char_u *p; |
| 451 | int opt_idx; |
| 452 | |
| 453 | # ifdef MSWIN |
| 454 | // MS-Windows has builtin support for conversion to and from Unicode, using |
| 455 | // "utf-8" for 'encoding' should work best for most users. |
| 456 | p = vim_strsave((char_u *)ENC_DFLT); |
| 457 | # else |
| 458 | // enc_locale() will try to find the encoding of the current locale. |
| 459 | // This works best for properly configured systems, old and new. |
| 460 | p = enc_locale(); |
| 461 | # endif |
| 462 | if (p == NULL) |
| 463 | return; |
| 464 | |
| 465 | // Try setting 'encoding' and check if the value is valid. |
| 466 | // If not, go back to the default encoding. |
| 467 | char_u *save_enc = p_enc; |
| 468 | p_enc = p; |
| 469 | if (STRCMP(p_enc, "gb18030") == 0) |
| 470 | { |
| 471 | // We don't support "gb18030", but "cp936" is a good substitute |
| 472 | // for practical purposes, thus use that. It's not an alias to |
| 473 | // still support conversion between gb18030 and utf-8. |
| 474 | p_enc = vim_strsave((char_u *)"cp936"); |
| 475 | vim_free(p); |
| 476 | } |
| 477 | if (mb_init() == NULL) |
| 478 | { |
| 479 | opt_idx = findoption((char_u *)"encoding"); |
| 480 | if (opt_idx >= 0) |
| 481 | { |
| 482 | options[opt_idx].def_val[VI_DEFAULT] = p_enc; |
| 483 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 484 | } |
| 485 | |
| 486 | #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) |
| 487 | if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) |
| 488 | { |
| 489 | // Adjust the default for 'isprint' and 'iskeyword' to match |
| 490 | // latin1. Also set the defaults for when 'nocompatible' is |
| 491 | // set. |
| 492 | set_string_option_direct((char_u *)"isp", -1, |
| 493 | ISP_LATIN1, OPT_FREE, SID_NONE); |
| 494 | set_string_option_direct((char_u *)"isk", -1, |
| 495 | ISK_LATIN1, OPT_FREE, SID_NONE); |
| 496 | opt_idx = findoption((char_u *)"isp"); |
| 497 | if (opt_idx >= 0) |
| 498 | options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; |
| 499 | opt_idx = findoption((char_u *)"isk"); |
| 500 | if (opt_idx >= 0) |
| 501 | options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; |
| 502 | (void)init_chartab(); |
| 503 | } |
| 504 | #endif |
| 505 | |
| 506 | #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
| 507 | // Win32 console: When GetACP() returns a different value from |
| 508 | // GetConsoleCP() set 'termencoding'. |
| 509 | if ( |
| 510 | # ifdef VIMDLL |
| 511 | (!gui.in_use && !gui.starting) && |
| 512 | # endif |
| 513 | GetACP() != GetConsoleCP()) |
| 514 | { |
| 515 | char buf[50]; |
| 516 | |
| 517 | // Win32 console: In ConPTY, GetConsoleCP() returns zero. |
| 518 | // Use an alternative value. |
| 519 | if (GetConsoleCP() == 0) |
| 520 | sprintf(buf, "cp%ld", (long)GetACP()); |
| 521 | else |
| 522 | sprintf(buf, "cp%ld", (long)GetConsoleCP()); |
| 523 | p_tenc = vim_strsave((char_u *)buf); |
| 524 | if (p_tenc != NULL) |
| 525 | { |
| 526 | opt_idx = findoption((char_u *)"termencoding"); |
| 527 | if (opt_idx >= 0) |
| 528 | { |
| 529 | options[opt_idx].def_val[VI_DEFAULT] = p_tenc; |
| 530 | options[opt_idx].flags |= P_DEF_ALLOCED; |
| 531 | } |
| 532 | convert_setup(&input_conv, p_tenc, p_enc); |
| 533 | convert_setup(&output_conv, p_enc, p_tenc); |
| 534 | } |
| 535 | else |
| 536 | p_tenc = empty_option; |
| 537 | } |
| 538 | #endif |
| 539 | #if defined(MSWIN) |
| 540 | // $HOME may have characters in active code page. |
| 541 | init_homedir(); |
| 542 | #endif |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | vim_free(p_enc); |
| 547 | p_enc = save_enc; |
| 548 | } |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Initialize the options, first part. |
| 553 | * |
| 554 | * Called only once from main(), just after creating the first buffer. |
| 555 | * If "clean_arg" is TRUE Vim was started with --clean. |
| 556 | */ |
| 557 | void |
| 558 | set_init_1(int clean_arg) |
| 559 | { |
| 560 | #ifdef FEAT_LANGMAP |
| 561 | langmap_init(); |
| 562 | #endif |
| 563 | |
| 564 | // Be Vi compatible by default |
| 565 | p_cp = TRUE; |
| 566 | |
| 567 | // Use POSIX compatibility when $VIM_POSIX is set. |
| 568 | if (mch_getenv((char_u *)"VIM_POSIX") != NULL) |
| 569 | { |
| 570 | set_string_default("cpo", (char_u *)CPO_ALL); |
| 571 | set_string_default("shm", (char_u *)SHM_POSIX); |
| 572 | } |
| 573 | |
| 574 | set_init_default_shell(); |
| 575 | set_init_default_backupskip(); |
| 576 | set_init_default_maxmemtot(); |
| 577 | set_init_default_cdpath(); |
| 578 | set_init_default_printencoding(); |
| 579 | #ifdef FEAT_POSTSCRIPT |
| 580 | set_init_default_printexpr(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 581 | #endif |
| 582 | |
| 583 | /* |
| 584 | * Set all the options (except the terminal options) to their default |
| 585 | * value. Also set the global value for local options. |
| 586 | */ |
| 587 | set_options_default(0); |
| 588 | |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 589 | #ifdef UNIX |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 590 | set_init_restricted_mode(); |
matveyt | adbb1bf | 2022-02-01 17:26:12 +0000 | [diff] [blame] | 591 | #endif |
| 592 | |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 593 | #ifdef CLEAN_RUNTIMEPATH |
| 594 | if (clean_arg) |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 595 | set_init_clean_rtp(); |
Bram Moolenaar | 0726870 | 2018-03-01 21:57:32 +0100 | [diff] [blame] | 596 | #endif |
| 597 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 598 | #ifdef FEAT_GUI |
| 599 | if (found_reverse_arg) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 600 | 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] | 601 | #endif |
| 602 | |
| 603 | curbuf->b_p_initialized = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 604 | curbuf->b_p_ar = -1; // no local 'autoread' value |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 605 | curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 606 | check_buf_options(curbuf); |
| 607 | check_win_options(curwin); |
| 608 | check_options(); |
| 609 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 610 | // Must be before option_expand(), because that one needs vim_isIDc() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 611 | didset_options(); |
| 612 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 613 | #ifdef FEAT_SPELL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 614 | // Use the current chartab for the generic chartab. This is not in |
| 615 | // didset_options() because it only depends on 'encoding'. |
Bram Moolenaar | 6bb6836 | 2005-03-22 23:03:44 +0000 | [diff] [blame] | 616 | init_spell_chartab(); |
| 617 | #endif |
| 618 | |
K.Takata | ce3189d | 2023-02-15 19:13:43 +0000 | [diff] [blame] | 619 | set_init_default_encoding(); |
| 620 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 621 | // Expand environment variables and things like "~" for the defaults. |
| 622 | set_init_expand_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 623 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 624 | save_file_ff(curbuf); // Buffer is unchanged |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 625 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 626 | #if defined(FEAT_ARABIC) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 627 | // Detect use of mlterm. |
| 628 | // Mlterm is a terminal emulator akin to xterm that has some special |
| 629 | // abilities (bidi namely). |
| 630 | // NOTE: mlterm's author is being asked to 'set' a variable |
| 631 | // instead of an environment variable due to inheritance. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 632 | if (mch_getenv((char_u *)"MLTERM") != NULL) |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 633 | set_option_value_give_err((char_u *)"tbidi", 1L, NULL, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 634 | #endif |
| 635 | |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 636 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 637 | |
Yegappan Lakshmanan | 6c41bed | 2023-02-10 14:50:31 +0000 | [diff] [blame] | 638 | set_init_lang_env(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 639 | |
| 640 | #ifdef FEAT_MULTI_LANG |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 641 | // Set the default for 'helplang'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 642 | set_helplang_default(get_mess_lang()); |
| 643 | #endif |
| 644 | } |
| 645 | |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 646 | static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1"; |
| 647 | |
| 648 | /* |
| 649 | * Set the "fileencodings" option to the default value for when 'encoding' is |
| 650 | * utf-8. |
| 651 | */ |
| 652 | void |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 653 | set_fencs_unicode(void) |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 654 | { |
| 655 | set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, |
| 656 | OPT_FREE, 0); |
| 657 | } |
| 658 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 659 | /* |
| 660 | * Set an option to its default value. |
| 661 | * This does not take care of side effects! |
| 662 | */ |
| 663 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 664 | set_option_default( |
| 665 | int opt_idx, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 666 | int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
| 667 | int compatible) // use Vi default value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 668 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 669 | char_u *varp; // pointer to variable for current option |
| 670 | int dvi; // index in def_val[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 671 | long_u flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 672 | long_u *flagsp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 673 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 674 | |
| 675 | varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); |
| 676 | flags = options[opt_idx].flags; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 677 | if (varp != NULL) // skip hidden option, nothing to do for it |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 678 | { |
| 679 | dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
| 680 | if (flags & P_STRING) |
| 681 | { |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 682 | // 'fencs' default value depends on 'encoding' |
| 683 | if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8) |
| 684 | set_fencs_unicode(); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 685 | // Use set_string_option_direct() for local options to handle |
| 686 | // freeing and allocating the value. |
Bram Moolenaar | 5ffefbb | 2021-06-13 20:27:36 +0200 | [diff] [blame] | 687 | else if (options[opt_idx].indir != PV_NONE) |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 688 | set_string_option_direct(NULL, opt_idx, |
| 689 | options[opt_idx].def_val[dvi], opt_flags, 0); |
| 690 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 691 | { |
Bram Moolenaar | b833c1e | 2018-05-05 16:36:06 +0200 | [diff] [blame] | 692 | if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) |
| 693 | free_string_option(*(char_u **)(varp)); |
| 694 | *(char_u **)varp = options[opt_idx].def_val[dvi]; |
| 695 | options[opt_idx].flags &= ~P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | else if (flags & P_NUM) |
| 699 | { |
Bram Moolenaar | 5fc1a8b | 2006-10-17 16:34:24 +0000 | [diff] [blame] | 700 | if (options[opt_idx].indir == PV_SCROLL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 701 | win_comp_scroll(curwin); |
| 702 | else |
| 703 | { |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 704 | long def_val = (long)(long_i)options[opt_idx].def_val[dvi]; |
| 705 | |
| 706 | if ((long *)varp == &curwin->w_p_so |
| 707 | || (long *)varp == &curwin->w_p_siso) |
| 708 | // 'scrolloff' and 'sidescrolloff' local values have a |
| 709 | // different default value than the global default. |
| 710 | *(long *)varp = -1; |
| 711 | else |
| 712 | *(long *)varp = def_val; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 713 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 714 | if (both) |
| 715 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 716 | def_val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 719 | else // P_BOOL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 720 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 721 | // the cast to long is required for Manx C, long_i is needed for |
| 722 | // MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 723 | *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 724 | #ifdef UNIX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 725 | // 'modeline' defaults to off for root |
Bram Moolenaar | 8243a79 | 2007-05-01 17:05:03 +0000 | [diff] [blame] | 726 | if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) |
| 727 | *(int *)varp = FALSE; |
| 728 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 729 | // May also set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 730 | if (both) |
| 731 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
| 732 | *(int *)varp; |
| 733 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 734 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 735 | // The default value is not insecure. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 736 | flagsp = insecure_flag(opt_idx, opt_flags); |
| 737 | *flagsp = *flagsp & ~P_INSECURE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | #ifdef FEAT_EVAL |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 741 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 742 | #endif |
| 743 | } |
| 744 | |
| 745 | /* |
| 746 | * Set all options (except terminal options) to their default value. |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 747 | * When "opt_flags" is non-zero skip 'encoding'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 748 | */ |
| 749 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 750 | set_options_default( |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 751 | int opt_flags) // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 752 | { |
| 753 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 755 | tabpage_T *tp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 756 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 757 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | b341dda | 2015-08-25 12:56:31 +0200 | [diff] [blame] | 758 | if (!(options[i].flags & P_NODEFAULT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 759 | && (opt_flags == 0 |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 760 | || (options[i].var != (char_u *)&p_enc |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 761 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 762 | && options[i].var != (char_u *)&p_cm |
Bram Moolenaar | 8060687 | 2015-08-25 21:27:35 +0200 | [diff] [blame] | 763 | && options[i].var != (char_u *)&p_key |
Bram Moolenaar | 5ea87a0 | 2015-08-26 23:24:09 +0200 | [diff] [blame] | 764 | # endif |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 765 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 766 | set_option_default(i, opt_flags, p_cp); |
| 767 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 768 | // The 'scroll' option must be computed for all windows. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 769 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 770 | win_comp_scroll(wp); |
Bram Moolenaar | 5a4eceb | 2014-09-09 17:33:07 +0200 | [diff] [blame] | 771 | parse_cino(curbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Set the Vi-default value of a string option. |
| 776 | * Used for 'sh', 'backupskip' and 'term'. |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 777 | * When "escape" is TRUE escape spaces with a backslash. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 778 | */ |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 779 | static void |
| 780 | set_string_default_esc(char *name, char_u *val, int escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 781 | { |
| 782 | char_u *p; |
| 783 | int opt_idx; |
| 784 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 785 | if (escape && vim_strchr(val, ' ') != NULL) |
| 786 | p = vim_strsave_escaped(val, (char_u *)" "); |
| 787 | else |
| 788 | p = vim_strsave(val); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 789 | if (p == NULL) // we don't want a NULL |
| 790 | return; |
| 791 | |
| 792 | opt_idx = findoption((char_u *)name); |
| 793 | if (opt_idx < 0) |
| 794 | return; |
| 795 | |
| 796 | if (options[opt_idx].flags & P_DEF_ALLOCED) |
| 797 | vim_free(options[opt_idx].def_val[VI_DEFAULT]); |
| 798 | options[opt_idx].def_val[VI_DEFAULT] = p; |
| 799 | options[opt_idx].flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Bram Moolenaar | 4bfa8af | 2018-02-03 15:14:46 +0100 | [diff] [blame] | 802 | void |
| 803 | set_string_default(char *name, char_u *val) |
| 804 | { |
| 805 | set_string_default_esc(name, val, FALSE); |
| 806 | } |
| 807 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 808 | /* |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 809 | * For an option value that contains comma separated items, find "newval" in |
| 810 | * "origval". Return NULL if not found. |
| 811 | */ |
| 812 | static char_u * |
| 813 | find_dup_item(char_u *origval, char_u *newval, long_u flags) |
| 814 | { |
Bram Moolenaar | 8f13d82 | 2020-09-12 21:04:23 +0200 | [diff] [blame] | 815 | int bs = 0; |
Bram Moolenaar | b00ef05 | 2020-09-12 14:53:53 +0200 | [diff] [blame] | 816 | size_t newlen; |
| 817 | char_u *s; |
| 818 | |
| 819 | if (origval == NULL) |
| 820 | return NULL; |
| 821 | |
| 822 | newlen = STRLEN(newval); |
| 823 | for (s = origval; *s != NUL; ++s) |
| 824 | { |
| 825 | if ((!(flags & P_COMMA) |
| 826 | || s == origval |
| 827 | || (s[-1] == ',' && !(bs & 1))) |
| 828 | && STRNCMP(s, newval, newlen) == 0 |
| 829 | && (!(flags & P_COMMA) |
| 830 | || s[newlen] == ',' |
| 831 | || s[newlen] == NUL)) |
| 832 | return s; |
| 833 | // Count backslashes. Only a comma with an even number of backslashes |
| 834 | // or a single backslash preceded by a comma before it is recognized as |
| 835 | // a separator. |
| 836 | if ((s > origval + 1 |
| 837 | && s[-1] == '\\' |
| 838 | && s[-2] != ',') |
| 839 | || (s == origval + 1 |
| 840 | && s[-1] == '\\')) |
| 841 | ++bs; |
| 842 | else |
| 843 | bs = 0; |
| 844 | } |
| 845 | return NULL; |
| 846 | } |
| 847 | |
| 848 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 849 | * Set the Vi-default value of a number option. |
| 850 | * Used for 'lines' and 'columns'. |
| 851 | */ |
| 852 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 853 | set_number_default(char *name, long val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 854 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 855 | int opt_idx; |
| 856 | |
| 857 | opt_idx = findoption((char_u *)name); |
| 858 | if (opt_idx >= 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 859 | options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 862 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 863 | /* |
| 864 | * Set all window-local and buffer-local options to the Vim default. |
| 865 | * local-global options will use the global value. |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 866 | * When "do_buffer" is FALSE don't set buffer-local options. |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 867 | */ |
| 868 | void |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 869 | set_local_options_default(win_T *wp, int do_buffer) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 870 | { |
| 871 | win_T *save_curwin = curwin; |
| 872 | int i; |
| 873 | |
| 874 | curwin = wp; |
| 875 | curbuf = curwin->w_buffer; |
| 876 | block_autocmds(); |
| 877 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 878 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 879 | { |
| 880 | struct vimoption *p = &(options[i]); |
| 881 | char_u *varp = get_varp_scope(p, OPT_LOCAL); |
| 882 | |
| 883 | if (p->indir != PV_NONE |
Bram Moolenaar | 4645104 | 2019-08-24 15:50:46 +0200 | [diff] [blame] | 884 | && (do_buffer || (p->indir & PV_BUF) == 0) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 885 | && !(options[i].flags & P_NODEFAULT) |
| 886 | && !optval_default(p, varp, FALSE)) |
Bram Moolenaar | 8617348 | 2019-10-01 17:02:16 +0200 | [diff] [blame] | 887 | set_option_default(i, OPT_FREE|OPT_LOCAL, FALSE); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | unblock_autocmds(); |
| 891 | curwin = save_curwin; |
| 892 | curbuf = curwin->w_buffer; |
| 893 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 894 | #endif |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 895 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 896 | #if defined(EXITFREE) || defined(PROTO) |
| 897 | /* |
| 898 | * Free all options. |
| 899 | */ |
| 900 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 901 | free_all_options(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 902 | { |
| 903 | int i; |
| 904 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 905 | for (i = 0; !istermoption_idx(i); i++) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 906 | { |
| 907 | if (options[i].indir == PV_NONE) |
| 908 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 909 | // global option: free value and default value. |
Bram Moolenaar | 6739114 | 2017-02-19 21:07:04 +0100 | [diff] [blame] | 910 | if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 911 | free_string_option(*(char_u **)options[i].var); |
| 912 | if (options[i].flags & P_DEF_ALLOCED) |
| 913 | free_string_option(options[i].def_val[VI_DEFAULT]); |
| 914 | } |
| 915 | else if (options[i].var != VAR_WIN |
| 916 | && (options[i].flags & P_STRING)) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 917 | // buffer-local option: free global value |
Bram Moolenaar | 77111e2 | 2021-07-29 21:11:30 +0200 | [diff] [blame] | 918 | clear_string_option((char_u **)options[i].var); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 919 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 920 | free_operatorfunc_option(); |
Yegappan Lakshmanan | 19916a8 | 2021-11-24 16:32:55 +0000 | [diff] [blame] | 921 | free_tagfunc_option(); |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 922 | } |
| 923 | #endif |
| 924 | |
| 925 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 926 | /* |
| 927 | * Initialize the options, part two: After getting Rows and Columns and |
| 928 | * setting 'term'. |
| 929 | */ |
| 930 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 931 | set_init_2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 932 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 933 | int idx; |
| 934 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 935 | // 'scroll' defaults to half the window height. The stored default is zero, |
| 936 | // which results in the actual value computed from the window height. |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 937 | idx = findoption((char_u *)"scroll"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 938 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 939 | set_option_default(idx, OPT_LOCAL, p_cp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 940 | comp_col(); |
| 941 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 942 | // 'window' is only for backwards compatibility with Vi. |
| 943 | // Default is Rows - 1. |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 944 | if (!option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 945 | p_window = Rows - 1; |
| 946 | set_number_default("window", Rows - 1); |
| 947 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 948 | // For DOS console the default is always black. |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 949 | #if !((defined(MSWIN)) && !defined(FEAT_GUI)) |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 950 | // If 'background' wasn't set by the user, try guessing the value, |
| 951 | // depending on the terminal name. Only need to check for terminals |
| 952 | // with a dark background, that can handle color. |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 953 | idx = findoption((char_u *)"bg"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 954 | if (idx >= 0 && !(options[idx].flags & P_WAS_SET) |
| 955 | && *term_bg_default() == 'd') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 956 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 957 | set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 958 | // don't mark it as set, when starting the GUI it may be |
| 959 | // changed again |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 960 | options[idx].flags &= ~P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 961 | } |
| 962 | #endif |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 963 | |
| 964 | #ifdef CURSOR_SHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 965 | parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 966 | #endif |
| 967 | #ifdef FEAT_MOUSESHAPE |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 968 | parse_shape_opt(SHAPE_MOUSE); // set mouse shapes from 'mouseshape' |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 969 | #endif |
| 970 | #ifdef FEAT_PRINTER |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 971 | (void)parse_printoptions(NULL); // parse 'printoptions' default value |
Bram Moolenaar | 58d9823 | 2005-07-23 22:25:46 +0000 | [diff] [blame] | 972 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /* |
| 976 | * Initialize the options, part three: After reading the .vimrc |
| 977 | */ |
| 978 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 979 | set_init_3(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 980 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 981 | #if defined(UNIX) || defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 982 | /* |
| 983 | * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. |
| 984 | * This is done after other initializations, where 'shell' might have been |
| 985 | * set, but only if they have not been set before. |
| 986 | */ |
| 987 | char_u *p; |
| 988 | int idx_srr; |
| 989 | int do_srr; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 990 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 991 | int idx_sp; |
| 992 | int do_sp; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 993 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 994 | |
| 995 | idx_srr = findoption((char_u *)"srr"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 996 | if (idx_srr < 0) |
| 997 | do_srr = FALSE; |
| 998 | else |
| 999 | do_srr = !(options[idx_srr].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1000 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1001 | idx_sp = findoption((char_u *)"sp"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1002 | if (idx_sp < 0) |
| 1003 | do_sp = FALSE; |
| 1004 | else |
| 1005 | do_sp = !(options[idx_sp].flags & P_WAS_SET); |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1006 | # endif |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 1007 | p = get_isolated_shell_name(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1008 | if (p != NULL) |
| 1009 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 1010 | // Default for p_sp is "| tee", for p_srr is ">". |
| 1011 | // For known shells it is changed here to include stderr. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1012 | if ( fnamecmp(p, "csh") == 0 |
| 1013 | || fnamecmp(p, "tcsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1014 | # if defined(MSWIN) // also check with .exe extension |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1015 | || fnamecmp(p, "csh.exe") == 0 |
| 1016 | || fnamecmp(p, "tcsh.exe") == 0 |
| 1017 | # endif |
| 1018 | ) |
| 1019 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1020 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1021 | if (do_sp) |
| 1022 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1023 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1024 | p_sp = (char_u *)">&"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1025 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1026 | p_sp = (char_u *)"|& tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1027 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1028 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1029 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1030 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1031 | if (do_srr) |
| 1032 | { |
| 1033 | p_srr = (char_u *)">&"; |
| 1034 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1035 | } |
| 1036 | } |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1037 | # ifdef MSWIN |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1038 | // Windows PowerShell output is UTF-16 with BOM so re-encode to the |
| 1039 | // current codepage. |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1040 | else if ( fnamecmp(p, "powershell") == 0 |
| 1041 | || fnamecmp(p, "powershell.exe") == 0 |
| 1042 | ) |
| 1043 | { |
| 1044 | # if defined(FEAT_QUICKFIX) |
| 1045 | if (do_sp) |
| 1046 | { |
| 1047 | p_sp = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1048 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1049 | } |
| 1050 | # endif |
| 1051 | if (do_srr) |
| 1052 | { |
| 1053 | p_srr = (char_u *)"2>&1 | Out-File -Encoding default"; |
| 1054 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1055 | } |
| 1056 | } |
| 1057 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1058 | else |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1059 | // Always use POSIX shell style redirection if we reach this |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1060 | if ( fnamecmp(p, "sh") == 0 |
| 1061 | || fnamecmp(p, "ksh") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1062 | || fnamecmp(p, "mksh") == 0 |
| 1063 | || fnamecmp(p, "pdksh") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1064 | || fnamecmp(p, "zsh") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1065 | || fnamecmp(p, "zsh-beta") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1066 | || fnamecmp(p, "bash") == 0 |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 1067 | || fnamecmp(p, "fish") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1068 | || fnamecmp(p, "ash") == 0 |
| 1069 | || fnamecmp(p, "dash") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1070 | || fnamecmp(p, "pwsh") == 0 |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1071 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1072 | || fnamecmp(p, "cmd") == 0 |
| 1073 | || fnamecmp(p, "sh.exe") == 0 |
| 1074 | || fnamecmp(p, "ksh.exe") == 0 |
Bram Moolenaar | f1fda2d | 2011-04-28 12:57:36 +0200 | [diff] [blame] | 1075 | || fnamecmp(p, "mksh.exe") == 0 |
| 1076 | || fnamecmp(p, "pdksh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1077 | || fnamecmp(p, "zsh.exe") == 0 |
Bram Moolenaar | c1e3790 | 2006-04-18 21:55:01 +0000 | [diff] [blame] | 1078 | || fnamecmp(p, "zsh-beta.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1079 | || fnamecmp(p, "bash.exe") == 0 |
| 1080 | || fnamecmp(p, "cmd.exe") == 0 |
Natanael Copa | 5631836 | 2021-05-06 18:46:35 +0200 | [diff] [blame] | 1081 | || fnamecmp(p, "dash.exe") == 0 |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1082 | || fnamecmp(p, "pwsh.exe") == 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1083 | # endif |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1084 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1085 | { |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1086 | # if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1087 | if (do_sp) |
| 1088 | { |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1089 | # ifdef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1090 | p_sp = (char_u *)">%s 2>&1"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1091 | # else |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1092 | if (fnamecmp(p, "pwsh") == 0) |
| 1093 | p_sp = (char_u *)">%s 2>&1"; |
| 1094 | else |
| 1095 | p_sp = (char_u *)"2>&1| tee"; |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1096 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1097 | options[idx_sp].def_val[VI_DEFAULT] = p_sp; |
| 1098 | } |
Bram Moolenaar | e7fedb6 | 2015-12-31 19:07:19 +0100 | [diff] [blame] | 1099 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1100 | if (do_srr) |
| 1101 | { |
| 1102 | p_srr = (char_u *)">%s 2>&1"; |
| 1103 | options[idx_srr].def_val[VI_DEFAULT] = p_srr; |
| 1104 | } |
| 1105 | } |
| 1106 | vim_free(p); |
| 1107 | } |
| 1108 | #endif |
| 1109 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 1110 | #if defined(MSWIN) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1111 | /* |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1112 | * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the |
| 1113 | * 'shell' option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1114 | * This is done after other initializations, where 'shell' might have been |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1115 | * set, but only if they have not been set before. |
| 1116 | * Default values depend on shell (cmd.exe is default shell): |
| 1117 | * |
| 1118 | * p_shcf p_sxq |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 1119 | * cmd.exe - "/c" "(" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1120 | * powershell.exe - "-Command" "\"" |
Mike Williams | a3d1b29 | 2021-06-30 20:56:00 +0200 | [diff] [blame] | 1121 | * pwsh.exe - "-c" "\"" |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1122 | * "sh" like shells - "-c" "\"" |
| 1123 | * |
| 1124 | * 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] | 1125 | */ |
Mike Williams | 1279502 | 2021-06-28 20:53:58 +0200 | [diff] [blame] | 1126 | if (strstr((char *)gettail(p_sh), "powershell") != NULL) |
| 1127 | { |
| 1128 | int idx_opt; |
| 1129 | |
| 1130 | idx_opt = findoption((char_u *)"shcf"); |
| 1131 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1132 | { |
| 1133 | p_shcf = (char_u*)"-Command"; |
| 1134 | options[idx_opt].def_val[VI_DEFAULT] = p_shcf; |
| 1135 | } |
| 1136 | |
| 1137 | idx_opt = findoption((char_u *)"sxq"); |
| 1138 | if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET)) |
| 1139 | { |
| 1140 | p_sxq = (char_u*)"\""; |
| 1141 | options[idx_opt].def_val[VI_DEFAULT] = p_sxq; |
| 1142 | } |
| 1143 | } |
| 1144 | else if (strstr((char *)gettail(p_sh), "sh") != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1145 | { |
| 1146 | int idx3; |
| 1147 | |
| 1148 | idx3 = findoption((char_u *)"shcf"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1149 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1150 | { |
| 1151 | p_shcf = (char_u *)"-c"; |
| 1152 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1153 | } |
| 1154 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1155 | // Somehow Win32 requires the quotes around the redirection too |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1156 | idx3 = findoption((char_u *)"sxq"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1157 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1158 | { |
| 1159 | p_sxq = (char_u *)"\""; |
| 1160 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1161 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1162 | } |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1163 | else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL) |
| 1164 | { |
| 1165 | int idx3; |
| 1166 | |
| 1167 | /* |
| 1168 | * cmd.exe on Windows will strip the first and last double quote given |
| 1169 | * on the command line, e.g. most of the time things like: |
| 1170 | * cmd /c "my path/to/echo" "my args to echo" |
| 1171 | * become: |
| 1172 | * my path/to/echo" "my args to echo |
| 1173 | * when executed. |
| 1174 | * |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1175 | * To avoid this, set shellxquote to surround the command in |
| 1176 | * parenthesis. This appears to make most commands work, without |
| 1177 | * breaking commands that worked previously, such as |
| 1178 | * '"path with spaces/cmd" "a&b"'. |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1179 | */ |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1180 | idx3 = findoption((char_u *)"sxq"); |
| 1181 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1182 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1183 | p_sxq = (char_u *)"("; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1184 | options[idx3].def_val[VI_DEFAULT] = p_sxq; |
| 1185 | } |
| 1186 | |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1187 | idx3 = findoption((char_u *)"shcf"); |
| 1188 | if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) |
| 1189 | { |
Bram Moolenaar | 034b115 | 2012-02-19 18:19:30 +0100 | [diff] [blame] | 1190 | p_shcf = (char_u *)"/c"; |
Bram Moolenaar | a64ba22 | 2012-02-12 23:23:31 +0100 | [diff] [blame] | 1191 | options[idx3].def_val[VI_DEFAULT] = p_shcf; |
| 1192 | } |
| 1193 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1194 | #endif |
| 1195 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 1196 | if (BUFEMPTY()) |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1197 | { |
| 1198 | int idx_ffs = findoption((char_u *)"ffs"); |
| 1199 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1200 | // Apply the first entry of 'fileformats' to the initial buffer. |
Bram Moolenaar | 364fa5c | 2016-03-20 17:53:25 +0100 | [diff] [blame] | 1201 | if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) |
| 1202 | set_fileformat(default_fileformat(), OPT_LOCAL); |
| 1203 | } |
| 1204 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1205 | set_title_defaults(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
| 1209 | /* |
| 1210 | * When 'helplang' is still at its default value, set it to "lang". |
| 1211 | * Only the first two characters of "lang" are used. |
| 1212 | */ |
| 1213 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1214 | set_helplang_default(char_u *lang) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1215 | { |
| 1216 | int idx; |
| 1217 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 1218 | if (lang == NULL || STRLEN(lang) < 2) // safety check |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1219 | return; |
| 1220 | idx = findoption((char_u *)"hlg"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1221 | if (idx < 0 || (options[idx].flags & P_WAS_SET)) |
| 1222 | return; |
| 1223 | |
| 1224 | if (options[idx].flags & P_ALLOCED) |
| 1225 | free_string_option(p_hlg); |
| 1226 | p_hlg = vim_strsave(lang); |
| 1227 | if (p_hlg == NULL) |
| 1228 | p_hlg = empty_option; |
| 1229 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1230 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1231 | // zh_CN becomes "cn", zh_TW becomes "tw" |
| 1232 | if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1233 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1234 | p_hlg[0] = TOLOWER_ASC(p_hlg[3]); |
| 1235 | p_hlg[1] = TOLOWER_ASC(p_hlg[4]); |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 1236 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1237 | // any C like setting, such as C.UTF-8, becomes "en" |
| 1238 | else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') |
| 1239 | { |
| 1240 | p_hlg[0] = 'e'; |
| 1241 | p_hlg[1] = 'n'; |
| 1242 | } |
| 1243 | p_hlg[2] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1244 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1245 | options[idx].flags |= P_ALLOCED; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1246 | } |
| 1247 | #endif |
| 1248 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1249 | /* |
| 1250 | * 'title' and 'icon' only default to true if they have not been set or reset |
| 1251 | * in .vimrc and we can read the old value. |
| 1252 | * When 'title' and 'icon' have been reset in .vimrc, we won't even check if |
| 1253 | * they can be reset. This reduces startup time when using X on a remote |
| 1254 | * machine. |
| 1255 | */ |
| 1256 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 1257 | set_title_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1258 | { |
| 1259 | int idx1; |
| 1260 | long val; |
| 1261 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 1262 | // If GUI is (going to be) used, we can always set the window title and |
| 1263 | // icon name. Saves a bit of time, because the X11 display server does |
| 1264 | // not need to be contacted. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1265 | idx1 = findoption((char_u *)"title"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 1266 | if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +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_title(); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1274 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | p_title = val; |
| 1276 | } |
| 1277 | idx1 = findoption((char_u *)"icon"); |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1278 | if (idx1 < 0 || (options[idx1].flags & P_WAS_SET)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1279 | { |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1280 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1281 | } |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 1282 | |
| 1283 | #ifdef FEAT_GUI |
| 1284 | if (gui.starting || gui.in_use) |
| 1285 | val = TRUE; |
| 1286 | else |
| 1287 | #endif |
| 1288 | val = mch_can_restore_icon(); |
| 1289 | options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; |
| 1290 | p_icon = val; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1291 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1292 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1293 | void |
| 1294 | ex_set(exarg_T *eap) |
| 1295 | { |
| 1296 | int flags = 0; |
| 1297 | |
| 1298 | if (eap->cmdidx == CMD_setlocal) |
| 1299 | flags = OPT_LOCAL; |
| 1300 | else if (eap->cmdidx == CMD_setglobal) |
| 1301 | flags = OPT_GLOBAL; |
| 1302 | #if defined(FEAT_EVAL) && defined(FEAT_BROWSE) |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 1303 | if ((cmdmod.cmod_flags & CMOD_BROWSE) && flags == 0) |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 1304 | ex_options(eap); |
| 1305 | else |
| 1306 | #endif |
| 1307 | { |
| 1308 | if (eap->forceit) |
| 1309 | flags |= OPT_ONECOLUMN; |
| 1310 | (void)do_set(eap->arg, flags); |
| 1311 | } |
| 1312 | } |
| 1313 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1314 | /* |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 1315 | * :set boolean option prefix |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1316 | */ |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1317 | typedef enum { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1318 | PREFIX_NO = 0, // "no" prefix |
| 1319 | PREFIX_NONE, // no prefix |
| 1320 | PREFIX_INV, // "inv" prefix |
| 1321 | } set_prefix_T; |
| 1322 | |
| 1323 | /* |
| 1324 | * Return the prefix type for the option name in *argp. |
| 1325 | */ |
| 1326 | static set_prefix_T |
| 1327 | get_option_prefix(char_u **argp) |
| 1328 | { |
| 1329 | int prefix = PREFIX_NONE; |
| 1330 | char_u *arg = *argp; |
| 1331 | |
| 1332 | if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0) |
| 1333 | { |
| 1334 | prefix = PREFIX_NO; |
| 1335 | arg += 2; |
| 1336 | } |
| 1337 | else if (STRNCMP(arg, "inv", 3) == 0) |
| 1338 | { |
| 1339 | prefix = PREFIX_INV; |
| 1340 | arg += 3; |
| 1341 | } |
| 1342 | |
| 1343 | *argp = arg; |
| 1344 | return prefix; |
| 1345 | } |
| 1346 | |
| 1347 | /* |
| 1348 | * Parse the option name in "arg" and return the option index in "*opt_idxp", |
| 1349 | * and the option name length in "*lenp". For a <t_xx> option, return the key |
| 1350 | * number in "*keyp". |
| 1351 | * |
| 1352 | * Returns FAIL if an option starting with "<" doesn't end with a ">", |
| 1353 | * otherwise returns OK. |
| 1354 | */ |
| 1355 | static int |
| 1356 | parse_option_name(char_u *arg, int *opt_idxp, int *lenp, int *keyp) |
| 1357 | { |
| 1358 | int key = 0; |
| 1359 | int len; |
| 1360 | int opt_idx; |
| 1361 | |
| 1362 | if (*arg == '<') |
| 1363 | { |
| 1364 | opt_idx = -1; |
| 1365 | // look out for <t_>;> |
| 1366 | if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) |
| 1367 | len = 5; |
| 1368 | else |
| 1369 | { |
| 1370 | len = 1; |
| 1371 | while (arg[len] != NUL && arg[len] != '>') |
| 1372 | ++len; |
| 1373 | } |
| 1374 | if (arg[len] != '>') |
| 1375 | return FAIL; |
| 1376 | |
| 1377 | arg[len] = NUL; // put NUL after name |
| 1378 | if (arg[1] == 't' && arg[2] == '_') // could be term code |
| 1379 | opt_idx = findoption(arg + 1); |
| 1380 | arg[len++] = '>'; // restore '>' |
| 1381 | if (opt_idx == -1) |
| 1382 | key = find_key_option(arg + 1, TRUE); |
| 1383 | } |
| 1384 | else |
| 1385 | { |
| 1386 | int nextchar; // next non-white char after option name |
| 1387 | |
| 1388 | len = 0; |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 1389 | // The two characters after "t_" may not be alphanumeric. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 1390 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 1391 | len = 4; |
| 1392 | else |
| 1393 | while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') |
| 1394 | ++len; |
| 1395 | nextchar = arg[len]; |
| 1396 | arg[len] = NUL; // put NUL after name |
| 1397 | opt_idx = findoption(arg); |
| 1398 | arg[len] = nextchar; // restore nextchar |
| 1399 | if (opt_idx == -1) |
| 1400 | key = find_key_option(arg, FALSE); |
| 1401 | } |
| 1402 | |
| 1403 | *keyp = key; |
| 1404 | *lenp = len; |
| 1405 | *opt_idxp = opt_idx; |
| 1406 | |
| 1407 | return OK; |
| 1408 | } |
| 1409 | |
| 1410 | /* |
| 1411 | * Get the option operator (+=, ^=, -=). |
| 1412 | */ |
| 1413 | static set_op_T |
| 1414 | get_opt_op(char_u *arg) |
| 1415 | { |
| 1416 | set_op_T op = OP_NONE; |
| 1417 | |
| 1418 | if (*arg != NUL && *(arg + 1) == '=') |
| 1419 | { |
| 1420 | if (*arg == '+') |
| 1421 | op = OP_ADDING; // "+=" |
| 1422 | else if (*arg == '^') |
| 1423 | op = OP_PREPENDING; // "^=" |
| 1424 | else if (*arg == '-') |
| 1425 | op = OP_REMOVING; // "-=" |
| 1426 | } |
| 1427 | |
| 1428 | return op; |
| 1429 | } |
| 1430 | |
| 1431 | /* |
| 1432 | * Validate whether the value of the option in "opt_idx" can be changed. |
| 1433 | * Returns FAIL if the option can be skipped or cannot be changed. Returns OK |
| 1434 | * if it can be changed. |
| 1435 | */ |
| 1436 | static int |
| 1437 | validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg) |
| 1438 | { |
| 1439 | // Skip all options that are not window-local (used when showing |
| 1440 | // an already loaded buffer in a window). |
| 1441 | if ((opt_flags & OPT_WINONLY) |
| 1442 | && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) |
| 1443 | return FAIL; |
| 1444 | |
| 1445 | // Skip all options that are window-local (used for :vimgrep). |
| 1446 | if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 |
| 1447 | && options[opt_idx].var == VAR_WIN) |
| 1448 | return FAIL; |
| 1449 | |
| 1450 | // Disallow changing some options from modelines. |
| 1451 | if (opt_flags & OPT_MODELINE) |
| 1452 | { |
| 1453 | if (flags & (P_SECURE | P_NO_ML)) |
| 1454 | { |
| 1455 | *errmsg = e_not_allowed_in_modeline; |
| 1456 | return FAIL; |
| 1457 | } |
| 1458 | if ((flags & P_MLE) && !p_mle) |
| 1459 | { |
| 1460 | *errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off; |
| 1461 | return FAIL; |
| 1462 | } |
| 1463 | #ifdef FEAT_DIFF |
| 1464 | // In diff mode some options are overruled. This avoids that |
| 1465 | // 'foldmethod' becomes "marker" instead of "diff" and that |
| 1466 | // "wrap" gets set. |
| 1467 | if (curwin->w_p_diff |
| 1468 | && opt_idx >= 0 // shut up coverity warning |
| 1469 | && ( |
| 1470 | # ifdef FEAT_FOLDING |
| 1471 | options[opt_idx].indir == PV_FDM || |
| 1472 | # endif |
| 1473 | options[opt_idx].indir == PV_WRAP)) |
| 1474 | return FAIL; |
| 1475 | #endif |
| 1476 | } |
| 1477 | |
| 1478 | #ifdef HAVE_SANDBOX |
| 1479 | // Disallow changing some options in the sandbox |
| 1480 | if (sandbox != 0 && (flags & P_SECURE)) |
| 1481 | { |
| 1482 | *errmsg = e_not_allowed_in_sandbox; |
| 1483 | return FAIL; |
| 1484 | } |
| 1485 | #endif |
| 1486 | |
| 1487 | return OK; |
| 1488 | } |
| 1489 | |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1490 | /* |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1491 | * Get the Vim/Vi default value for a string option. |
| 1492 | */ |
| 1493 | static char_u * |
| 1494 | stropt_get_default_val( |
| 1495 | int opt_idx, |
| 1496 | char_u *varp, |
| 1497 | int flags, |
| 1498 | int cp_val) |
| 1499 | { |
| 1500 | char_u *newval; |
| 1501 | |
| 1502 | newval = options[opt_idx].def_val[((flags & P_VI_DEF) || cp_val) |
| 1503 | ? VI_DEFAULT : VIM_DEFAULT]; |
| 1504 | if ((char_u **)varp == &p_bg) |
| 1505 | { |
| 1506 | // guess the value of 'background' |
| 1507 | #ifdef FEAT_GUI |
| 1508 | if (gui.in_use) |
| 1509 | newval = gui_bg_default(); |
| 1510 | else |
| 1511 | #endif |
| 1512 | newval = term_bg_default(); |
| 1513 | } |
| 1514 | else if ((char_u **)varp == &p_fencs && enc_utf8) |
| 1515 | newval = fencs_utf8_default; |
| 1516 | |
| 1517 | // expand environment variables and ~ since the default value was |
| 1518 | // already expanded, only required when an environment variable was set |
| 1519 | // later |
| 1520 | if (newval == NULL) |
| 1521 | newval = empty_option; |
| 1522 | else |
| 1523 | { |
| 1524 | char_u *s = option_expand(opt_idx, newval); |
| 1525 | if (s == NULL) |
| 1526 | s = newval; |
| 1527 | newval = vim_strsave(s); |
| 1528 | } |
| 1529 | |
| 1530 | return newval; |
| 1531 | } |
| 1532 | |
| 1533 | /* |
| 1534 | * Convert the 'backspace' option number value to a string: for adding, |
| 1535 | * prepending and removing string. |
| 1536 | */ |
| 1537 | static void |
| 1538 | opt_backspace_nr2str( |
| 1539 | char_u *varp, |
| 1540 | char_u **origval_p, |
| 1541 | char_u **origval_l_p, |
| 1542 | char_u **origval_g_p, |
| 1543 | char_u **oldval_p) |
| 1544 | { |
| 1545 | int i = getdigits((char_u **)varp); |
| 1546 | |
| 1547 | switch (i) |
| 1548 | { |
| 1549 | case 0: |
| 1550 | *(char_u **)varp = empty_option; |
| 1551 | break; |
| 1552 | case 1: |
| 1553 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); |
| 1554 | break; |
| 1555 | case 2: |
| 1556 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start"); |
| 1557 | break; |
| 1558 | case 3: |
| 1559 | *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop"); |
| 1560 | break; |
| 1561 | } |
| 1562 | vim_free(*oldval_p); |
| 1563 | if (*origval_p == *oldval_p) |
| 1564 | *origval_p = *(char_u **)varp; |
| 1565 | if (*origval_l_p == *oldval_p) |
| 1566 | *origval_l_p = *(char_u **)varp; |
| 1567 | if (*origval_g_p == *oldval_p) |
| 1568 | *origval_g_p = *(char_u **)varp; |
| 1569 | *oldval_p = *(char_u **)varp; |
| 1570 | } |
| 1571 | |
| 1572 | /* |
| 1573 | * Convert the 'whichwrap' option number value to a string, for backwards |
| 1574 | * compatibility with Vim 3.0. |
| 1575 | * Note: 'argp' is a pointer to a char_u pointer and is updated. |
| 1576 | */ |
| 1577 | static char_u * |
| 1578 | opt_whichwrap_nr2str(char_u **argp, char_u *whichwrap) |
| 1579 | { |
| 1580 | *whichwrap = NUL; |
| 1581 | int i = getdigits(argp); |
| 1582 | if (i & 1) |
| 1583 | STRCAT(whichwrap, "b,"); |
| 1584 | if (i & 2) |
| 1585 | STRCAT(whichwrap, "s,"); |
| 1586 | if (i & 4) |
| 1587 | STRCAT(whichwrap, "h,l,"); |
| 1588 | if (i & 8) |
| 1589 | STRCAT(whichwrap, "<,>,"); |
| 1590 | if (i & 16) |
| 1591 | STRCAT(whichwrap, "[,],"); |
| 1592 | if (*whichwrap != NUL) // remove trailing , |
| 1593 | whichwrap[STRLEN(whichwrap) - 1] = NUL; |
| 1594 | |
| 1595 | return whichwrap; |
| 1596 | } |
| 1597 | |
| 1598 | /* |
| 1599 | * Copy the new string value into allocated memory for the option. |
| 1600 | * Can't use set_string_option_direct(), because we need to remove the |
| 1601 | * backslashes. |
| 1602 | */ |
| 1603 | static char_u * |
| 1604 | stropt_copy_value( |
| 1605 | char_u *origval, |
| 1606 | char_u **argp, |
| 1607 | set_op_T op, |
| 1608 | int flags UNUSED) |
| 1609 | { |
| 1610 | char_u *arg = *argp; |
| 1611 | unsigned newlen; |
| 1612 | char_u *newval; |
| 1613 | char_u *s = NULL; |
| 1614 | |
| 1615 | // get a bit too much |
| 1616 | newlen = (unsigned)STRLEN(arg) + 1; |
| 1617 | if (op != OP_NONE) |
| 1618 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1619 | newval = alloc(newlen); |
| 1620 | if (newval == NULL) // out of mem, don't change |
| 1621 | return NULL; |
| 1622 | s = newval; |
| 1623 | |
| 1624 | // Copy the string, skip over escaped chars. |
| 1625 | // For MS-DOS and WIN32 backslashes before normal file name characters |
| 1626 | // are not removed, and keep backslash at start, for "\\machine\path", |
| 1627 | // but do remove it for "\\\\machine\\path". |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 1628 | // The reverse is found in escape_option_str_cmdline(). |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1629 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
| 1630 | { |
| 1631 | int i; |
| 1632 | |
| 1633 | if (*arg == '\\' && arg[1] != NUL |
| 1634 | #ifdef BACKSLASH_IN_FILENAME |
| 1635 | && !((flags & P_EXPAND) |
| 1636 | && vim_isfilec(arg[1]) |
| 1637 | && !VIM_ISWHITE(arg[1]) |
| 1638 | && (arg[1] != '\\' |
| 1639 | || (s == newval && arg[2] != '\\'))) |
| 1640 | #endif |
| 1641 | ) |
| 1642 | ++arg; // remove backslash |
| 1643 | if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) |
| 1644 | { |
| 1645 | // copy multibyte char |
| 1646 | mch_memmove(s, arg, (size_t)i); |
| 1647 | arg += i; |
| 1648 | s += i; |
| 1649 | } |
| 1650 | else |
| 1651 | *s++ = *arg++; |
| 1652 | } |
| 1653 | *s = NUL; |
| 1654 | |
| 1655 | *argp = arg; |
| 1656 | return newval; |
| 1657 | } |
| 1658 | |
| 1659 | /* |
| 1660 | * Expand environment variables and ~ in string option value 'newval'. |
| 1661 | */ |
| 1662 | static char_u * |
| 1663 | stropt_expand_envvar( |
| 1664 | int opt_idx, |
| 1665 | char_u *origval, |
| 1666 | char_u *newval, |
| 1667 | set_op_T op) |
| 1668 | { |
| 1669 | char_u *s = option_expand(opt_idx, newval); |
| 1670 | if (s == NULL) |
| 1671 | return newval; |
| 1672 | |
| 1673 | vim_free(newval); |
| 1674 | unsigned newlen = (unsigned)STRLEN(s) + 1; |
| 1675 | if (op != OP_NONE) |
| 1676 | newlen += (unsigned)STRLEN(origval) + 1; |
| 1677 | |
| 1678 | newval = alloc(newlen); |
| 1679 | if (newval == NULL) |
| 1680 | return NULL; |
| 1681 | |
| 1682 | STRCPY(newval, s); |
| 1683 | |
| 1684 | return newval; |
| 1685 | } |
| 1686 | |
| 1687 | /* |
| 1688 | * Concatenate the original and new values of a string option, adding a "," if |
| 1689 | * needed. |
| 1690 | */ |
| 1691 | static void |
| 1692 | stropt_concat_with_comma( |
| 1693 | char_u *origval, |
| 1694 | char_u *newval, |
| 1695 | set_op_T op, |
| 1696 | int flags) |
| 1697 | { |
| 1698 | int len = 0; |
| 1699 | |
| 1700 | int comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); |
| 1701 | if (op == OP_ADDING) |
| 1702 | { |
| 1703 | len = (int)STRLEN(origval); |
| 1704 | // strip a trailing comma, would get 2 |
| 1705 | if (comma && len > 1 |
| 1706 | && (flags & P_ONECOMMA) == P_ONECOMMA |
| 1707 | && origval[len - 1] == ',' |
| 1708 | && origval[len - 2] != '\\') |
| 1709 | len--; |
| 1710 | mch_memmove(newval + len + comma, newval, STRLEN(newval) + 1); |
| 1711 | mch_memmove(newval, origval, (size_t)len); |
| 1712 | } |
| 1713 | else |
| 1714 | { |
| 1715 | len = (int)STRLEN(newval); |
| 1716 | STRMOVE(newval + len + comma, origval); |
| 1717 | } |
| 1718 | if (comma) |
| 1719 | newval[len] = ','; |
| 1720 | } |
| 1721 | |
| 1722 | /* |
| 1723 | * Remove a value from a string option. Copy string option value in "origval" |
| 1724 | * to "newval" and then remove the string "strval" of length "len". |
| 1725 | */ |
| 1726 | static void |
| 1727 | stropt_remove_val( |
| 1728 | char_u *origval, |
| 1729 | char_u *newval, |
| 1730 | int flags, |
| 1731 | char_u *strval, |
| 1732 | int len) |
| 1733 | { |
| 1734 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1735 | // and is used here). |
| 1736 | STRCPY(newval, origval); |
| 1737 | if (*strval) |
| 1738 | { |
| 1739 | // may need to remove a comma |
| 1740 | if (flags & P_COMMA) |
| 1741 | { |
| 1742 | if (strval == origval) |
| 1743 | { |
| 1744 | // include comma after string |
| 1745 | if (strval[len] == ',') |
| 1746 | ++len; |
| 1747 | } |
| 1748 | else |
| 1749 | { |
| 1750 | // include comma before string |
| 1751 | --strval; |
| 1752 | ++len; |
| 1753 | } |
| 1754 | } |
| 1755 | STRMOVE(newval + (strval - origval), strval + len); |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | /* |
| 1760 | * Remove flags that appear twice in the string option value 'newval'. |
| 1761 | */ |
| 1762 | static void |
| 1763 | stropt_remove_dupflags(char_u *newval, int flags) |
| 1764 | { |
| 1765 | char_u *s = newval; |
| 1766 | |
| 1767 | // Remove flags that appear twice. |
| 1768 | while (*s) |
| 1769 | { |
| 1770 | // if options have P_FLAGLIST and P_ONECOMMA such as 'whichwrap' |
| 1771 | if (flags & P_ONECOMMA) |
| 1772 | { |
| 1773 | if (*s != ',' && *(s + 1) == ',' && vim_strchr(s + 2, *s) != NULL) |
| 1774 | { |
| 1775 | // Remove the duplicated value and the next comma. |
| 1776 | STRMOVE(s, s + 2); |
| 1777 | continue; |
| 1778 | } |
| 1779 | } |
| 1780 | else |
| 1781 | { |
| 1782 | if ((!(flags & P_COMMA) || *s != ',') |
| 1783 | && vim_strchr(s + 1, *s) != NULL) |
| 1784 | { |
| 1785 | STRMOVE(s, s + 1); |
| 1786 | continue; |
| 1787 | } |
| 1788 | } |
| 1789 | ++s; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | /* |
| 1794 | * Get the string value specified for a ":set" command. The following set |
| 1795 | * options are supported: |
| 1796 | * set {opt}& |
| 1797 | * set {opt}< |
| 1798 | * set {opt}={val} |
| 1799 | * set {opt}:{val} |
| 1800 | */ |
| 1801 | static char_u * |
| 1802 | stropt_get_newval( |
| 1803 | int nextchar, |
| 1804 | int opt_idx, |
| 1805 | char_u **argp, |
| 1806 | char_u *varp, |
| 1807 | char_u **origval_arg, |
| 1808 | char_u **origval_l_arg, |
| 1809 | char_u **origval_g_arg, |
| 1810 | char_u **oldval_arg, |
| 1811 | set_op_T *op_arg, |
| 1812 | int flags, |
| 1813 | int cp_val) |
| 1814 | { |
| 1815 | char_u *arg = *argp; |
| 1816 | char_u *origval = *origval_arg; |
| 1817 | char_u *origval_l = *origval_l_arg; |
| 1818 | char_u *origval_g = *origval_g_arg; |
| 1819 | char_u *oldval = *oldval_arg; |
| 1820 | set_op_T op = *op_arg; |
| 1821 | char_u *save_arg = NULL; |
| 1822 | char_u *newval; |
| 1823 | char_u *s = NULL; |
| 1824 | char_u whichwrap[80]; |
| 1825 | |
| 1826 | if (nextchar == '&') // set to default val |
| 1827 | newval = stropt_get_default_val(opt_idx, varp, flags, cp_val); |
| 1828 | else if (nextchar == '<') // set to global val |
| 1829 | newval = vim_strsave(*(char_u **)get_varp_scope( |
| 1830 | &(options[opt_idx]), OPT_GLOBAL)); |
| 1831 | else |
| 1832 | { |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 1833 | ++arg; // jump to after the '=' or ':' |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1834 | |
| 1835 | // Set 'keywordprg' to ":help" if an empty |
| 1836 | // value was passed to :set by the user. |
| 1837 | if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' ')) |
| 1838 | { |
| 1839 | save_arg = arg; |
| 1840 | arg = (char_u *)":help"; |
| 1841 | } |
| 1842 | // Convert 'backspace' number to string |
| 1843 | else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) |
| 1844 | opt_backspace_nr2str(varp, &origval, &origval_l, &origval_g, |
| 1845 | &oldval); |
| 1846 | else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) |
| 1847 | { |
| 1848 | // Convert 'whichwrap' number to string, for backwards |
| 1849 | // compatibility with Vim 3.0. |
| 1850 | char_u *t = opt_whichwrap_nr2str(&arg, whichwrap); |
| 1851 | save_arg = arg; |
| 1852 | arg = t; |
| 1853 | } |
| 1854 | // Remove '>' before 'dir' and 'bdir', for backwards compatibility with |
| 1855 | // version 3.0 |
| 1856 | else if (*arg == '>' && (varp == (char_u *)&p_dir |
| 1857 | || varp == (char_u *)&p_bdir)) |
| 1858 | ++arg; |
| 1859 | |
| 1860 | // Copy the new string into allocated memory. |
| 1861 | newval = stropt_copy_value(origval, &arg, op, flags); |
| 1862 | if (newval == NULL) |
| 1863 | goto done; |
| 1864 | |
| 1865 | // Expand environment variables and ~. |
| 1866 | // Don't do it when adding without inserting a comma. |
| 1867 | if (op == OP_NONE || (flags & P_COMMA)) |
| 1868 | { |
| 1869 | newval = stropt_expand_envvar(opt_idx, origval, newval, op); |
| 1870 | if (newval == NULL) |
| 1871 | goto done; |
| 1872 | } |
| 1873 | |
| 1874 | // locate newval[] in origval[] when removing it and when adding to |
| 1875 | // avoid duplicates |
| 1876 | int len = 0; |
| 1877 | if (op == OP_REMOVING || (flags & P_NODUP)) |
| 1878 | { |
| 1879 | len = (int)STRLEN(newval); |
| 1880 | s = find_dup_item(origval, newval, flags); |
| 1881 | |
| 1882 | // do not add if already there |
| 1883 | if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) |
| 1884 | { |
| 1885 | op = OP_NONE; |
| 1886 | STRCPY(newval, origval); |
| 1887 | } |
| 1888 | |
| 1889 | // if no duplicate, move pointer to end of original value |
| 1890 | if (s == NULL) |
| 1891 | s = origval + (int)STRLEN(origval); |
| 1892 | } |
| 1893 | |
| 1894 | // concatenate the two strings; add a ',' if needed |
| 1895 | if (op == OP_ADDING || op == OP_PREPENDING) |
| 1896 | stropt_concat_with_comma(origval, newval, op, flags); |
| 1897 | else if (op == OP_REMOVING) |
| 1898 | // Remove newval[] from origval[]. (Note: "len" has been set above |
| 1899 | // and is used here). |
| 1900 | stropt_remove_val(origval, newval, flags, s, len); |
| 1901 | |
| 1902 | if (flags & P_FLAGLIST) |
| 1903 | // Remove flags that appear twice. |
| 1904 | stropt_remove_dupflags(newval, flags); |
| 1905 | } |
| 1906 | |
| 1907 | done: |
| 1908 | if (save_arg != NULL) |
| 1909 | arg = save_arg; // arg was temporarily changed, restore it |
| 1910 | *argp = arg; |
| 1911 | *origval_arg = origval; |
| 1912 | *origval_l_arg = origval_l; |
| 1913 | *origval_g_arg = origval_g; |
| 1914 | *oldval_arg = oldval; |
| 1915 | *op_arg = op; |
| 1916 | |
| 1917 | return newval; |
| 1918 | } |
| 1919 | |
| 1920 | /* |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1921 | * Part of do_set() for string options. |
| 1922 | * Returns FAIL on failure, do not process further options. |
| 1923 | */ |
| 1924 | static int |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1925 | do_set_option_string( |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1926 | int opt_idx, |
| 1927 | int opt_flags, |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1928 | char_u **argp, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1929 | int nextchar, |
| 1930 | set_op_T op_arg, |
Yee Cheng Chin | 6ee7b52 | 2023-10-01 09:13:22 +0200 | [diff] [blame] | 1931 | long_u flags, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1932 | int cp_val, |
| 1933 | char_u *varp_arg, |
| 1934 | char *errbuf, |
| 1935 | int *value_checked, |
| 1936 | char **errmsg) |
| 1937 | { |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 1938 | char_u *arg = *argp; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1939 | set_op_T op = op_arg; |
| 1940 | char_u *varp = varp_arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1941 | char_u *oldval = NULL; // previous value if *varp |
| 1942 | char_u *newval; |
| 1943 | char_u *origval = NULL; |
| 1944 | char_u *origval_l = NULL; |
| 1945 | char_u *origval_g = NULL; |
| 1946 | #if defined(FEAT_EVAL) |
| 1947 | char_u *saved_origval = NULL; |
| 1948 | char_u *saved_origval_l = NULL; |
| 1949 | char_u *saved_origval_g = NULL; |
| 1950 | char_u *saved_newval = NULL; |
| 1951 | #endif |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1952 | |
| 1953 | // When using ":set opt=val" for a global option |
| 1954 | // with a local value the local value will be |
| 1955 | // reset, use the global value here. |
| 1956 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
| 1957 | && ((int)options[opt_idx].indir & PV_BOTH)) |
| 1958 | varp = options[opt_idx].var; |
| 1959 | |
| 1960 | // The old value is kept until we are sure that the new value is valid. |
| 1961 | oldval = *(char_u **)varp; |
| 1962 | |
| 1963 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 1964 | { |
| 1965 | origval_l = *(char_u **)get_varp_scope( |
| 1966 | &(options[opt_idx]), OPT_LOCAL); |
| 1967 | origval_g = *(char_u **)get_varp_scope( |
| 1968 | &(options[opt_idx]), OPT_GLOBAL); |
| 1969 | |
| 1970 | // A global-local string option might have an empty option as value to |
| 1971 | // indicate that the global value should be used. |
| 1972 | if (((int)options[opt_idx].indir & PV_BOTH) |
| 1973 | && origval_l == empty_option) |
| 1974 | origval_l = origval_g; |
| 1975 | } |
| 1976 | |
| 1977 | // When setting the local value of a global option, the old value may be |
| 1978 | // the global value. |
| 1979 | if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) |
| 1980 | origval = *(char_u **)get_varp(&options[opt_idx]); |
| 1981 | else |
| 1982 | origval = oldval; |
| 1983 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1984 | // Get the new value for the option |
| 1985 | newval = stropt_get_newval(nextchar, opt_idx, &arg, varp, &origval, |
| 1986 | &origval_l, &origval_g, &oldval, &op, flags, |
| 1987 | cp_val); |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1988 | |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 1989 | // Set the new value. |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1990 | *(char_u **)(varp) = newval; |
Bram Moolenaar | 339e114 | 2023-02-15 14:26:25 +0000 | [diff] [blame] | 1991 | if (newval == NULL) |
| 1992 | *(char_u **)(varp) = empty_option; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 1993 | |
| 1994 | #if defined(FEAT_EVAL) |
| 1995 | if (!starting |
| 1996 | # ifdef FEAT_CRYPT |
| 1997 | && options[opt_idx].indir != PV_KEY |
| 1998 | # endif |
| 1999 | && origval != NULL && newval != NULL) |
| 2000 | { |
| 2001 | // origval may be freed by did_set_string_option(), make a copy. |
| 2002 | saved_origval = vim_strsave(origval); |
| 2003 | // newval (and varp) may become invalid if the buffer is closed by |
| 2004 | // autocommands. |
| 2005 | saved_newval = vim_strsave(newval); |
| 2006 | if (origval_l != NULL) |
| 2007 | saved_origval_l = vim_strsave(origval_l); |
| 2008 | if (origval_g != NULL) |
| 2009 | saved_origval_g = vim_strsave(origval_g); |
| 2010 | } |
| 2011 | #endif |
| 2012 | |
| 2013 | { |
| 2014 | long_u *p = insecure_flag(opt_idx, opt_flags); |
| 2015 | int secure_saved = secure; |
| 2016 | |
| 2017 | // When an option is set in the sandbox, from a modeline or in secure |
| 2018 | // mode, then deal with side effects in secure mode. Also when the |
| 2019 | // value was set with the P_INSECURE flag and is not completely |
| 2020 | // replaced. |
| 2021 | if ((opt_flags & OPT_MODELINE) |
| 2022 | #ifdef HAVE_SANDBOX |
| 2023 | || sandbox != 0 |
| 2024 | #endif |
| 2025 | || (op != OP_NONE && (*p & P_INSECURE))) |
| 2026 | secure = 1; |
| 2027 | |
| 2028 | // Handle side effects, and set the global value for ":set" on local |
| 2029 | // options. Note: when setting 'syntax' or 'filetype' autocommands may |
| 2030 | // be triggered that can cause havoc. |
| 2031 | *errmsg = did_set_string_option( |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2032 | opt_idx, (char_u **)varp, oldval, newval, errbuf, |
Yee Cheng Chin | 6ee7b52 | 2023-10-01 09:13:22 +0200 | [diff] [blame] | 2033 | opt_flags, op, value_checked); |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2034 | |
| 2035 | secure = secure_saved; |
| 2036 | } |
| 2037 | |
| 2038 | #if defined(FEAT_EVAL) |
| 2039 | if (*errmsg == NULL) |
zeertzjq | 269aa2b | 2022-11-28 11:36:50 +0000 | [diff] [blame] | 2040 | trigger_optionset_string(opt_idx, opt_flags, saved_origval, |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2041 | saved_origval_l, saved_origval_g, saved_newval); |
| 2042 | vim_free(saved_origval); |
| 2043 | vim_free(saved_origval_l); |
| 2044 | vim_free(saved_origval_g); |
| 2045 | vim_free(saved_newval); |
| 2046 | #endif |
| 2047 | |
Bram Moolenaar | 6f98114 | 2022-09-22 12:48:58 +0100 | [diff] [blame] | 2048 | *argp = arg; |
Bram Moolenaar | 4740394 | 2022-09-21 21:12:53 +0100 | [diff] [blame] | 2049 | return *errmsg == NULL ? OK : FAIL; |
| 2050 | } |
| 2051 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2052 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2053 | * Set a boolean option. |
| 2054 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2055 | */ |
| 2056 | static char * |
| 2057 | do_set_option_bool( |
| 2058 | int opt_idx, |
| 2059 | int opt_flags, |
| 2060 | set_prefix_T prefix, |
| 2061 | long_u flags, |
| 2062 | char_u *varp, |
| 2063 | int nextchar, |
| 2064 | int afterchar, |
| 2065 | int cp_val) |
| 2066 | |
| 2067 | { |
| 2068 | varnumber_T value; |
| 2069 | |
| 2070 | if (nextchar == '=' || nextchar == ':') |
| 2071 | return e_invalid_argument; |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2072 | if (opt_idx < 0 || varp == NULL) |
| 2073 | return NULL; // "cannot happen" |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2074 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2075 | // ":set opt!": invert |
| 2076 | // ":set opt&": reset to default value |
| 2077 | // ":set opt<": reset to global value |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2078 | if (nextchar == '!') |
| 2079 | value = *(int *)(varp) ^ 1; |
| 2080 | else if (nextchar == '&') |
| 2081 | value = (int)(long)(long_i)options[opt_idx].def_val[ |
| 2082 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2083 | else if (nextchar == '<') |
| 2084 | { |
| 2085 | // For 'autoread' -1 means to use global value. |
| 2086 | if ((int *)varp == &curbuf->b_p_ar && opt_flags == OPT_LOCAL) |
| 2087 | value = -1; |
| 2088 | else |
| 2089 | value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2090 | } |
| 2091 | else |
| 2092 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2093 | // ":set invopt": invert |
| 2094 | // ":set opt" or ":set noopt": set or reset |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2095 | if (nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2096 | return e_trailing_characters; |
| 2097 | if (prefix == PREFIX_INV) |
| 2098 | value = *(int *)(varp) ^ 1; |
| 2099 | else |
| 2100 | value = prefix == PREFIX_NO ? 0 : 1; |
| 2101 | } |
| 2102 | |
| 2103 | return set_bool_option(opt_idx, varp, (int)value, opt_flags); |
| 2104 | } |
| 2105 | |
| 2106 | /* |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2107 | * Set a numeric option. |
| 2108 | * Returns an untranslated error message or NULL. |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2109 | */ |
| 2110 | static char * |
| 2111 | do_set_option_numeric( |
| 2112 | int opt_idx, |
| 2113 | int opt_flags, |
| 2114 | char_u **argp, |
| 2115 | int nextchar, |
| 2116 | set_op_T op, |
| 2117 | long_u flags, |
| 2118 | int cp_val, |
| 2119 | char_u *varp, |
| 2120 | char *errbuf, |
| 2121 | size_t errbuflen) |
| 2122 | { |
| 2123 | char_u *arg = *argp; |
| 2124 | varnumber_T value; |
| 2125 | int i; |
| 2126 | char *errmsg = NULL; |
| 2127 | |
Bram Moolenaar | 546933f | 2023-02-06 16:40:49 +0000 | [diff] [blame] | 2128 | if (opt_idx < 0 || varp == NULL) |
| 2129 | return NULL; // "cannot happen" |
| 2130 | // |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2131 | /* |
| 2132 | * Different ways to set a number option: |
| 2133 | * & set to default value |
| 2134 | * < set to global value |
| 2135 | * <xx> accept special key codes for 'wildchar' |
| 2136 | * c accept any non-digit for 'wildchar' |
| 2137 | * [-]0-9 set number |
| 2138 | * other error |
| 2139 | */ |
| 2140 | ++arg; |
| 2141 | if (nextchar == '&') |
| 2142 | value = (long)(long_i)options[opt_idx].def_val[ |
| 2143 | ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; |
| 2144 | else if (nextchar == '<') |
| 2145 | { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2146 | if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 2147 | // for 'undolevels' NO_LOCAL_UNDOLEVEL means using the global value |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2148 | value = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | bf5f189 | 2023-06-27 21:51:07 +0100 | [diff] [blame] | 2149 | else if (opt_flags == OPT_LOCAL |
| 2150 | && ((long *)varp == &curwin->w_p_siso |
| 2151 | || (long *)varp == &curwin->w_p_so)) |
| 2152 | // for 'scrolloff'/'sidescrolloff' -1 means using the global value |
| 2153 | value = -1; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2154 | else |
| 2155 | value = *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); |
| 2156 | } |
| 2157 | else if (((long *)varp == &p_wc || (long *)varp == &p_wcm) |
| 2158 | && (*arg == '<' |
| 2159 | || *arg == '^' |
| 2160 | || (*arg != NUL |
| 2161 | && (!arg[1] || VIM_ISWHITE(arg[1])) |
| 2162 | && !VIM_ISDIGIT(*arg)))) |
| 2163 | { |
| 2164 | value = string_to_key(arg, FALSE); |
| 2165 | if (value == 0 && (long *)varp != &p_wcm) |
| 2166 | { |
| 2167 | errmsg = e_invalid_argument; |
| 2168 | goto skip; |
| 2169 | } |
| 2170 | } |
| 2171 | else if (*arg == '-' || VIM_ISDIGIT(*arg)) |
| 2172 | { |
| 2173 | // Allow negative (for 'undolevels'), octal and hex numbers. |
Bram Moolenaar | 5fb78c3 | 2023-03-04 20:47:39 +0000 | [diff] [blame] | 2174 | vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, TRUE, NULL); |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2175 | if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i]))) |
| 2176 | { |
| 2177 | errmsg = e_number_required_after_equal; |
| 2178 | goto skip; |
| 2179 | } |
| 2180 | } |
| 2181 | else |
| 2182 | { |
| 2183 | errmsg = e_number_required_after_equal; |
| 2184 | goto skip; |
| 2185 | } |
| 2186 | |
| 2187 | if (op == OP_ADDING) |
| 2188 | value = *(long *)varp + value; |
| 2189 | else if (op == OP_PREPENDING) |
| 2190 | value = *(long *)varp * value; |
| 2191 | else if (op == OP_REMOVING) |
| 2192 | value = *(long *)varp - value; |
| 2193 | |
| 2194 | errmsg = set_num_option(opt_idx, varp, value, errbuf, errbuflen, |
| 2195 | opt_flags); |
| 2196 | |
| 2197 | skip: |
| 2198 | *argp = arg; |
| 2199 | return errmsg; |
| 2200 | } |
| 2201 | |
| 2202 | /* |
| 2203 | * Set a key code (t_xx) option |
| 2204 | */ |
| 2205 | static char * |
| 2206 | do_set_option_keycode(char_u **argp, char_u *key_name, int nextchar) |
| 2207 | { |
| 2208 | char_u *arg = *argp; |
| 2209 | char_u *p; |
| 2210 | |
| 2211 | if (nextchar == '&') |
| 2212 | { |
| 2213 | if (add_termcap_entry(key_name, TRUE) == FAIL) |
| 2214 | return e_not_found_in_termcap; |
| 2215 | } |
| 2216 | else |
| 2217 | { |
| 2218 | ++arg; // jump to after the '=' or ':' |
| 2219 | for (p = arg; *p && !VIM_ISWHITE(*p); ++p) |
| 2220 | if (*p == '\\' && p[1] != NUL) |
| 2221 | ++p; |
| 2222 | nextchar = *p; |
| 2223 | *p = NUL; |
| 2224 | add_termcode(key_name, arg, FALSE); |
| 2225 | *p = nextchar; |
| 2226 | } |
| 2227 | if (full_screen) |
| 2228 | ttest(FALSE); |
| 2229 | redraw_all_later(UPD_CLEAR); |
| 2230 | |
| 2231 | *argp = arg; |
| 2232 | return NULL; |
| 2233 | } |
| 2234 | |
| 2235 | /* |
| 2236 | * Set an option to a new value. |
| 2237 | */ |
| 2238 | static char * |
| 2239 | do_set_option_value( |
| 2240 | int opt_idx, |
| 2241 | int opt_flags, |
| 2242 | char_u **argp, |
| 2243 | set_prefix_T prefix, |
| 2244 | set_op_T op, |
| 2245 | long_u flags, |
| 2246 | char_u *varp, |
| 2247 | char_u *key_name, |
| 2248 | int nextchar, |
| 2249 | int afterchar, |
| 2250 | int cp_val, |
| 2251 | int *stopopteval, |
| 2252 | char *errbuf, |
| 2253 | size_t errbuflen) |
| 2254 | { |
| 2255 | int value_checked = FALSE; |
| 2256 | char *errmsg = NULL; |
| 2257 | char_u *arg = *argp; |
| 2258 | |
| 2259 | if (flags & P_BOOL) |
| 2260 | { |
| 2261 | // boolean option |
| 2262 | errmsg = do_set_option_bool(opt_idx, opt_flags, prefix, flags, varp, |
| 2263 | nextchar, afterchar, cp_val); |
| 2264 | if (errmsg != NULL) |
| 2265 | goto skip; |
| 2266 | } |
| 2267 | else |
| 2268 | { |
| 2269 | // numeric or string option |
| 2270 | if (vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2271 | || prefix != PREFIX_NONE) |
| 2272 | { |
| 2273 | errmsg = e_invalid_argument; |
| 2274 | goto skip; |
| 2275 | } |
| 2276 | |
| 2277 | if (flags & P_NUM) |
| 2278 | { |
| 2279 | // numeric option |
| 2280 | errmsg = do_set_option_numeric(opt_idx, opt_flags, &arg, nextchar, |
| 2281 | op, flags, cp_val, varp, |
| 2282 | errbuf, errbuflen); |
| 2283 | if (errmsg != NULL) |
| 2284 | goto skip; |
| 2285 | } |
| 2286 | else if (opt_idx >= 0) |
| 2287 | { |
| 2288 | // string option |
Yegappan Lakshmanan | 1a64764 | 2023-02-14 13:07:18 +0000 | [diff] [blame] | 2289 | if (do_set_option_string(opt_idx, opt_flags, &arg, nextchar, op, |
| 2290 | flags, cp_val, varp, errbuf, |
| 2291 | &value_checked, &errmsg) == FAIL) |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2292 | { |
| 2293 | if (errmsg != NULL) |
| 2294 | goto skip; |
| 2295 | *stopopteval = TRUE; |
| 2296 | goto skip; |
| 2297 | } |
| 2298 | } |
| 2299 | else |
| 2300 | { |
| 2301 | // key code option |
| 2302 | errmsg = do_set_option_keycode(&arg, key_name, nextchar); |
| 2303 | if (errmsg != NULL) |
| 2304 | goto skip; |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | if (opt_idx >= 0) |
| 2309 | did_set_option(opt_idx, opt_flags, op == OP_NONE, value_checked); |
| 2310 | |
| 2311 | skip: |
| 2312 | *argp = arg; |
| 2313 | return errmsg; |
| 2314 | } |
| 2315 | |
| 2316 | /* |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2317 | * Set an option to a new value. |
| 2318 | * Return NULL if OK, return an untranslated error message when something is |
| 2319 | * wrong. "errbuf[errbuflen]" can be used to create the error message. |
| 2320 | */ |
| 2321 | static char * |
| 2322 | do_set_option( |
| 2323 | int opt_flags, |
| 2324 | char_u **argp, |
| 2325 | char_u *arg_start, |
| 2326 | char_u **startarg, |
| 2327 | int *did_show, |
| 2328 | int *stopopteval, |
| 2329 | char *errbuf, |
| 2330 | size_t errbuflen) |
| 2331 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2332 | int opt_idx; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2333 | char_u *arg; |
| 2334 | set_prefix_T prefix; // no prefix, "no" prefix or "inv" prefix |
| 2335 | set_op_T op; |
| 2336 | long_u flags; // flags for current option |
| 2337 | char_u *varp; // pointer to variable for current option |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2338 | char_u key_name[2]; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2339 | int nextchar; // next non-white char after option name |
| 2340 | int afterchar; // character just after option name |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2341 | char *errmsg = NULL; |
| 2342 | int key; |
| 2343 | int len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2344 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2345 | prefix = get_option_prefix(argp); |
| 2346 | arg = *argp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2347 | |
| 2348 | // find end of name |
| 2349 | key = 0; |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2350 | if (parse_option_name(arg, &opt_idx, &len, &key) == FAIL) |
| 2351 | return e_invalid_argument; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2352 | |
| 2353 | // remember character after option name |
| 2354 | afterchar = arg[len]; |
| 2355 | |
| 2356 | if (in_vim9script()) |
| 2357 | { |
| 2358 | char_u *p = skipwhite(arg + len); |
| 2359 | |
| 2360 | // disallow white space before =val, +=val, -=val, ^=val |
| 2361 | if (p > arg + len && (p[0] == '=' |
| 2362 | || (vim_strchr((char_u *)"+-^", p[0]) != NULL |
| 2363 | && p[1] == '='))) |
| 2364 | { |
| 2365 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2366 | arg = p; |
| 2367 | *startarg = p; |
| 2368 | goto skip; |
| 2369 | } |
| 2370 | } |
| 2371 | else |
| 2372 | // skip white space, allow ":set ai ?", ":set hlsearch !" |
| 2373 | while (VIM_ISWHITE(arg[len])) |
| 2374 | ++len; |
| 2375 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2376 | op = get_opt_op(arg + len); |
| 2377 | if (op != OP_NONE) |
| 2378 | len++; |
| 2379 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2380 | nextchar = arg[len]; |
| 2381 | |
| 2382 | if (opt_idx == -1 && key == 0) // found a mismatch: skip |
| 2383 | { |
| 2384 | if (in_vim9script() && arg > arg_start |
| 2385 | && vim_strchr((char_u *)"!&<", *arg) != NULL) |
| 2386 | errmsg = e_no_white_space_allowed_between_option_and; |
| 2387 | else |
| 2388 | errmsg = e_unknown_option; |
| 2389 | goto skip; |
| 2390 | } |
| 2391 | |
| 2392 | if (opt_idx >= 0) |
| 2393 | { |
| 2394 | if (options[opt_idx].var == NULL) // hidden option: skip |
| 2395 | { |
| 2396 | // Only give an error message when requesting the value of |
| 2397 | // a hidden option, ignore setting it. |
| 2398 | if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL |
| 2399 | && (!(options[opt_idx].flags & P_BOOL) |
| 2400 | || nextchar == '?')) |
| 2401 | errmsg = e_option_not_supported; |
| 2402 | goto skip; |
| 2403 | } |
| 2404 | |
| 2405 | flags = options[opt_idx].flags; |
| 2406 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 2407 | } |
| 2408 | else |
| 2409 | { |
| 2410 | flags = P_STRING; |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2411 | varp = NULL; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2412 | if (key < 0) |
| 2413 | { |
| 2414 | key_name[0] = KEY2TERMCAP0(key); |
| 2415 | key_name[1] = KEY2TERMCAP1(key); |
| 2416 | } |
| 2417 | else |
| 2418 | { |
| 2419 | key_name[0] = KS_KEY; |
| 2420 | key_name[1] = (key & 0xff); |
| 2421 | } |
| 2422 | } |
| 2423 | |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2424 | // Make sure the option value can be changed. |
| 2425 | if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg) == FAIL) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2426 | goto skip; |
| 2427 | |
Bram Moolenaar | 40b4872 | 2023-02-05 17:04:50 +0000 | [diff] [blame] | 2428 | int cp_val = p_cp; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2429 | if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) |
| 2430 | { |
| 2431 | arg += len; |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2432 | if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') |
| 2433 | { |
| 2434 | if (arg[3] == 'm') // "opt&vim": set to Vim default |
| 2435 | { |
| 2436 | cp_val = FALSE; |
| 2437 | arg += 3; |
| 2438 | } |
| 2439 | else // "opt&vi": set to Vi default |
| 2440 | { |
| 2441 | cp_val = TRUE; |
| 2442 | arg += 2; |
| 2443 | } |
| 2444 | } |
| 2445 | if (vim_strchr((char_u *)"?!&<", nextchar) != NULL |
| 2446 | && arg[1] != NUL && !VIM_ISWHITE(arg[1])) |
| 2447 | { |
| 2448 | errmsg = e_trailing_characters; |
| 2449 | goto skip; |
| 2450 | } |
| 2451 | } |
| 2452 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2453 | // Allow '=' and ':' for historical reasons (MSDOS command.com). |
| 2454 | // Allows only one '=' character per "set" command line. grrr. (jw) |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2455 | if (nextchar == '?' |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2456 | || (prefix == PREFIX_NONE |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2457 | && vim_strchr((char_u *)"=:&<", nextchar) == NULL |
| 2458 | && !(flags & P_BOOL))) |
| 2459 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2460 | // print value |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2461 | if (*did_show) |
| 2462 | msg_putchar('\n'); // cursor below last one |
| 2463 | else |
| 2464 | { |
| 2465 | gotocmdline(TRUE); // cursor at status line |
| 2466 | *did_show = TRUE; // remember that we did a line |
| 2467 | } |
| 2468 | if (opt_idx >= 0) |
| 2469 | { |
| 2470 | showoneopt(&options[opt_idx], opt_flags); |
| 2471 | #ifdef FEAT_EVAL |
| 2472 | if (p_verbose > 0) |
| 2473 | { |
| 2474 | // Mention where the option was last set. |
| 2475 | if (varp == options[opt_idx].var) |
| 2476 | last_set_msg(options[opt_idx].script_ctx); |
| 2477 | else if ((int)options[opt_idx].indir & PV_WIN) |
| 2478 | last_set_msg(curwin->w_p_script_ctx[ |
| 2479 | (int)options[opt_idx].indir & PV_MASK]); |
| 2480 | else if ((int)options[opt_idx].indir & PV_BUF) |
| 2481 | last_set_msg(curbuf->b_p_script_ctx[ |
| 2482 | (int)options[opt_idx].indir & PV_MASK]); |
| 2483 | } |
| 2484 | #endif |
| 2485 | } |
| 2486 | else |
| 2487 | { |
| 2488 | char_u *p; |
| 2489 | |
| 2490 | p = find_termcode(key_name); |
| 2491 | if (p == NULL) |
| 2492 | { |
| 2493 | errmsg = e_key_code_not_set; |
| 2494 | goto skip; |
| 2495 | } |
| 2496 | else |
| 2497 | (void)show_one_termcode(key_name, p, TRUE); |
| 2498 | } |
| 2499 | if (nextchar != '?' |
| 2500 | && nextchar != NUL && !VIM_ISWHITE(afterchar)) |
| 2501 | errmsg = e_trailing_characters; |
| 2502 | } |
| 2503 | else |
| 2504 | { |
Yegappan Lakshmanan | c72078b | 2023-02-05 16:02:35 +0000 | [diff] [blame] | 2505 | errmsg = do_set_option_value(opt_idx, opt_flags, &arg, prefix, op, |
| 2506 | flags, varp, key_name, nextchar, |
| 2507 | afterchar, cp_val, stopopteval, errbuf, |
| 2508 | errbuflen); |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | skip: |
| 2512 | *argp = arg; |
| 2513 | return errmsg; |
| 2514 | } |
| 2515 | |
| 2516 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2517 | * Parse 'arg' for option settings. |
| 2518 | * |
| 2519 | * 'arg' may be IObuff, but only when no errors can be present and option |
| 2520 | * does not need to be expanded with option_expand(). |
| 2521 | * "opt_flags": |
| 2522 | * 0 for ":set" |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2523 | * OPT_GLOBAL for ":setglobal" |
| 2524 | * OPT_LOCAL for ":setlocal" and a modeline |
| 2525 | * OPT_MODELINE for a modeline |
| 2526 | * OPT_WINONLY to only set window-local options |
| 2527 | * OPT_NOWIN to skip setting window-local options |
| 2528 | * OPT_ONECOLUMN do not use multiple columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2529 | * |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2530 | * Returns FAIL if an error is detected, OK otherwise. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2531 | */ |
| 2532 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2533 | do_set( |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2534 | char_u *arg_start, // option string (may be written to!) |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2535 | int opt_flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2536 | { |
Bram Moolenaar | 1594f31 | 2021-07-08 16:40:13 +0200 | [diff] [blame] | 2537 | char_u *arg = arg_start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2538 | int i; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2539 | int did_show = FALSE; // already showed one value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2540 | |
| 2541 | if (*arg == NUL) |
| 2542 | { |
| 2543 | showoptions(0, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2544 | did_show = TRUE; |
| 2545 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2548 | while (*arg != NUL) // loop to process all options |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | { |
zeertzjq | 0ef9a5c | 2023-01-17 21:38:25 +0000 | [diff] [blame] | 2550 | if (STRNCMP(arg, "all", 3) == 0 && !ASCII_ISALPHA(arg[3]) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2551 | && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2552 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2553 | // ":set all" show all options. |
| 2554 | // ":set all&" set all options to their default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2555 | arg += 3; |
| 2556 | if (*arg == '&') |
| 2557 | { |
| 2558 | ++arg; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2559 | // Only for :set command set global value of local options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2560 | set_options_default(OPT_FREE | opt_flags); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2561 | didset_options(); |
| 2562 | didset_options2(); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 2563 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2564 | } |
| 2565 | else |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2566 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2567 | showoptions(1, opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2568 | did_show = TRUE; |
| 2569 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2570 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2571 | else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2572 | { |
| 2573 | showoptions(2, opt_flags); |
Bram Moolenaar | 15a24f0 | 2021-12-03 20:43:24 +0000 | [diff] [blame] | 2574 | show_termcodes(opt_flags); |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2575 | did_show = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2576 | arg += 7; |
| 2577 | } |
| 2578 | else |
| 2579 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2580 | int stopopteval = FALSE; |
| 2581 | char *errmsg = NULL; |
| 2582 | char errbuf[80]; |
| 2583 | char_u *startarg = arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2584 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2585 | errmsg = do_set_option(opt_flags, &arg, arg_start, &startarg, |
| 2586 | &did_show, &stopopteval, errbuf, |
| 2587 | sizeof(errbuf)); |
| 2588 | if (stopopteval) |
| 2589 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2590 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2591 | // Advance to next argument. |
| 2592 | // - skip until a blank found, taking care of backslashes |
| 2593 | // - skip blanks |
| 2594 | // - skip one "=val" argument (for hidden options ":set gfn =xx") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2595 | for (i = 0; i < 2 ; ++i) |
| 2596 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 2597 | while (*arg != NUL && !VIM_ISWHITE(*arg)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2598 | if (*arg++ == '\\' && *arg != NUL) |
| 2599 | ++arg; |
| 2600 | arg = skipwhite(arg); |
| 2601 | if (*arg != '=') |
| 2602 | break; |
| 2603 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2604 | |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2605 | if (errmsg != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2606 | { |
Yegappan Lakshmanan | 78012f5 | 2023-02-02 16:34:11 +0000 | [diff] [blame] | 2607 | vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1); |
| 2608 | i = (int)STRLEN(IObuff) + 2; |
| 2609 | if (i + (arg - startarg) < IOSIZE) |
| 2610 | { |
| 2611 | // append the argument with the error |
| 2612 | STRCAT(IObuff, ": "); |
| 2613 | mch_memmove(IObuff + i, startarg, (arg - startarg)); |
| 2614 | IObuff[i + (arg - startarg)] = NUL; |
| 2615 | } |
| 2616 | // make sure all characters are printable |
| 2617 | trans_characters(IObuff, IOSIZE); |
| 2618 | |
| 2619 | ++no_wait_return; // wait_return() done later |
| 2620 | emsg((char *)IObuff); // show error highlighted |
| 2621 | --no_wait_return; |
| 2622 | |
| 2623 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2624 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | arg = skipwhite(arg); |
| 2628 | } |
| 2629 | |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2630 | theend: |
| 2631 | if (silent_mode && did_show) |
| 2632 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2633 | // After displaying option values in silent mode. |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2634 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2635 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2636 | msg_putchar('\n'); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2637 | cursor_on(); // msg_start() switches it off |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2638 | out_flush(); |
| 2639 | silent_mode = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2640 | info_message = FALSE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2643 | return OK; |
| 2644 | } |
| 2645 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2646 | /* |
| 2647 | * Call this when an option has been given a new value through a user command. |
| 2648 | * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. |
| 2649 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2650 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2651 | did_set_option( |
| 2652 | int opt_idx, |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2653 | int opt_flags, // possibly with OPT_MODELINE |
| 2654 | int new_value, // value was replaced completely |
| 2655 | int value_checked) // value was checked to be safe, no need to set the |
| 2656 | // P_INSECURE flag. |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2657 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2658 | long_u *p; |
| 2659 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2660 | options[opt_idx].flags |= P_WAS_SET; |
| 2661 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2662 | // When an option is set in the sandbox, from a modeline or in secure mode |
| 2663 | // set the P_INSECURE flag. Otherwise, if a new value is stored reset the |
| 2664 | // flag. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2665 | p = insecure_flag(opt_idx, opt_flags); |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2666 | if (!value_checked && (secure |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2667 | #ifdef HAVE_SANDBOX |
| 2668 | || sandbox != 0 |
| 2669 | #endif |
Bram Moolenaar | 916a818 | 2018-11-25 02:18:29 +0100 | [diff] [blame] | 2670 | || (opt_flags & OPT_MODELINE))) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2671 | *p = *p | P_INSECURE; |
| 2672 | else if (new_value) |
| 2673 | *p = *p & ~P_INSECURE; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2676 | /* |
| 2677 | * Convert a key name or string into a key value. |
| 2678 | * Used for 'wildchar' and 'cedit' options. |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2679 | * When "multi_byte" is TRUE allow for multi-byte characters. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2680 | */ |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2681 | int |
| 2682 | string_to_key(char_u *arg, int multi_byte) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2683 | { |
| 2684 | if (*arg == '<') |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 2685 | return find_key_option(arg + 1, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2686 | if (*arg == '^') |
| 2687 | return Ctrl_chr(arg[1]); |
Bram Moolenaar | dbe948d | 2017-07-23 22:50:51 +0200 | [diff] [blame] | 2688 | if (multi_byte) |
| 2689 | return PTR2CHAR(arg); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2690 | return *arg; |
| 2691 | } |
| 2692 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2693 | /* |
| 2694 | * When changing 'title', 'titlestring', 'icon' or 'iconstring', call |
| 2695 | * maketitle() to create and display it. |
| 2696 | * When switching the title or icon off, call mch_restore_title() to get |
| 2697 | * the old value back. |
| 2698 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2699 | void |
Bram Moolenaar | 84a9308 | 2018-06-16 22:58:15 +0200 | [diff] [blame] | 2700 | did_set_title(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2701 | { |
| 2702 | if (starting != NO_SCREEN |
| 2703 | #ifdef FEAT_GUI |
| 2704 | && !gui.starting |
| 2705 | #endif |
| 2706 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2707 | maketitle(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2708 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2709 | |
| 2710 | /* |
| 2711 | * set_options_bin - called when 'bin' changes value. |
| 2712 | */ |
| 2713 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2714 | set_options_bin( |
| 2715 | int oldval, |
| 2716 | int newval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2717 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2718 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2719 | // The option values that are changed when 'bin' changes are |
| 2720 | // copied when 'bin is set and restored when 'bin' is reset. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2721 | if (newval) |
| 2722 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2723 | if (!oldval) // switched on |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2724 | { |
| 2725 | if (!(opt_flags & OPT_GLOBAL)) |
| 2726 | { |
| 2727 | curbuf->b_p_tw_nobin = curbuf->b_p_tw; |
| 2728 | curbuf->b_p_wm_nobin = curbuf->b_p_wm; |
| 2729 | curbuf->b_p_ml_nobin = curbuf->b_p_ml; |
| 2730 | curbuf->b_p_et_nobin = curbuf->b_p_et; |
| 2731 | } |
| 2732 | if (!(opt_flags & OPT_LOCAL)) |
| 2733 | { |
| 2734 | p_tw_nobin = p_tw; |
| 2735 | p_wm_nobin = p_wm; |
| 2736 | p_ml_nobin = p_ml; |
| 2737 | p_et_nobin = p_et; |
| 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | if (!(opt_flags & OPT_GLOBAL)) |
| 2742 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2743 | curbuf->b_p_tw = 0; // no automatic line wrap |
| 2744 | curbuf->b_p_wm = 0; // no automatic line wrap |
| 2745 | curbuf->b_p_ml = 0; // no modelines |
| 2746 | curbuf->b_p_et = 0; // no expandtab |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2747 | } |
| 2748 | if (!(opt_flags & OPT_LOCAL)) |
| 2749 | { |
| 2750 | p_tw = 0; |
| 2751 | p_wm = 0; |
| 2752 | p_ml = FALSE; |
| 2753 | p_et = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2754 | p_bin = TRUE; // needed when called for the "-b" argument |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2755 | } |
| 2756 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2757 | else if (oldval) // switched off |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2758 | { |
| 2759 | if (!(opt_flags & OPT_GLOBAL)) |
| 2760 | { |
| 2761 | curbuf->b_p_tw = curbuf->b_p_tw_nobin; |
| 2762 | curbuf->b_p_wm = curbuf->b_p_wm_nobin; |
| 2763 | curbuf->b_p_ml = curbuf->b_p_ml_nobin; |
| 2764 | curbuf->b_p_et = curbuf->b_p_et_nobin; |
| 2765 | } |
| 2766 | if (!(opt_flags & OPT_LOCAL)) |
| 2767 | { |
| 2768 | p_tw = p_tw_nobin; |
| 2769 | p_wm = p_wm_nobin; |
| 2770 | p_ml = p_ml_nobin; |
| 2771 | p_et = p_et_nobin; |
| 2772 | } |
| 2773 | } |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 2774 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2775 | // Remember where the dependent option were reset |
| 2776 | didset_options_sctx(opt_flags, p_bin_dep_opts); |
| 2777 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2780 | /* |
| 2781 | * Expand environment variables for some string options. |
| 2782 | * These string options cannot be indirect! |
| 2783 | * If "val" is NULL expand the current value of the option. |
| 2784 | * Return pointer to NameBuff, or NULL when not expanded. |
| 2785 | */ |
| 2786 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2787 | option_expand(int opt_idx, char_u *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2788 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2789 | // if option doesn't need expansion nothing to do |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2790 | if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) |
| 2791 | return NULL; |
| 2792 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2793 | // If val is longer than MAXPATHL no meaningful expansion can be done, |
| 2794 | // expand_env() would truncate the string. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2795 | if (val != NULL && STRLEN(val) > MAXPATHL) |
| 2796 | return NULL; |
| 2797 | |
| 2798 | if (val == NULL) |
| 2799 | val = *(char_u **)options[opt_idx].var; |
| 2800 | |
| 2801 | /* |
| 2802 | * Expanding this with NameBuff, expand_env() must not be passed IObuff. |
| 2803 | * Escape spaces when expanding 'tags', they are used to separate file |
| 2804 | * names. |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2805 | * For 'spellsuggest' expand after "file:". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2806 | */ |
| 2807 | expand_env_esc(val, NameBuff, MAXPATHL, |
Bram Moolenaar | 9f0545d | 2007-09-26 20:36:32 +0000 | [diff] [blame] | 2808 | (char_u **)options[opt_idx].var == &p_tags, FALSE, |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2809 | #ifdef FEAT_SPELL |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2810 | (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : |
| 2811 | #endif |
| 2812 | NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2813 | if (STRCMP(NameBuff, val) == 0) // they are the same |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2814 | return NULL; |
| 2815 | |
| 2816 | return NameBuff; |
| 2817 | } |
| 2818 | |
| 2819 | /* |
| 2820 | * After setting various option values: recompute variables that depend on |
| 2821 | * option values. |
| 2822 | */ |
| 2823 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2824 | didset_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2825 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2826 | // initialize the table for 'iskeyword' et.al. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2827 | (void)init_chartab(); |
| 2828 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2829 | didset_string_options(); |
| 2830 | |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 2831 | #ifdef FEAT_SPELL |
Bram Moolenaar | 8aff23a | 2005-08-19 20:40:30 +0000 | [diff] [blame] | 2832 | (void)spell_check_msm(); |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 2833 | (void)spell_check_sps(); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2834 | (void)compile_cap_prog(curwin->w_s); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2835 | (void)did_set_spell_option(TRUE); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 2836 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2837 | // set cedit_key |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2838 | (void)did_set_cedit(NULL); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 2839 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2840 | // initialize the table for 'breakat'. |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2841 | did_set_breakat(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2842 | #endif |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 2843 | after_copy_winopt(curwin); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /* |
| 2847 | * More side effects of setting options. |
| 2848 | */ |
| 2849 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2850 | didset_options2(void) |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2851 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2852 | // Initialize the highlight_attr[] table. |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2853 | (void)highlight_changed(); |
| 2854 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2855 | // Parse default for 'wildmode' |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2856 | check_opt_wim(); |
| 2857 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2858 | // Parse default for 'listchars'. |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2859 | (void)set_listchars_option(curwin, curwin->w_p_lcs, TRUE); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2860 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2861 | // Parse default for 'fillchars'. |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 2862 | (void)set_fillchars_option(curwin, curwin->w_p_fcs, TRUE); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2863 | |
| 2864 | #ifdef FEAT_CLIPBOARD |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2865 | // Parse default for 'clipboard' |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 2866 | (void)did_set_clipboard(NULL); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 2867 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2868 | #ifdef FEAT_VARTABS |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2869 | vim_free(curbuf->b_p_vsts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2870 | (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); |
Bram Moolenaar | 55c77cf | 2019-02-16 19:05:11 +0100 | [diff] [blame] | 2871 | vim_free(curbuf->b_p_vts_array); |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2872 | (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 2873 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | /* |
| 2877 | * Check for string options that are NULL (normally only termcap options). |
| 2878 | */ |
| 2879 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2880 | check_options(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2881 | { |
| 2882 | int opt_idx; |
| 2883 | |
| 2884 | for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) |
| 2885 | if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) |
| 2886 | check_string_option((char_u **)get_varp(&(options[opt_idx]))); |
| 2887 | } |
| 2888 | |
| 2889 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2890 | * Return the option index found by a pointer into term_strings[]. |
| 2891 | * Return -1 if not found. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2892 | */ |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2893 | int |
| 2894 | get_term_opt_idx(char_u **p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2895 | { |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2896 | int opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2897 | |
| 2898 | for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) |
| 2899 | if (options[opt_idx].var == (char_u *)p) |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 2900 | return opt_idx; |
| 2901 | return -1; // cannot happen: didn't find it! |
| 2902 | } |
| 2903 | |
| 2904 | /* |
| 2905 | * Mark a terminal option as allocated, found by a pointer into term_strings[]. |
| 2906 | * Return the option index or -1 if not found. |
| 2907 | */ |
| 2908 | int |
| 2909 | set_term_option_alloced(char_u **p) |
| 2910 | { |
| 2911 | int opt_idx = get_term_opt_idx(p); |
| 2912 | |
| 2913 | if (opt_idx >= 0) |
| 2914 | options[opt_idx].flags |= P_ALLOCED; |
| 2915 | return opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2918 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 2919 | /* |
| 2920 | * Return TRUE when option "opt" was set from a modeline or in secure mode. |
| 2921 | * Return FALSE when it wasn't. |
| 2922 | * Return -1 for an unknown option. |
| 2923 | */ |
| 2924 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2925 | was_set_insecurely(char_u *opt, int opt_flags) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2926 | { |
| 2927 | int idx = findoption(opt); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2928 | long_u *flagp; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2929 | |
| 2930 | if (idx >= 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2931 | { |
| 2932 | flagp = insecure_flag(idx, opt_flags); |
| 2933 | return (*flagp & P_INSECURE) != 0; |
| 2934 | } |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 2935 | internal_error("was_set_insecurely()"); |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2936 | return -1; |
| 2937 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2938 | |
| 2939 | /* |
| 2940 | * Get a pointer to the flags used for the P_INSECURE flag of option |
| 2941 | * "opt_idx". For some local options a local flags field is used. |
Bram Moolenaar | d5e8c92 | 2021-02-02 21:10:01 +0100 | [diff] [blame] | 2942 | * NOTE: Caller must make sure that "curwin" is set to the window from which |
| 2943 | * the option is used. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2944 | */ |
| 2945 | static long_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 2946 | insecure_flag(int opt_idx, int opt_flags) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2947 | { |
| 2948 | if (opt_flags & OPT_LOCAL) |
| 2949 | switch ((int)options[opt_idx].indir) |
| 2950 | { |
| 2951 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2952 | case PV_STL: return &curwin->w_p_stl_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2953 | #endif |
| 2954 | #ifdef FEAT_EVAL |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2955 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2956 | case PV_FDE: return &curwin->w_p_fde_flags; |
| 2957 | case PV_FDT: return &curwin->w_p_fdt_flags; |
Bram Moolenaar | 2e97890 | 2006-05-13 12:37:50 +0000 | [diff] [blame] | 2958 | # endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 2959 | # ifdef FEAT_BEVAL |
| 2960 | case PV_BEXPR: return &curbuf->b_p_bexpr_flags; |
| 2961 | # endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2962 | case PV_INDE: return &curbuf->b_p_inde_flags; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2963 | case PV_FEX: return &curbuf->b_p_fex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2964 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 2965 | case PV_INEX: return &curbuf->b_p_inex_flags; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2966 | # endif |
| 2967 | #endif |
| 2968 | } |
| 2969 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 2970 | // Nothing special, return global flags field. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 2971 | return &options[opt_idx].flags; |
| 2972 | } |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 2973 | #endif |
| 2974 | |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2975 | /* |
| 2976 | * Redraw the window title and/or tab page text later. |
| 2977 | */ |
Yegappan Lakshmanan | eb91e24 | 2023-08-31 18:10:46 +0200 | [diff] [blame] | 2978 | void |
| 2979 | redraw_titles(void) |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2980 | { |
| 2981 | need_maketitle = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2982 | redraw_tabline = TRUE; |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2983 | } |
Bram Moolenaar | 1f26d2f | 2009-02-11 10:35:36 +0000 | [diff] [blame] | 2984 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2985 | /* |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2986 | * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII |
| 2987 | * characters or characters in "allowed". |
| 2988 | */ |
Bram Moolenaar | e677df8 | 2019-09-02 22:31:11 +0200 | [diff] [blame] | 2989 | int |
Bram Moolenaar | 8f130ed | 2019-04-10 22:15:19 +0200 | [diff] [blame] | 2990 | valid_name(char_u *val, char *allowed) |
| 2991 | { |
| 2992 | char_u *s; |
| 2993 | |
| 2994 | for (s = val; *s != NUL; ++s) |
| 2995 | if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL) |
| 2996 | return FALSE; |
| 2997 | return TRUE; |
| 2998 | } |
| 2999 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3000 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 3001 | /* |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3002 | * 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] | 3003 | * window-local value. |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3004 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 3005 | void |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3006 | 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] | 3007 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3008 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 3009 | int indir = (int)options[opt_idx].indir; |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3010 | sctx_T new_script_ctx = script_ctx; |
| 3011 | |
Bram Moolenaar | 5125874 | 2020-05-03 17:19:33 +0200 | [diff] [blame] | 3012 | // Modeline already has the line number set. |
| 3013 | if (!(opt_flags & OPT_MODELINE)) |
| 3014 | new_script_ctx.sc_lnum += SOURCING_LNUM; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3015 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 3016 | // Remember where the option was set. For local options need to do that |
| 3017 | // in the buffer or window structure. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3018 | if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3019 | options[opt_idx].script_ctx = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3020 | if (both || (opt_flags & OPT_LOCAL)) |
| 3021 | { |
| 3022 | if (indir & PV_BUF) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3023 | curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3024 | else if (indir & PV_WIN) |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3025 | { |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 3026 | curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx; |
Bram Moolenaar | e70dd11 | 2022-01-21 16:31:11 +0000 | [diff] [blame] | 3027 | if (both) |
| 3028 | // also setting the "all buffers" value |
| 3029 | curwin->w_allbuf_opt.wo_script_ctx[indir & PV_MASK] = |
| 3030 | new_script_ctx; |
| 3031 | } |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 3032 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3033 | } |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3034 | |
| 3035 | /* |
Bram Moolenaar | 5600a70 | 2022-01-22 15:09:36 +0000 | [diff] [blame] | 3036 | * Get the script context of global option "name". |
| 3037 | * |
| 3038 | */ |
| 3039 | sctx_T * |
| 3040 | get_option_sctx(char *name) |
| 3041 | { |
| 3042 | int idx = findoption((char_u *)name); |
| 3043 | |
| 3044 | if (idx >= 0) |
| 3045 | return &options[idx].script_ctx; |
| 3046 | siemsg("no such option: %s", name); |
| 3047 | return NULL; |
| 3048 | } |
| 3049 | |
| 3050 | /* |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 3051 | * Set the script_ctx for a termcap option. |
| 3052 | * "name" must be the two character code, e.g. "RV". |
| 3053 | * When "name" is NULL use "opt_idx". |
| 3054 | */ |
| 3055 | void |
| 3056 | set_term_option_sctx_idx(char *name, int opt_idx) |
| 3057 | { |
| 3058 | char_u buf[5]; |
| 3059 | int idx; |
| 3060 | |
| 3061 | if (name == NULL) |
| 3062 | idx = opt_idx; |
| 3063 | else |
| 3064 | { |
| 3065 | buf[0] = 't'; |
| 3066 | buf[1] = '_'; |
| 3067 | buf[2] = name[0]; |
| 3068 | buf[3] = name[1]; |
| 3069 | buf[4] = 0; |
| 3070 | idx = findoption(buf); |
| 3071 | } |
| 3072 | if (idx >= 0) |
| 3073 | set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx); |
| 3074 | } |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 3075 | #endif |
| 3076 | |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 3077 | #if defined(FEAT_EVAL) |
| 3078 | /* |
| 3079 | * Apply the OptionSet autocommand. |
| 3080 | */ |
| 3081 | static void |
| 3082 | apply_optionset_autocmd( |
| 3083 | int opt_idx, |
| 3084 | long opt_flags, |
| 3085 | long oldval, |
| 3086 | long oldval_g, |
| 3087 | long newval, |
| 3088 | char *errmsg) |
| 3089 | { |
| 3090 | char_u buf_old[12], buf_old_global[12], buf_new[12], buf_type[12]; |
| 3091 | |
| 3092 | // Don't do this while starting up, failure or recursively. |
| 3093 | if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL) |
| 3094 | return; |
| 3095 | |
| 3096 | vim_snprintf((char *)buf_old, sizeof(buf_old), "%ld", oldval); |
| 3097 | vim_snprintf((char *)buf_old_global, sizeof(buf_old_global), "%ld", |
| 3098 | oldval_g); |
| 3099 | vim_snprintf((char *)buf_new, sizeof(buf_new), "%ld", newval); |
| 3100 | vim_snprintf((char *)buf_type, sizeof(buf_type), "%s", |
| 3101 | (opt_flags & OPT_LOCAL) ? "local" : "global"); |
| 3102 | set_vim_var_string(VV_OPTION_NEW, buf_new, -1); |
| 3103 | set_vim_var_string(VV_OPTION_OLD, buf_old, -1); |
| 3104 | set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
| 3105 | if (opt_flags & OPT_LOCAL) |
| 3106 | { |
| 3107 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
| 3108 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3109 | } |
| 3110 | if (opt_flags & OPT_GLOBAL) |
| 3111 | { |
| 3112 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
| 3113 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); |
| 3114 | } |
| 3115 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 3116 | { |
| 3117 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
| 3118 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3119 | set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); |
| 3120 | } |
| 3121 | if (opt_flags & OPT_MODELINE) |
| 3122 | { |
| 3123 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
| 3124 | set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); |
| 3125 | } |
| 3126 | apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, |
| 3127 | NULL, FALSE, NULL); |
| 3128 | reset_v_option_vars(); |
| 3129 | } |
| 3130 | #endif |
| 3131 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3132 | #if defined(FEAT_ARABIC) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3133 | /* |
| 3134 | * Process the updated 'arabic' option value. |
| 3135 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3136 | char * |
| 3137 | did_set_arabic(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3138 | { |
| 3139 | char *errmsg = NULL; |
| 3140 | |
| 3141 | if (curwin->w_p_arab) |
| 3142 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 3143 | // 'arabic' is set, handle various sub-settings. |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3144 | if (!p_tbidi) |
| 3145 | { |
| 3146 | // set rightleft mode |
| 3147 | if (!curwin->w_p_rl) |
| 3148 | { |
| 3149 | curwin->w_p_rl = TRUE; |
| 3150 | changed_window_setting(); |
| 3151 | } |
| 3152 | |
| 3153 | // Enable Arabic shaping (major part of what Arabic requires) |
| 3154 | if (!p_arshape) |
| 3155 | { |
| 3156 | p_arshape = TRUE; |
| 3157 | redraw_later_clear(); |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | // Arabic requires a utf-8 encoding, inform the user if it's not |
| 3162 | // set. |
| 3163 | if (STRCMP(p_enc, "utf-8") != 0) |
| 3164 | { |
| 3165 | static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); |
| 3166 | |
| 3167 | msg_source(HL_ATTR(HLF_W)); |
| 3168 | msg_attr(_(w_arabic), HL_ATTR(HLF_W)); |
| 3169 | #ifdef FEAT_EVAL |
| 3170 | set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); |
| 3171 | #endif |
| 3172 | } |
| 3173 | |
| 3174 | // set 'delcombine' |
| 3175 | p_deco = TRUE; |
| 3176 | |
| 3177 | # ifdef FEAT_KEYMAP |
| 3178 | // Force-set the necessary keymap for arabic |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3179 | errmsg = set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", |
| 3180 | OPT_LOCAL); |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3181 | # endif |
| 3182 | } |
| 3183 | else |
| 3184 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 3185 | // 'arabic' is reset, handle various sub-settings. |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3186 | if (!p_tbidi) |
| 3187 | { |
| 3188 | // reset rightleft mode |
| 3189 | if (curwin->w_p_rl) |
| 3190 | { |
| 3191 | curwin->w_p_rl = FALSE; |
| 3192 | changed_window_setting(); |
| 3193 | } |
| 3194 | |
| 3195 | // 'arabicshape' isn't reset, it is a global option and |
| 3196 | // another window may still need it "on". |
| 3197 | } |
| 3198 | |
| 3199 | // 'delcombine' isn't reset, it is a global option and another |
| 3200 | // window may still want it "on". |
| 3201 | |
| 3202 | # ifdef FEAT_KEYMAP |
| 3203 | // Revert to the default keymap |
| 3204 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3205 | curbuf->b_p_imsearch = B_IMODE_USE_INSERT; |
| 3206 | # endif |
| 3207 | } |
| 3208 | |
| 3209 | return errmsg; |
| 3210 | } |
| 3211 | #endif |
| 3212 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3213 | #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
| 3214 | /* |
| 3215 | * Process the updated 'autochdir' option value. |
| 3216 | */ |
| 3217 | char * |
| 3218 | did_set_autochdir(optset_T *args UNUSED) |
| 3219 | { |
| 3220 | // Change directories when the 'acd' option is set now. |
| 3221 | DO_AUTOCHDIR; |
| 3222 | return NULL; |
| 3223 | } |
| 3224 | #endif |
| 3225 | |
| 3226 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
| 3227 | /* |
| 3228 | * Process the updated 'ballooneval' option value. |
| 3229 | */ |
| 3230 | char * |
| 3231 | did_set_ballooneval(optset_T *args) |
| 3232 | { |
| 3233 | if (balloonEvalForTerm) |
| 3234 | return NULL; |
| 3235 | |
| 3236 | if (p_beval && !args->os_oldval.boolean) |
| 3237 | gui_mch_enable_beval_area(balloonEval); |
| 3238 | else if (!p_beval && args->os_oldval.boolean) |
| 3239 | gui_mch_disable_beval_area(balloonEval); |
| 3240 | |
| 3241 | return NULL; |
| 3242 | } |
| 3243 | #endif |
| 3244 | |
| 3245 | #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
| 3246 | /* |
| 3247 | * Process the updated 'balloonevalterm' option value. |
| 3248 | */ |
| 3249 | char * |
| 3250 | did_set_balloonevalterm(optset_T *args UNUSED) |
| 3251 | { |
| 3252 | mch_bevalterm_changed(); |
| 3253 | return NULL; |
| 3254 | } |
| 3255 | #endif |
| 3256 | |
| 3257 | /* |
| 3258 | * Process the updated 'binary' option value. |
| 3259 | */ |
| 3260 | char * |
| 3261 | did_set_binary(optset_T *args) |
| 3262 | { |
| 3263 | // when 'bin' is set also set some other options |
| 3264 | set_options_bin(args->os_oldval.boolean, curbuf->b_p_bin, args->os_flags); |
| 3265 | redraw_titles(); |
| 3266 | |
| 3267 | return NULL; |
| 3268 | } |
| 3269 | |
| 3270 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 3271 | /* |
| 3272 | * Called when the 'breakat' option changes value. |
| 3273 | */ |
| 3274 | char * |
| 3275 | did_set_breakat(optset_T *args UNUSED) |
| 3276 | { |
| 3277 | char_u *p; |
| 3278 | int i; |
| 3279 | |
| 3280 | for (i = 0; i < 256; i++) |
| 3281 | breakat_flags[i] = FALSE; |
| 3282 | |
| 3283 | if (p_breakat != NULL) |
| 3284 | for (p = p_breakat; *p; p++) |
| 3285 | breakat_flags[*p] = TRUE; |
| 3286 | |
| 3287 | return NULL; |
| 3288 | } |
| 3289 | #endif |
| 3290 | |
| 3291 | /* |
| 3292 | * Process the updated 'buflisted' option value. |
| 3293 | */ |
| 3294 | char * |
| 3295 | did_set_buflisted(optset_T *args) |
| 3296 | { |
| 3297 | // when 'buflisted' changes, trigger autocommands |
| 3298 | if (args->os_oldval.boolean != curbuf->b_p_bl) |
| 3299 | apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, |
| 3300 | NULL, NULL, TRUE, curbuf); |
| 3301 | return NULL; |
| 3302 | } |
| 3303 | |
| 3304 | /* |
| 3305 | * Process the new 'cmdheight' option value. |
| 3306 | */ |
| 3307 | char * |
| 3308 | did_set_cmdheight(optset_T *args) |
| 3309 | { |
| 3310 | long old_value = args->os_oldval.number; |
| 3311 | char *errmsg = NULL; |
| 3312 | |
| 3313 | // if p_ch changed value, change the command line height |
| 3314 | if (p_ch < 1) |
| 3315 | { |
| 3316 | errmsg = e_argument_must_be_positive; |
| 3317 | p_ch = 1; |
| 3318 | } |
| 3319 | if (p_ch > Rows - min_rows() + 1) |
| 3320 | p_ch = Rows - min_rows() + 1; |
| 3321 | |
| 3322 | // Only compute the new window layout when startup has been |
| 3323 | // completed. Otherwise the frame sizes may be wrong. |
| 3324 | if ((p_ch != old_value |
| 3325 | || tabline_height() + topframe->fr_height != Rows - p_ch) |
| 3326 | && full_screen |
| 3327 | #ifdef FEAT_GUI |
| 3328 | && !gui.starting |
| 3329 | #endif |
| 3330 | ) |
| 3331 | command_height(); |
| 3332 | |
| 3333 | return errmsg; |
| 3334 | } |
| 3335 | |
| 3336 | /* |
| 3337 | * Process the updated 'compatible' option value. |
| 3338 | */ |
| 3339 | char * |
| 3340 | did_set_compatible(optset_T *args UNUSED) |
| 3341 | { |
| 3342 | compatible_set(); |
| 3343 | return NULL; |
| 3344 | } |
| 3345 | |
| 3346 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
| 3347 | /* |
| 3348 | * Process the new 'conceallevel' option value. |
| 3349 | */ |
| 3350 | char * |
| 3351 | did_set_conceallevel(optset_T *args UNUSED) |
| 3352 | { |
| 3353 | char *errmsg = NULL; |
| 3354 | |
| 3355 | if (curwin->w_p_cole < 0) |
| 3356 | { |
| 3357 | errmsg = e_argument_must_be_positive; |
| 3358 | curwin->w_p_cole = 0; |
| 3359 | } |
| 3360 | else if (curwin->w_p_cole > 3) |
| 3361 | { |
| 3362 | errmsg = e_invalid_argument; |
| 3363 | curwin->w_p_cole = 3; |
| 3364 | } |
| 3365 | |
| 3366 | return errmsg; |
| 3367 | } |
| 3368 | #endif |
| 3369 | |
| 3370 | #if defined(FEAT_DIFF) || defined(PROTO) |
| 3371 | /* |
| 3372 | * Process the updated 'diff' option value. |
| 3373 | */ |
| 3374 | char * |
| 3375 | did_set_diff(optset_T *args UNUSED) |
| 3376 | { |
| 3377 | // May add or remove the buffer from the list of diff buffers. |
| 3378 | diff_buf_adjust(curwin); |
| 3379 | # ifdef FEAT_FOLDING |
| 3380 | if (foldmethodIsDiff(curwin)) |
| 3381 | foldUpdateAll(curwin); |
| 3382 | # endif |
| 3383 | return NULL; |
| 3384 | } |
| 3385 | #endif |
| 3386 | |
| 3387 | /* |
| 3388 | * Process the updated 'endoffile' or 'endofline' or 'fixendofline' or 'bomb' |
| 3389 | * option value. |
| 3390 | */ |
| 3391 | char * |
| 3392 | did_set_eof_eol_fixeol_bomb(optset_T *args UNUSED) |
| 3393 | { |
| 3394 | // redraw the window title and tab page text |
| 3395 | redraw_titles(); |
| 3396 | return NULL; |
| 3397 | } |
| 3398 | |
| 3399 | /* |
| 3400 | * Process the updated 'equalalways' option value. |
| 3401 | */ |
| 3402 | char * |
| 3403 | did_set_equalalways(optset_T *args) |
| 3404 | { |
| 3405 | if (p_ea && !args->os_oldval.boolean) |
| 3406 | win_equal(curwin, FALSE, 0); |
| 3407 | |
| 3408 | return NULL; |
| 3409 | } |
| 3410 | |
| 3411 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 3412 | /* |
| 3413 | * Process the new 'foldcolumn' option value. |
| 3414 | */ |
| 3415 | char * |
| 3416 | did_set_foldcolumn(optset_T *args UNUSED) |
| 3417 | { |
| 3418 | char *errmsg = NULL; |
| 3419 | |
| 3420 | if (curwin->w_p_fdc < 0) |
| 3421 | { |
| 3422 | errmsg = e_argument_must_be_positive; |
| 3423 | curwin->w_p_fdc = 0; |
| 3424 | } |
| 3425 | else if (curwin->w_p_fdc > 12) |
| 3426 | { |
| 3427 | errmsg = e_invalid_argument; |
| 3428 | curwin->w_p_fdc = 12; |
| 3429 | } |
| 3430 | |
| 3431 | return errmsg; |
| 3432 | } |
| 3433 | |
| 3434 | /* |
| 3435 | * Process the new 'foldlevel' option value. |
| 3436 | */ |
| 3437 | char * |
| 3438 | did_set_foldlevel(optset_T *args UNUSED) |
| 3439 | { |
| 3440 | if (curwin->w_p_fdl < 0) |
| 3441 | curwin->w_p_fdl = 0; |
| 3442 | newFoldLevel(); |
| 3443 | return NULL; |
| 3444 | } |
| 3445 | |
| 3446 | /* |
| 3447 | * Process the new 'foldminlines' option value. |
| 3448 | */ |
| 3449 | char * |
| 3450 | did_set_foldminlines(optset_T *args UNUSED) |
| 3451 | { |
| 3452 | foldUpdateAll(curwin); |
| 3453 | return NULL; |
| 3454 | } |
| 3455 | |
| 3456 | /* |
| 3457 | * Process the new 'foldnestmax' option value. |
| 3458 | */ |
| 3459 | char * |
| 3460 | did_set_foldnestmax(optset_T *args UNUSED) |
| 3461 | { |
| 3462 | if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) |
| 3463 | foldUpdateAll(curwin); |
| 3464 | return NULL; |
| 3465 | } |
| 3466 | #endif |
| 3467 | |
| 3468 | #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) |
| 3469 | /* |
| 3470 | * Process the updated 'hlsearch' option value. |
| 3471 | */ |
| 3472 | char * |
| 3473 | did_set_hlsearch(optset_T *args UNUSED) |
| 3474 | { |
| 3475 | // when 'hlsearch' is set or reset: reset no_hlsearch |
| 3476 | set_no_hlsearch(FALSE); |
| 3477 | return NULL; |
| 3478 | } |
| 3479 | #endif |
| 3480 | |
| 3481 | /* |
| 3482 | * Process the updated 'ignorecase' option value. |
| 3483 | */ |
| 3484 | char * |
| 3485 | did_set_ignorecase(optset_T *args UNUSED) |
| 3486 | { |
| 3487 | // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw |
| 3488 | if (p_hls) |
| 3489 | redraw_all_later(UPD_SOME_VALID); |
| 3490 | return NULL; |
| 3491 | } |
| 3492 | |
| 3493 | #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
| 3494 | /* |
| 3495 | * Process the updated 'imdisable' option value. |
| 3496 | */ |
| 3497 | char * |
| 3498 | did_set_imdisable(optset_T *args UNUSED) |
| 3499 | { |
| 3500 | // Only de-activate it here, it will be enabled when changing mode. |
| 3501 | if (p_imdisable) |
| 3502 | im_set_active(FALSE); |
| 3503 | else if (State & MODE_INSERT) |
| 3504 | // When the option is set from an autocommand, it may need to take |
| 3505 | // effect right away. |
| 3506 | im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); |
| 3507 | return NULL; |
| 3508 | } |
| 3509 | #endif |
| 3510 | |
| 3511 | /* |
| 3512 | * Process the new 'iminsert' option value. |
| 3513 | */ |
| 3514 | char * |
| 3515 | did_set_iminsert(optset_T *args UNUSED) |
| 3516 | { |
| 3517 | char *errmsg = NULL; |
| 3518 | |
| 3519 | if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) |
| 3520 | { |
| 3521 | errmsg = e_invalid_argument; |
| 3522 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 3523 | } |
| 3524 | p_iminsert = curbuf->b_p_iminsert; |
| 3525 | if (termcap_active) // don't do this in the alternate screen |
| 3526 | showmode(); |
| 3527 | #if defined(FEAT_KEYMAP) |
| 3528 | // Show/unshow value of 'keymap' in status lines. |
| 3529 | status_redraw_curbuf(); |
| 3530 | #endif |
| 3531 | |
| 3532 | return errmsg; |
| 3533 | } |
| 3534 | |
| 3535 | /* |
| 3536 | * Process the new 'imsearch' option value. |
| 3537 | */ |
| 3538 | char * |
| 3539 | did_set_imsearch(optset_T *args UNUSED) |
| 3540 | { |
| 3541 | char *errmsg = NULL; |
| 3542 | |
| 3543 | if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) |
| 3544 | { |
| 3545 | errmsg = e_invalid_argument; |
| 3546 | curbuf->b_p_imsearch = B_IMODE_NONE; |
| 3547 | } |
| 3548 | p_imsearch = curbuf->b_p_imsearch; |
| 3549 | |
| 3550 | return errmsg; |
| 3551 | } |
| 3552 | |
| 3553 | #if (defined(FEAT_XIM) && defined(FEAT_GUI_GTK)) || defined(PROTO) |
| 3554 | /* |
| 3555 | * Process the new 'imstyle' option value. |
| 3556 | */ |
| 3557 | char * |
| 3558 | did_set_imstyle(optset_T *args UNUSED) |
| 3559 | { |
| 3560 | char *errmsg = NULL; |
| 3561 | |
| 3562 | if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) |
| 3563 | errmsg = e_invalid_argument; |
| 3564 | |
| 3565 | return errmsg; |
| 3566 | } |
| 3567 | #endif |
| 3568 | |
| 3569 | /* |
| 3570 | * Process the updated 'insertmode' option value. |
| 3571 | */ |
| 3572 | char * |
| 3573 | did_set_insertmode(optset_T *args) |
| 3574 | { |
| 3575 | // when 'insertmode' is set from an autocommand need to do work here |
| 3576 | if (p_im) |
| 3577 | { |
| 3578 | if ((State & MODE_INSERT) == 0) |
| 3579 | need_start_insertmode = TRUE; |
| 3580 | stop_insert_mode = FALSE; |
| 3581 | } |
| 3582 | // only reset if it was set previously |
| 3583 | else if (args->os_oldval.boolean) |
| 3584 | { |
| 3585 | need_start_insertmode = FALSE; |
| 3586 | stop_insert_mode = TRUE; |
| 3587 | if (restart_edit != 0 && mode_displayed) |
| 3588 | clear_cmdline = TRUE; // remove "(insert)" |
| 3589 | restart_edit = 0; |
| 3590 | } |
| 3591 | |
| 3592 | return NULL; |
| 3593 | } |
| 3594 | |
| 3595 | #if defined(FEAT_LANGMAP) || defined(PROTO) |
| 3596 | /* |
| 3597 | * Process the updated 'langnoremap' option value. |
| 3598 | */ |
| 3599 | char * |
| 3600 | did_set_langnoremap(optset_T *args UNUSED) |
| 3601 | { |
| 3602 | // 'langnoremap' -> !'langremap' |
| 3603 | p_lrm = !p_lnr; |
| 3604 | return NULL; |
| 3605 | } |
| 3606 | |
| 3607 | /* |
| 3608 | * Process the updated 'langremap' option value. |
| 3609 | */ |
| 3610 | char * |
| 3611 | did_set_langremap(optset_T *args UNUSED) |
| 3612 | { |
| 3613 | // 'langremap' -> !'langnoremap' |
| 3614 | p_lnr = !p_lrm; |
| 3615 | return NULL; |
| 3616 | } |
| 3617 | #endif |
| 3618 | |
| 3619 | /* |
| 3620 | * Process the new 'laststatus' option value. |
| 3621 | */ |
| 3622 | char * |
| 3623 | did_set_laststatus(optset_T *args UNUSED) |
| 3624 | { |
| 3625 | last_status(FALSE); // (re)set last window status line |
| 3626 | return NULL; |
| 3627 | } |
| 3628 | |
| 3629 | #if defined(FEAT_GUI) || defined(PROTO) |
| 3630 | /* |
| 3631 | * Process the new 'linespace' option value. |
| 3632 | */ |
| 3633 | char * |
| 3634 | did_set_linespace(optset_T *args UNUSED) |
| 3635 | { |
| 3636 | // Recompute gui.char_height and resize the Vim window to keep the |
| 3637 | // same number of lines. |
| 3638 | if (gui.in_use && gui_mch_adjust_charheight() == OK) |
| 3639 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
| 3640 | return NULL; |
| 3641 | } |
| 3642 | #endif |
| 3643 | |
| 3644 | /* |
| 3645 | * Process the updated 'lisp' option value. |
| 3646 | */ |
| 3647 | char * |
| 3648 | did_set_lisp(optset_T *args UNUSED) |
| 3649 | { |
| 3650 | // When 'lisp' option changes include/exclude '-' in keyword characters. |
| 3651 | (void)buf_init_chartab(curbuf, FALSE); // ignore errors |
| 3652 | return NULL; |
| 3653 | } |
| 3654 | |
| 3655 | /* |
| 3656 | * Process the new 'maxcombine' option value. |
| 3657 | */ |
| 3658 | char * |
| 3659 | did_set_maxcombine(optset_T *args UNUSED) |
| 3660 | { |
| 3661 | if (p_mco > MAX_MCO) |
| 3662 | p_mco = MAX_MCO; |
| 3663 | else if (p_mco < 0) |
| 3664 | p_mco = 0; |
| 3665 | screenclear(); // will re-allocate the screen |
| 3666 | return NULL; |
| 3667 | } |
| 3668 | |
| 3669 | /* |
| 3670 | * Process the updated 'modifiable' option value. |
| 3671 | */ |
| 3672 | char * |
| 3673 | did_set_modifiable(optset_T *args UNUSED) |
| 3674 | { |
| 3675 | // when 'modifiable' is changed, redraw the window title |
| 3676 | |
| 3677 | # ifdef FEAT_TERMINAL |
| 3678 | // Cannot set 'modifiable' when in Terminal mode. |
| 3679 | if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) |
| 3680 | && curbuf->b_term != NULL && !term_is_finished(curbuf)))) |
| 3681 | { |
| 3682 | curbuf->b_p_ma = FALSE; |
| 3683 | args->os_doskip = TRUE; |
| 3684 | return e_cannot_make_terminal_with_running_job_modifiable; |
| 3685 | } |
| 3686 | # endif |
| 3687 | redraw_titles(); |
| 3688 | |
| 3689 | return NULL; |
| 3690 | } |
| 3691 | |
| 3692 | /* |
| 3693 | * Process the updated 'modified' option value. |
| 3694 | */ |
| 3695 | char * |
| 3696 | did_set_modified(optset_T *args) |
| 3697 | { |
| 3698 | if (!args->os_newval.boolean) |
| 3699 | save_file_ff(curbuf); // Buffer is unchanged |
| 3700 | redraw_titles(); |
| 3701 | modified_was_set = args->os_newval.boolean; |
| 3702 | return NULL; |
| 3703 | } |
| 3704 | |
| 3705 | #if defined(FEAT_GUI) || defined(PROTO) |
| 3706 | /* |
| 3707 | * Process the updated 'mousehide' option value. |
| 3708 | */ |
| 3709 | char * |
| 3710 | did_set_mousehide(optset_T *args UNUSED) |
| 3711 | { |
| 3712 | if (!p_mh) |
| 3713 | gui_mch_mousehide(FALSE); |
| 3714 | return NULL; |
| 3715 | } |
| 3716 | #endif |
| 3717 | |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3718 | /* |
| 3719 | * Process the updated 'number' or 'relativenumber' option value. |
| 3720 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3721 | char * |
| 3722 | did_set_number_relativenumber(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3723 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3724 | #if (defined(FEAT_SIGNS) && defined(FEAT_GUI)) || defined(PROTO) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3725 | if (gui.in_use |
| 3726 | && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u') |
| 3727 | && curbuf->b_signlist != NULL) |
| 3728 | { |
| 3729 | // If the 'number' or 'relativenumber' options are modified and |
| 3730 | // 'signcolumn' is set to 'number', then clear the screen for a full |
| 3731 | // refresh. Otherwise the sign icons are not displayed properly in the |
| 3732 | // number column. If the 'number' option is set and only the |
| 3733 | // 'relativenumber' option is toggled, then don't refresh the screen |
| 3734 | // (optimization). |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3735 | 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] | 3736 | redraw_all_later(UPD_CLEAR); |
| 3737 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3738 | #endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 3739 | return NULL; |
| 3740 | } |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 3741 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3742 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 3743 | /* |
| 3744 | * Process the new 'numberwidth' option value. |
| 3745 | */ |
| 3746 | char * |
| 3747 | did_set_numberwidth(optset_T *args UNUSED) |
| 3748 | { |
| 3749 | char *errmsg = NULL; |
| 3750 | |
| 3751 | // 'numberwidth' must be positive |
| 3752 | if (curwin->w_p_nuw < 1) |
| 3753 | { |
| 3754 | errmsg = e_argument_must_be_positive; |
| 3755 | curwin->w_p_nuw = 1; |
| 3756 | } |
| 3757 | if (curwin->w_p_nuw > 20) |
| 3758 | { |
| 3759 | errmsg = e_invalid_argument; |
| 3760 | curwin->w_p_nuw = 20; |
| 3761 | } |
| 3762 | curwin->w_nrwidth_line_count = 0; // trigger a redraw |
| 3763 | |
| 3764 | return errmsg; |
| 3765 | } |
| 3766 | #endif |
| 3767 | |
| 3768 | /* |
| 3769 | * Process the updated 'paste' option value. Called after p_paste was set or |
| 3770 | * reset. When 'paste' is set or reset also change other options. |
| 3771 | */ |
| 3772 | char * |
| 3773 | did_set_paste(optset_T *args UNUSED) |
| 3774 | { |
| 3775 | static int old_p_paste = FALSE; |
| 3776 | static int save_sm = 0; |
| 3777 | static int save_sta = 0; |
| 3778 | static int save_ru = 0; |
| 3779 | #ifdef FEAT_RIGHTLEFT |
| 3780 | static int save_ri = 0; |
| 3781 | static int save_hkmap = 0; |
| 3782 | #endif |
| 3783 | buf_T *buf; |
| 3784 | |
| 3785 | if (p_paste) |
| 3786 | { |
| 3787 | // Paste switched from off to on. |
| 3788 | // Save the current values, so they can be restored later. |
| 3789 | if (!old_p_paste) |
| 3790 | { |
| 3791 | // save options for each buffer |
| 3792 | FOR_ALL_BUFFERS(buf) |
| 3793 | { |
| 3794 | buf->b_p_tw_nopaste = buf->b_p_tw; |
| 3795 | buf->b_p_wm_nopaste = buf->b_p_wm; |
| 3796 | buf->b_p_sts_nopaste = buf->b_p_sts; |
| 3797 | buf->b_p_ai_nopaste = buf->b_p_ai; |
| 3798 | buf->b_p_et_nopaste = buf->b_p_et; |
| 3799 | #ifdef FEAT_VARTABS |
| 3800 | if (buf->b_p_vsts_nopaste) |
| 3801 | vim_free(buf->b_p_vsts_nopaste); |
| 3802 | buf->b_p_vsts_nopaste = |
| 3803 | buf->b_p_vsts && buf->b_p_vsts != empty_option |
| 3804 | ? vim_strsave(buf->b_p_vsts) : NULL; |
| 3805 | #endif |
| 3806 | } |
| 3807 | |
| 3808 | // save global options |
| 3809 | save_sm = p_sm; |
| 3810 | save_sta = p_sta; |
| 3811 | save_ru = p_ru; |
| 3812 | #ifdef FEAT_RIGHTLEFT |
| 3813 | save_ri = p_ri; |
| 3814 | save_hkmap = p_hkmap; |
| 3815 | #endif |
| 3816 | // save global values for local buffer options |
| 3817 | p_ai_nopaste = p_ai; |
| 3818 | p_et_nopaste = p_et; |
| 3819 | p_sts_nopaste = p_sts; |
| 3820 | p_tw_nopaste = p_tw; |
| 3821 | p_wm_nopaste = p_wm; |
| 3822 | #ifdef FEAT_VARTABS |
| 3823 | if (p_vsts_nopaste) |
| 3824 | vim_free(p_vsts_nopaste); |
| 3825 | p_vsts_nopaste = p_vsts && p_vsts != empty_option |
| 3826 | ? vim_strsave(p_vsts) : NULL; |
| 3827 | #endif |
| 3828 | } |
| 3829 | |
| 3830 | // Always set the option values, also when 'paste' is set when it is |
| 3831 | // already on. Set options for each buffer. |
| 3832 | FOR_ALL_BUFFERS(buf) |
| 3833 | { |
| 3834 | buf->b_p_tw = 0; // textwidth is 0 |
| 3835 | buf->b_p_wm = 0; // wrapmargin is 0 |
| 3836 | buf->b_p_sts = 0; // softtabstop is 0 |
| 3837 | buf->b_p_ai = 0; // no auto-indent |
| 3838 | buf->b_p_et = 0; // no expandtab |
| 3839 | #ifdef FEAT_VARTABS |
| 3840 | if (buf->b_p_vsts) |
| 3841 | free_string_option(buf->b_p_vsts); |
| 3842 | buf->b_p_vsts = empty_option; |
| 3843 | VIM_CLEAR(buf->b_p_vsts_array); |
| 3844 | #endif |
| 3845 | } |
| 3846 | |
| 3847 | // set global options |
| 3848 | p_sm = 0; // no showmatch |
| 3849 | p_sta = 0; // no smarttab |
| 3850 | if (p_ru) |
| 3851 | status_redraw_all(); // redraw to remove the ruler |
| 3852 | p_ru = 0; // no ruler |
| 3853 | #ifdef FEAT_RIGHTLEFT |
| 3854 | p_ri = 0; // no reverse insert |
| 3855 | p_hkmap = 0; // no Hebrew keyboard |
| 3856 | #endif |
| 3857 | // set global values for local buffer options |
| 3858 | p_tw = 0; |
| 3859 | p_wm = 0; |
| 3860 | p_sts = 0; |
| 3861 | p_ai = 0; |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 3862 | p_et = 0; |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3863 | #ifdef FEAT_VARTABS |
| 3864 | if (p_vsts) |
| 3865 | free_string_option(p_vsts); |
| 3866 | p_vsts = empty_option; |
| 3867 | #endif |
| 3868 | } |
| 3869 | |
| 3870 | // Paste switched from on to off: Restore saved values. |
| 3871 | else if (old_p_paste) |
| 3872 | { |
| 3873 | // restore options for each buffer |
| 3874 | FOR_ALL_BUFFERS(buf) |
| 3875 | { |
| 3876 | buf->b_p_tw = buf->b_p_tw_nopaste; |
| 3877 | buf->b_p_wm = buf->b_p_wm_nopaste; |
| 3878 | buf->b_p_sts = buf->b_p_sts_nopaste; |
| 3879 | buf->b_p_ai = buf->b_p_ai_nopaste; |
| 3880 | buf->b_p_et = buf->b_p_et_nopaste; |
| 3881 | #ifdef FEAT_VARTABS |
| 3882 | if (buf->b_p_vsts) |
| 3883 | free_string_option(buf->b_p_vsts); |
| 3884 | buf->b_p_vsts = buf->b_p_vsts_nopaste |
| 3885 | ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option; |
| 3886 | vim_free(buf->b_p_vsts_array); |
| 3887 | if (buf->b_p_vsts && buf->b_p_vsts != empty_option) |
| 3888 | (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); |
| 3889 | else |
| 3890 | buf->b_p_vsts_array = NULL; |
| 3891 | #endif |
| 3892 | } |
| 3893 | |
| 3894 | // restore global options |
| 3895 | p_sm = save_sm; |
| 3896 | p_sta = save_sta; |
| 3897 | if (p_ru != save_ru) |
| 3898 | status_redraw_all(); // redraw to draw the ruler |
| 3899 | p_ru = save_ru; |
| 3900 | #ifdef FEAT_RIGHTLEFT |
| 3901 | p_ri = save_ri; |
| 3902 | p_hkmap = save_hkmap; |
| 3903 | #endif |
| 3904 | // set global values for local buffer options |
| 3905 | p_ai = p_ai_nopaste; |
| 3906 | p_et = p_et_nopaste; |
| 3907 | p_sts = p_sts_nopaste; |
| 3908 | p_tw = p_tw_nopaste; |
| 3909 | p_wm = p_wm_nopaste; |
| 3910 | #ifdef FEAT_VARTABS |
| 3911 | if (p_vsts) |
| 3912 | free_string_option(p_vsts); |
| 3913 | p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; |
| 3914 | #endif |
| 3915 | } |
| 3916 | |
| 3917 | old_p_paste = p_paste; |
| 3918 | |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 3919 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 3920 | // Remember where the dependent options were reset |
| 3921 | didset_options_sctx((OPT_LOCAL | OPT_GLOBAL), p_paste_dep_opts); |
| 3922 | #endif |
| 3923 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 3924 | return NULL; |
| 3925 | } |
| 3926 | |
| 3927 | |
| 3928 | #ifdef FEAT_QUICKFIX |
| 3929 | /* |
| 3930 | * Process the updated 'previewwindow' option value. |
| 3931 | */ |
| 3932 | char * |
| 3933 | did_set_previewwindow(optset_T *args) |
| 3934 | { |
| 3935 | if (!curwin->w_p_pvw) |
| 3936 | return NULL; |
| 3937 | |
| 3938 | // There can be only one window with 'previewwindow' set. |
| 3939 | win_T *win; |
| 3940 | |
| 3941 | FOR_ALL_WINDOWS(win) |
| 3942 | if (win->w_p_pvw && win != curwin) |
| 3943 | { |
| 3944 | curwin->w_p_pvw = FALSE; |
| 3945 | args->os_doskip = TRUE; |
| 3946 | return e_preview_window_already_exists; |
| 3947 | } |
| 3948 | |
| 3949 | return NULL; |
| 3950 | } |
| 3951 | #endif |
| 3952 | |
| 3953 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
| 3954 | /* |
| 3955 | * Process the new 'pyxversion' option value. |
| 3956 | */ |
| 3957 | char * |
| 3958 | did_set_pyxversion(optset_T *args UNUSED) |
| 3959 | { |
| 3960 | char *errmsg = NULL; |
| 3961 | |
| 3962 | if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) |
| 3963 | errmsg = e_invalid_argument; |
| 3964 | |
| 3965 | return errmsg; |
| 3966 | } |
| 3967 | #endif |
| 3968 | |
| 3969 | /* |
| 3970 | * Process the updated 'readonly' option value. |
| 3971 | */ |
| 3972 | char * |
| 3973 | did_set_readonly(optset_T *args) |
| 3974 | { |
| 3975 | // when 'readonly' is reset globally, also reset readonlymode |
| 3976 | if (!curbuf->b_p_ro && (args->os_flags & OPT_LOCAL) == 0) |
| 3977 | readonlymode = FALSE; |
| 3978 | |
| 3979 | // when 'readonly' is set may give W10 again |
| 3980 | if (curbuf->b_p_ro) |
| 3981 | curbuf->b_did_warn = FALSE; |
| 3982 | |
| 3983 | redraw_titles(); |
| 3984 | |
| 3985 | return NULL; |
| 3986 | } |
| 3987 | |
| 3988 | /* |
| 3989 | * Process the updated 'scrollbind' option value. |
| 3990 | */ |
| 3991 | char * |
| 3992 | did_set_scrollbind(optset_T *args UNUSED) |
| 3993 | { |
| 3994 | // when 'scrollbind' is set: snapshot the current position to avoid a jump |
| 3995 | // at the end of normal_cmd() |
| 3996 | if (!curwin->w_p_scb) |
| 3997 | return NULL; |
| 3998 | |
| 3999 | do_check_scrollbind(FALSE); |
| 4000 | curwin->w_scbind_pos = curwin->w_topline; |
| 4001 | return NULL; |
| 4002 | } |
| 4003 | |
| 4004 | #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) |
| 4005 | /* |
| 4006 | * Process the updated 'shellslash' option value. |
| 4007 | */ |
| 4008 | char * |
| 4009 | did_set_shellslash(optset_T *args UNUSED) |
| 4010 | { |
| 4011 | if (p_ssl) |
| 4012 | { |
| 4013 | psepc = '/'; |
| 4014 | psepcN = '\\'; |
| 4015 | pseps[0] = '/'; |
| 4016 | } |
| 4017 | else |
| 4018 | { |
| 4019 | psepc = '\\'; |
| 4020 | psepcN = '/'; |
| 4021 | pseps[0] = '\\'; |
| 4022 | } |
| 4023 | |
| 4024 | // need to adjust the file name arguments and buffer names. |
| 4025 | buflist_slash_adjust(); |
| 4026 | alist_slash_adjust(); |
| 4027 | # ifdef FEAT_EVAL |
| 4028 | scriptnames_slash_adjust(); |
| 4029 | # endif |
| 4030 | return NULL; |
| 4031 | } |
| 4032 | #endif |
| 4033 | |
| 4034 | /* |
| 4035 | * Process the new 'shiftwidth' or the 'tabstop' option value. |
| 4036 | */ |
| 4037 | char * |
| 4038 | did_set_shiftwidth_tabstop(optset_T *args) |
| 4039 | { |
| 4040 | long *pp = (long *)args->os_varp; |
| 4041 | char *errmsg = NULL; |
| 4042 | |
| 4043 | if (curbuf->b_p_sw < 0) |
| 4044 | { |
| 4045 | errmsg = e_argument_must_be_positive; |
| 4046 | #ifdef FEAT_VARTABS |
| 4047 | // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. |
| 4048 | curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0 |
| 4049 | ? tabstop_first(curbuf->b_p_vts_array) |
| 4050 | : curbuf->b_p_ts; |
| 4051 | #else |
| 4052 | curbuf->b_p_sw = curbuf->b_p_ts; |
| 4053 | #endif |
| 4054 | } |
| 4055 | |
| 4056 | #ifdef FEAT_FOLDING |
| 4057 | if (foldmethodIsIndent(curwin)) |
| 4058 | foldUpdateAll(curwin); |
| 4059 | #endif |
| 4060 | // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: |
| 4061 | // parse 'cinoptions'. |
| 4062 | if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) |
| 4063 | parse_cino(curbuf); |
| 4064 | |
| 4065 | return errmsg; |
| 4066 | } |
| 4067 | |
| 4068 | /* |
| 4069 | * Process the new 'showtabline' option value. |
| 4070 | */ |
| 4071 | char * |
| 4072 | did_set_showtabline(optset_T *args UNUSED) |
| 4073 | { |
| 4074 | shell_new_rows(); // recompute window positions and heights |
| 4075 | return NULL; |
| 4076 | } |
| 4077 | |
| 4078 | /* |
| 4079 | * Process the updated 'smoothscroll' option value. |
| 4080 | */ |
| 4081 | char * |
| 4082 | did_set_smoothscroll(optset_T *args UNUSED) |
| 4083 | { |
| 4084 | if (curwin->w_p_sms) |
| 4085 | return NULL; |
| 4086 | |
| 4087 | curwin->w_skipcol = 0; |
| 4088 | changed_line_abv_curs(); |
| 4089 | return NULL; |
| 4090 | } |
| 4091 | |
| 4092 | #if defined(FEAT_SPELL) || defined(PROTO) |
| 4093 | /* |
| 4094 | * Process the updated 'spell' option value. |
| 4095 | */ |
| 4096 | char * |
| 4097 | did_set_spell(optset_T *args UNUSED) |
| 4098 | { |
| 4099 | if (curwin->w_p_spell) |
| 4100 | return parse_spelllang(curwin); |
| 4101 | |
| 4102 | return NULL; |
| 4103 | } |
| 4104 | #endif |
| 4105 | |
| 4106 | /* |
| 4107 | * Process the updated 'swapfile' option value. |
| 4108 | */ |
| 4109 | char * |
| 4110 | did_set_swapfile(optset_T *args UNUSED) |
| 4111 | { |
| 4112 | // when 'swf' is set, create swapfile, when reset remove swapfile |
| 4113 | if (curbuf->b_p_swf && p_uc) |
| 4114 | ml_open_file(curbuf); // create the swap file |
| 4115 | else |
| 4116 | // no need to reset curbuf->b_may_swap, ml_open_file() will check |
| 4117 | // buf->b_p_swf |
| 4118 | mf_close_file(curbuf, TRUE); // remove the swap file |
| 4119 | return NULL; |
| 4120 | } |
| 4121 | |
| 4122 | #if defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4123 | char * |
| 4124 | did_set_termguicolors(optset_T *args UNUSED) |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 4125 | { |
| 4126 | # ifdef FEAT_VTP |
| 4127 | // Do not turn on 'tgc' when 24-bit colors are not supported. |
| 4128 | if ( |
| 4129 | # ifdef VIMDLL |
| 4130 | !gui.in_use && !gui.starting && |
| 4131 | # endif |
| 4132 | !has_vtp_working()) |
| 4133 | { |
| 4134 | p_tgc = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4135 | args->os_doskip = TRUE; |
Yegappan Lakshmanan | 80b817b | 2023-02-09 22:08:52 +0000 | [diff] [blame] | 4136 | return e_24_bit_colors_are_not_supported_on_this_environment; |
| 4137 | } |
| 4138 | if (is_term_win32()) |
| 4139 | swap_tcap(); |
| 4140 | # endif |
| 4141 | # ifdef FEAT_GUI |
| 4142 | if (!gui.in_use && !gui.starting) |
| 4143 | # endif |
| 4144 | highlight_gui_started(); |
| 4145 | # ifdef FEAT_VTP |
| 4146 | // reset t_Co |
| 4147 | if (is_term_win32()) |
| 4148 | { |
| 4149 | control_console_color_rgb(); |
| 4150 | set_termname(T_NAME); |
| 4151 | init_highlight(TRUE, FALSE); |
| 4152 | } |
| 4153 | # endif |
| 4154 | # ifdef FEAT_TERMINAL |
| 4155 | term_update_colors_all(); |
| 4156 | term_update_palette_all(); |
| 4157 | term_update_wincolor_all(); |
| 4158 | # endif |
| 4159 | |
| 4160 | return NULL; |
| 4161 | } |
| 4162 | #endif |
| 4163 | |
| 4164 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4165 | * Process the updated 'terse' option value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4166 | */ |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4167 | char * |
| 4168 | did_set_terse(optset_T *args UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4169 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4170 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4171 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4172 | // when 'terse' is set change 'shortmess' |
| 4173 | p = vim_strchr(p_shm, SHM_SEARCH); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4174 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4175 | // insert 's' in p_shm |
| 4176 | if (p_terse && p == NULL) |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4177 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4178 | STRCPY(IObuff, p_shm); |
| 4179 | STRCAT(IObuff, "s"); |
| 4180 | set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4181 | } |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4182 | // remove 's' from p_shm |
| 4183 | else if (!p_terse && p != NULL) |
| 4184 | STRMOVE(p, p + 1); |
| 4185 | return NULL; |
| 4186 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4187 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4188 | /* |
| 4189 | * Process the updated 'textauto' option value. |
| 4190 | */ |
| 4191 | char * |
| 4192 | did_set_textauto(optset_T *args) |
| 4193 | { |
| 4194 | // when 'textauto' is set or reset also change 'fileformats' |
| 4195 | set_string_option_direct((char_u *)"ffs", -1, |
| 4196 | p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", |
| 4197 | OPT_FREE | args->os_flags, 0); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4198 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4199 | return NULL; |
| 4200 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4201 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4202 | /* |
| 4203 | * Process the updated 'textmode' option value. |
| 4204 | */ |
| 4205 | char * |
| 4206 | did_set_textmode(optset_T *args) |
| 4207 | { |
| 4208 | // when 'textmode' is set or reset also change 'fileformat' |
| 4209 | set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, args->os_flags); |
| 4210 | |
| 4211 | return NULL; |
| 4212 | } |
| 4213 | |
| 4214 | /* |
| 4215 | * Process the new 'textwidth' option value. |
| 4216 | */ |
| 4217 | char * |
| 4218 | did_set_textwidth(optset_T *args UNUSED) |
| 4219 | { |
| 4220 | char *errmsg = NULL; |
| 4221 | |
| 4222 | if (curbuf->b_p_tw < 0) |
| 4223 | { |
| 4224 | errmsg = e_argument_must_be_positive; |
| 4225 | curbuf->b_p_tw = 0; |
| 4226 | } |
| 4227 | #ifdef FEAT_SYN_HL |
| 4228 | { |
| 4229 | win_T *wp; |
| 4230 | tabpage_T *tp; |
| 4231 | |
| 4232 | FOR_ALL_TAB_WINDOWS(tp, wp) |
| 4233 | check_colorcolumn(wp); |
| 4234 | } |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4235 | #endif |
| 4236 | |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 4237 | return errmsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4241 | * Process the updated 'title' or the 'icon' option value. |
| 4242 | */ |
| 4243 | char * |
| 4244 | did_set_title_icon(optset_T *args UNUSED) |
| 4245 | { |
| 4246 | // when 'title' changed, may need to change the title; same for 'icon' |
| 4247 | did_set_title(); |
| 4248 | return NULL; |
| 4249 | } |
| 4250 | |
| 4251 | /* |
| 4252 | * Process the new 'titlelen' option value. |
| 4253 | */ |
| 4254 | char * |
| 4255 | did_set_titlelen(optset_T *args) |
| 4256 | { |
| 4257 | long old_value = args->os_oldval.number; |
| 4258 | char *errmsg = NULL; |
| 4259 | |
| 4260 | // if 'titlelen' has changed, redraw the title |
| 4261 | if (p_titlelen < 0) |
| 4262 | { |
| 4263 | errmsg = e_argument_must_be_positive; |
| 4264 | p_titlelen = 85; |
| 4265 | } |
| 4266 | if (starting != NO_SCREEN && old_value != p_titlelen) |
| 4267 | need_maketitle = TRUE; |
| 4268 | |
| 4269 | return errmsg; |
| 4270 | } |
| 4271 | |
| 4272 | #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
| 4273 | /* |
| 4274 | * Process the updated 'undofile' option value. |
| 4275 | */ |
| 4276 | char * |
| 4277 | did_set_undofile(optset_T *args) |
| 4278 | { |
| 4279 | // Only take action when the option was set. |
| 4280 | if (!curbuf->b_p_udf && !p_udf) |
| 4281 | return NULL; |
| 4282 | |
| 4283 | // When reset we do not delete the undo file, the option may be set again |
| 4284 | // without making any changes in between. |
| 4285 | char_u hash[UNDO_HASH_SIZE]; |
| 4286 | buf_T *save_curbuf = curbuf; |
| 4287 | |
| 4288 | FOR_ALL_BUFFERS(curbuf) |
| 4289 | { |
| 4290 | // When 'undofile' is set globally: for every buffer, otherwise |
| 4291 | // only for the current buffer: Try to read in the undofile, |
| 4292 | // if one exists, the buffer wasn't changed and the buffer was |
| 4293 | // loaded |
| 4294 | if ((curbuf == save_curbuf |
| 4295 | || (args->os_flags & OPT_GLOBAL) |
| 4296 | || args->os_flags == 0) |
| 4297 | && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) |
| 4298 | { |
| 4299 | #ifdef FEAT_CRYPT |
Christian Brabandt | aae5834 | 2023-04-23 17:50:22 +0100 | [diff] [blame] | 4300 | if (crypt_method_is_sodium(crypt_get_method_nr(curbuf))) |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4301 | continue; |
| 4302 | #endif |
| 4303 | u_compute_hash(hash); |
| 4304 | u_read_undo(NULL, hash, curbuf->b_fname); |
| 4305 | } |
| 4306 | } |
| 4307 | curbuf = save_curbuf; |
| 4308 | |
| 4309 | return NULL; |
| 4310 | } |
| 4311 | #endif |
| 4312 | |
| 4313 | /* |
| 4314 | * Process the new global 'undolevels' option value. |
| 4315 | */ |
| 4316 | static void |
| 4317 | update_global_undolevels(long value, long old_value) |
| 4318 | { |
| 4319 | // sync undo before 'undolevels' changes |
| 4320 | |
| 4321 | // use the old value, otherwise u_sync() may not work properly |
| 4322 | p_ul = old_value; |
| 4323 | u_sync(TRUE); |
| 4324 | p_ul = value; |
| 4325 | } |
| 4326 | |
| 4327 | /* |
| 4328 | * Process the new buffer local 'undolevels' option value. |
| 4329 | */ |
| 4330 | static void |
| 4331 | update_buflocal_undolevels(long value, long old_value) |
| 4332 | { |
| 4333 | // use the old value, otherwise u_sync() may not work properly |
| 4334 | curbuf->b_p_ul = old_value; |
| 4335 | u_sync(TRUE); |
| 4336 | curbuf->b_p_ul = value; |
| 4337 | } |
| 4338 | |
| 4339 | /* |
| 4340 | * Process the new 'undolevels' option value. |
| 4341 | */ |
| 4342 | char * |
| 4343 | did_set_undolevels(optset_T *args) |
| 4344 | { |
| 4345 | long *pp = (long *)args->os_varp; |
| 4346 | |
| 4347 | if (pp == &p_ul) // global 'undolevels' |
| 4348 | update_global_undolevels(args->os_newval.number, |
| 4349 | args->os_oldval.number); |
| 4350 | else if (pp == &curbuf->b_p_ul) // buffer local 'undolevels' |
| 4351 | update_buflocal_undolevels(args->os_newval.number, |
| 4352 | args->os_oldval.number); |
| 4353 | |
| 4354 | return NULL; |
| 4355 | } |
| 4356 | |
| 4357 | /* |
| 4358 | * Process the new 'updatecount' option value. |
| 4359 | */ |
| 4360 | char * |
| 4361 | did_set_updatecount(optset_T *args) |
| 4362 | { |
| 4363 | long old_value = args->os_oldval.number; |
| 4364 | char *errmsg = NULL; |
| 4365 | |
| 4366 | // when 'updatecount' changes from zero to non-zero, open swap files |
| 4367 | if (p_uc < 0) |
| 4368 | { |
| 4369 | errmsg = e_argument_must_be_positive; |
| 4370 | p_uc = 100; |
| 4371 | } |
| 4372 | if (p_uc && !old_value) |
| 4373 | ml_open_files(); |
| 4374 | |
| 4375 | return errmsg; |
| 4376 | } |
| 4377 | |
| 4378 | /* |
| 4379 | * Process the updated 'weirdinvert' option value. |
| 4380 | */ |
| 4381 | char * |
| 4382 | did_set_weirdinvert(optset_T *args) |
| 4383 | { |
| 4384 | // When 'weirdinvert' changed, set/reset 't_xs'. |
| 4385 | // Then set 'weirdinvert' according to value of 't_xs'. |
| 4386 | if (p_wiv && !args->os_oldval.boolean) |
| 4387 | T_XS = (char_u *)"y"; |
| 4388 | else if (!p_wiv && args->os_oldval.boolean) |
| 4389 | T_XS = empty_option; |
| 4390 | p_wiv = (*T_XS != NUL); |
| 4391 | |
| 4392 | return NULL; |
| 4393 | } |
| 4394 | |
| 4395 | /* |
| 4396 | * Process the new 'window' option value. |
| 4397 | */ |
| 4398 | char * |
| 4399 | did_set_window(optset_T *args UNUSED) |
| 4400 | { |
| 4401 | if (p_window < 1) |
| 4402 | p_window = 1; |
| 4403 | else if (p_window >= Rows) |
| 4404 | p_window = Rows - 1; |
| 4405 | return NULL; |
| 4406 | } |
| 4407 | |
| 4408 | /* |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4409 | * Process the new 'winheight' or the 'helpheight' option value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4410 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4411 | char * |
| 4412 | did_set_winheight_helpheight(optset_T *args) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4413 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4414 | long *pp = (long *)args->os_varp; |
| 4415 | char *errmsg = NULL; |
| 4416 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4417 | if (p_wh < 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4418 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4419 | errmsg = e_argument_must_be_positive; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4420 | p_wh = 1; |
| 4421 | } |
| 4422 | if (p_wmh > p_wh) |
| 4423 | { |
| 4424 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 4425 | p_wh = p_wmh; |
| 4426 | } |
| 4427 | if (p_hh < 0) |
| 4428 | { |
| 4429 | errmsg = e_argument_must_be_positive; |
| 4430 | p_hh = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4433 | // Change window height NOW |
| 4434 | if (!ONE_WINDOW) |
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 | if (pp == &p_wh && curwin->w_height < p_wh) |
| 4437 | win_setheight((int)p_wh); |
| 4438 | if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) |
| 4439 | win_setheight((int)p_hh); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4440 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4441 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4442 | return errmsg; |
| 4443 | } |
| 4444 | |
| 4445 | /* |
| 4446 | * Process the new 'winminheight' option value. |
| 4447 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4448 | char * |
| 4449 | did_set_winminheight(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4450 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4451 | char *errmsg = NULL; |
| 4452 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4453 | if (p_wmh < 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4454 | { |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4455 | errmsg = e_argument_must_be_positive; |
| 4456 | p_wmh = 0; |
| 4457 | } |
| 4458 | if (p_wmh > p_wh) |
| 4459 | { |
| 4460 | errmsg = e_winheight_cannot_be_smaller_than_winminheight; |
| 4461 | p_wmh = p_wh; |
| 4462 | } |
| 4463 | win_setminheight(); |
| 4464 | |
| 4465 | return errmsg; |
| 4466 | } |
| 4467 | |
| 4468 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4469 | * Process the new 'winminwidth' option value. |
| 4470 | */ |
| 4471 | char * |
| 4472 | did_set_winminwidth(optset_T *args UNUSED) |
| 4473 | { |
| 4474 | char *errmsg = NULL; |
| 4475 | |
| 4476 | if (p_wmw < 0) |
| 4477 | { |
| 4478 | errmsg = e_argument_must_be_positive; |
| 4479 | p_wmw = 0; |
| 4480 | } |
| 4481 | if (p_wmw > p_wiw) |
| 4482 | { |
| 4483 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4484 | p_wmw = p_wiw; |
| 4485 | } |
| 4486 | win_setminwidth(); |
| 4487 | |
| 4488 | return errmsg; |
| 4489 | } |
| 4490 | |
| 4491 | /* |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4492 | * Process the new 'winwidth' option value. |
| 4493 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4494 | char * |
| 4495 | did_set_winwidth(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4496 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4497 | char *errmsg = NULL; |
| 4498 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4499 | if (p_wiw < 1) |
| 4500 | { |
| 4501 | errmsg = e_argument_must_be_positive; |
| 4502 | p_wiw = 1; |
| 4503 | } |
| 4504 | if (p_wmw > p_wiw) |
| 4505 | { |
| 4506 | errmsg = e_winwidth_cannot_be_smaller_than_winminwidth; |
| 4507 | p_wiw = p_wmw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4508 | } |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 4509 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4510 | // Change window width NOW |
| 4511 | if (!ONE_WINDOW && curwin->w_width < p_wiw) |
| 4512 | win_setwidth((int)p_wiw); |
| 4513 | |
| 4514 | return errmsg; |
| 4515 | } |
| 4516 | |
| 4517 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4518 | * Process the updated 'wrap' option value. |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4519 | */ |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4520 | char * |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4521 | did_set_wrap(optset_T *args UNUSED) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4522 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4523 | // If 'wrap' is set, set w_leftcol to zero. |
| 4524 | if (curwin->w_p_wrap) |
| 4525 | curwin->w_leftcol = 0; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4526 | return NULL; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /* |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4530 | * Set the value of a boolean option, and take care of side effects. |
| 4531 | * Returns NULL for success, or an error message for an error. |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4532 | */ |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4533 | static char * |
| 4534 | set_bool_option( |
| 4535 | int opt_idx, // index in options[] table |
| 4536 | char_u *varp, // pointer to the option variable |
| 4537 | int value, // new value |
| 4538 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4539 | { |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4540 | int old_value = *(int *)varp; |
| 4541 | #if defined(FEAT_EVAL) |
| 4542 | int old_global_value = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4543 | #endif |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4544 | char *errmsg = NULL; |
| 4545 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4546 | // Disallow changing some options from secure mode |
| 4547 | if ((secure |
| 4548 | #ifdef HAVE_SANDBOX |
| 4549 | || sandbox != 0 |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4550 | #endif |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4551 | ) && (options[opt_idx].flags & P_SECURE)) |
| 4552 | return e_not_allowed_here; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4553 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4554 | #if defined(FEAT_EVAL) |
| 4555 | // Save the global value before changing anything. This is needed as for |
| 4556 | // a global-only option setting the "local value" in fact sets the global |
| 4557 | // value (since there is only one value). |
| 4558 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4559 | old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), |
| 4560 | OPT_GLOBAL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4561 | #endif |
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 | *(int *)varp = value; // set the new value |
| 4564 | #ifdef FEAT_EVAL |
| 4565 | // Remember where the option was set. |
| 4566 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
Bram Moolenaar | 5c6dbcb | 2017-08-30 22:00:20 +0200 | [diff] [blame] | 4567 | #endif |
| 4568 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4569 | #ifdef FEAT_GUI |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4570 | need_mouse_correct = TRUE; |
Bram Moolenaar | 325b7a2 | 2004-07-05 15:58:32 +0000 | [diff] [blame] | 4571 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4572 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4573 | // May set global value for local option. |
| 4574 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4575 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4576 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4577 | // Handle side effects of changing a bool option. |
| 4578 | if (options[opt_idx].opt_did_set_cb != NULL) |
| 4579 | { |
| 4580 | optset_T args; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4581 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4582 | CLEAR_FIELD(args); |
| 4583 | args.os_varp = varp; |
| 4584 | args.os_flags = opt_flags; |
| 4585 | args.os_oldval.boolean = old_value; |
| 4586 | args.os_newval.boolean = value; |
| 4587 | args.os_errbuf = NULL; |
| 4588 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
| 4589 | if (args.os_doskip) |
| 4590 | return errmsg; |
| 4591 | } |
| 4592 | |
| 4593 | // after handling side effects, call autocommand |
| 4594 | |
| 4595 | options[opt_idx].flags |= P_WAS_SET; |
| 4596 | |
| 4597 | #if defined(FEAT_EVAL) |
| 4598 | apply_optionset_autocmd(opt_idx, opt_flags, |
| 4599 | (long)(old_value ? TRUE : FALSE), |
| 4600 | (long)(old_global_value ? TRUE : FALSE), |
| 4601 | (long)(value ? TRUE : FALSE), NULL); |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 4602 | #endif |
| 4603 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4604 | comp_col(); // in case 'ruler' or 'showcmd' changed |
| 4605 | if (curwin->w_curswant != MAXCOL |
| 4606 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
| 4607 | curwin->w_set_curswant = TRUE; |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4608 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4609 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 4610 | check_redraw(options[opt_idx].flags); |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4611 | |
| 4612 | return errmsg; |
| 4613 | } |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4614 | |
| 4615 | /* |
| 4616 | * Check the bounds of numeric options. |
| 4617 | */ |
| 4618 | static char * |
| 4619 | check_num_option_bounds( |
| 4620 | long *pp, |
| 4621 | long old_value, |
| 4622 | long old_Rows, |
| 4623 | long old_Columns, |
| 4624 | char *errbuf, |
| 4625 | size_t errbuflen, |
| 4626 | char *errmsg) |
| 4627 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4628 | if (Rows < min_rows() && full_screen) |
| 4629 | { |
| 4630 | if (errbuf != NULL) |
| 4631 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4632 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4633 | _(e_need_at_least_nr_lines), min_rows()); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4634 | errmsg = errbuf; |
| 4635 | } |
| 4636 | Rows = min_rows(); |
| 4637 | } |
| 4638 | if (Columns < MIN_COLUMNS && full_screen) |
| 4639 | { |
| 4640 | if (errbuf != NULL) |
| 4641 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 4642 | vim_snprintf(errbuf, errbuflen, |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4643 | _(e_need_at_least_nr_columns), MIN_COLUMNS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4644 | errmsg = errbuf; |
| 4645 | } |
| 4646 | Columns = MIN_COLUMNS; |
| 4647 | } |
Bram Moolenaar | e057d40 | 2013-06-30 17:51:51 +0200 | [diff] [blame] | 4648 | limit_screen_size(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4649 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4650 | // If the screen (shell) height has been changed, assume it is the |
| 4651 | // physical screenheight. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4652 | if (old_Rows != Rows || old_Columns != Columns) |
| 4653 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4654 | // Changing the screen size is not allowed while updating the screen. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4655 | if (updating_screen) |
| 4656 | *pp = old_value; |
| 4657 | else if (full_screen |
| 4658 | #ifdef FEAT_GUI |
| 4659 | && !gui.starting |
| 4660 | #endif |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4661 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4662 | set_shellsize((int)Columns, (int)Rows, TRUE); |
| 4663 | else |
| 4664 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4665 | // Postpone the resizing; check the size and cmdline position for |
| 4666 | // messages. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4667 | check_shellsize(); |
| 4668 | if (cmdline_row > Rows - p_ch && Rows > p_ch) |
| 4669 | cmdline_row = Rows - p_ch; |
| 4670 | } |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 4671 | if (p_window >= Rows || !option_was_set((char_u *)"window")) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 4672 | p_window = Rows - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4675 | if (curbuf->b_p_ts <= 0) |
| 4676 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4677 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4678 | curbuf->b_p_ts = 8; |
| 4679 | } |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 4680 | else if (curbuf->b_p_ts > TABSTOP_MAX) |
| 4681 | { |
| 4682 | errmsg = e_invalid_argument; |
| 4683 | curbuf->b_p_ts = 8; |
| 4684 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4685 | if (p_tm < 0) |
| 4686 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4687 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4688 | p_tm = 0; |
| 4689 | } |
| 4690 | if ((curwin->w_p_scr <= 0 |
| 4691 | || (curwin->w_p_scr > curwin->w_height |
| 4692 | && curwin->w_height > 0)) |
| 4693 | && full_screen) |
| 4694 | { |
| 4695 | if (pp == &(curwin->w_p_scr)) |
| 4696 | { |
| 4697 | if (curwin->w_p_scr != 0) |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4698 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4699 | win_comp_scroll(curwin); |
| 4700 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4701 | // If 'scroll' became invalid because of a side effect silently adjust |
| 4702 | // it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4703 | else if (curwin->w_p_scr <= 0) |
| 4704 | curwin->w_p_scr = 1; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4705 | else // curwin->w_p_scr > curwin->w_height |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4706 | curwin->w_p_scr = curwin->w_height; |
| 4707 | } |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4708 | if (p_hi < 0) |
| 4709 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4710 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 991e10f | 2008-10-02 20:48:41 +0000 | [diff] [blame] | 4711 | p_hi = 0; |
| 4712 | } |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4713 | else if (p_hi > 10000) |
| 4714 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4715 | errmsg = e_invalid_argument; |
Bram Moolenaar | 78159bb | 2014-06-25 11:48:54 +0200 | [diff] [blame] | 4716 | p_hi = 10000; |
| 4717 | } |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4718 | if (p_re < 0 || p_re > 2) |
| 4719 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 4720 | errmsg = e_invalid_argument; |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 4721 | p_re = 0; |
| 4722 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4723 | if (p_report < 0) |
| 4724 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4725 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4726 | p_report = 1; |
| 4727 | } |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 4728 | if ((p_sj < -100 || p_sj >= Rows) && full_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4729 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4730 | if (Rows != old_Rows) // Rows changed, just adjust p_sj |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4731 | p_sj = Rows / 2; |
| 4732 | else |
| 4733 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 4734 | errmsg = e_invalid_scroll_size; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4735 | p_sj = 1; |
| 4736 | } |
| 4737 | } |
| 4738 | if (p_so < 0 && full_screen) |
| 4739 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4740 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4741 | p_so = 0; |
| 4742 | } |
| 4743 | if (p_siso < 0 && full_screen) |
| 4744 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4745 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4746 | p_siso = 0; |
| 4747 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4748 | if (p_cwh < 1) |
| 4749 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4750 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4751 | p_cwh = 1; |
| 4752 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4753 | if (p_ut < 0) |
| 4754 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4755 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4756 | p_ut = 2000; |
| 4757 | } |
| 4758 | if (p_ss < 0) |
| 4759 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 4760 | errmsg = e_argument_must_be_positive; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4761 | p_ss = 0; |
| 4762 | } |
| 4763 | |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4764 | return errmsg; |
| 4765 | } |
| 4766 | |
| 4767 | /* |
| 4768 | * Set the value of a number option, and take care of side effects. |
| 4769 | * Returns NULL for success, or an error message for an error. |
| 4770 | */ |
| 4771 | static char * |
| 4772 | set_num_option( |
| 4773 | int opt_idx, // index in options[] table |
| 4774 | char_u *varp, // pointer to the option variable |
| 4775 | long value, // new value |
| 4776 | char *errbuf, // buffer for error messages |
| 4777 | size_t errbuflen, // length of "errbuf" |
| 4778 | int opt_flags) // OPT_LOCAL, OPT_GLOBAL, |
| 4779 | // OPT_MODELINE, etc. |
| 4780 | { |
| 4781 | char *errmsg = NULL; |
| 4782 | long old_value = *(long *)varp; |
| 4783 | #if defined(FEAT_EVAL) |
| 4784 | long old_global_value = 0; // only used when setting a local and |
| 4785 | // global option |
| 4786 | #endif |
| 4787 | long old_Rows = Rows; // remember old Rows |
| 4788 | long old_Columns = Columns; // remember old Columns |
| 4789 | long *pp = (long *)varp; |
| 4790 | |
| 4791 | // Disallow changing some options from secure mode. |
| 4792 | if ((secure |
| 4793 | #ifdef HAVE_SANDBOX |
| 4794 | || sandbox != 0 |
| 4795 | #endif |
| 4796 | ) && (options[opt_idx].flags & P_SECURE)) |
| 4797 | return e_not_allowed_here; |
| 4798 | |
| 4799 | #if defined(FEAT_EVAL) |
| 4800 | // Save the global value before changing anything. This is needed as for |
| 4801 | // a global-only option setting the "local value" in fact sets the global |
| 4802 | // value (since there is only one value). |
| 4803 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4804 | old_global_value = *(long *)get_varp_scope(&(options[opt_idx]), |
| 4805 | OPT_GLOBAL); |
| 4806 | #endif |
| 4807 | |
| 4808 | *pp = value; |
| 4809 | #ifdef FEAT_EVAL |
| 4810 | // Remember where the option was set. |
| 4811 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
| 4812 | #endif |
| 4813 | #ifdef FEAT_GUI |
| 4814 | need_mouse_correct = TRUE; |
| 4815 | #endif |
| 4816 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4817 | // Invoke the option specific callback function to validate and apply the |
| 4818 | // new value. |
| 4819 | if (options[opt_idx].opt_did_set_cb != NULL) |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4820 | { |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4821 | optset_T args; |
| 4822 | |
Yegappan Lakshmanan | 5284b23 | 2023-03-04 19:57:32 +0000 | [diff] [blame] | 4823 | CLEAR_FIELD(args); |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4824 | args.os_varp = varp; |
| 4825 | args.os_flags = opt_flags; |
| 4826 | args.os_oldval.number = old_value; |
| 4827 | args.os_newval.number = value; |
Yegappan Lakshmanan | 6d611de | 2023-02-25 11:59:33 +0000 | [diff] [blame] | 4828 | args.os_errbuf = NULL; |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4829 | errmsg = options[opt_idx].opt_did_set_cb(&args); |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 4832 | // Check the bounds for numeric options here |
Yegappan Lakshmanan | 0caaf1e | 2023-02-09 12:23:17 +0000 | [diff] [blame] | 4833 | errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns, |
| 4834 | errbuf, errbuflen, errmsg); |
| 4835 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4836 | // May set global value for local option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4837 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 4838 | *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; |
| 4839 | |
| 4840 | options[opt_idx].flags |= P_WAS_SET; |
| 4841 | |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 4842 | #if defined(FEAT_EVAL) |
Bram Moolenaar | f414048 | 2020-02-15 23:06:45 +0100 | [diff] [blame] | 4843 | apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value, |
| 4844 | value, errmsg); |
Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame] | 4845 | #endif |
| 4846 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4847 | comp_col(); // in case 'columns' or 'ls' changed |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4848 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | 488eb26 | 2015-03-13 11:23:50 +0100 | [diff] [blame] | 4849 | && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | 913077c | 2012-03-28 19:59:04 +0200 | [diff] [blame] | 4850 | curwin->w_set_curswant = TRUE; |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 4851 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 4852 | check_redraw(options[opt_idx].flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4853 | |
| 4854 | return errmsg; |
| 4855 | } |
| 4856 | |
| 4857 | /* |
| 4858 | * Called after an option changed: check if something needs to be redrawn. |
| 4859 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4860 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4861 | check_redraw(long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4862 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4863 | // 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] | 4864 | int doclear = (flags & P_RCLR) == P_RCLR; |
| 4865 | int all = ((flags & P_RALL) == P_RALL || doclear); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4866 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4867 | if ((flags & P_RSTAT) || all) // mark all status lines dirty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4868 | status_redraw_all(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4869 | |
| 4870 | if ((flags & P_RBUF) || (flags & P_RWIN) || all) |
| 4871 | changed_window_setting(); |
| 4872 | if (flags & P_RBUF) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4873 | redraw_curbuf_later(UPD_NOT_VALID); |
Bram Moolenaar | a2477fd | 2016-12-03 15:13:20 +0100 | [diff] [blame] | 4874 | if (flags & P_RWINONLY) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4875 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 4876 | if (doclear) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4877 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4878 | else if (all) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 4879 | redraw_all_later(UPD_NOT_VALID); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | /* |
| 4883 | * Find index for option 'arg'. |
| 4884 | * Return -1 if not found. |
| 4885 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 4886 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4887 | findoption(char_u *arg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4888 | { |
| 4889 | int opt_idx; |
| 4890 | char *s, *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4891 | static short quick_tab[27] = {0, 0}; // quick access table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4892 | int is_term_opt; |
| 4893 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4894 | // For first call: Initialize the quick-access table. |
| 4895 | // It contains the index for the first option that starts with a certain |
| 4896 | // letter. There are 26 letters, plus the first "t_" option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4897 | if (quick_tab[1] == 0) |
| 4898 | { |
| 4899 | p = options[0].fullname; |
| 4900 | for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4901 | { |
| 4902 | if (s[0] != p[0]) |
| 4903 | { |
| 4904 | if (s[0] == 't' && s[1] == '_') |
| 4905 | quick_tab[26] = opt_idx; |
| 4906 | else |
| 4907 | quick_tab[CharOrdLow(s[0])] = opt_idx; |
| 4908 | } |
| 4909 | p = s; |
| 4910 | } |
| 4911 | } |
| 4912 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 4913 | // Check for name starting with an illegal character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4914 | if (arg[0] < 'a' || arg[0] > 'z') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4915 | return -1; |
| 4916 | |
| 4917 | is_term_opt = (arg[0] == 't' && arg[1] == '_'); |
| 4918 | if (is_term_opt) |
| 4919 | opt_idx = quick_tab[26]; |
| 4920 | else |
| 4921 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4922 | for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) |
| 4923 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4924 | if (STRCMP(arg, s) == 0) // match full name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4925 | break; |
| 4926 | } |
| 4927 | if (s == NULL && !is_term_opt) |
| 4928 | { |
| 4929 | opt_idx = quick_tab[CharOrdLow(arg[0])]; |
| 4930 | for ( ; options[opt_idx].fullname != NULL; opt_idx++) |
| 4931 | { |
| 4932 | s = options[opt_idx].shortname; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4933 | if (s != NULL && STRCMP(arg, s) == 0) // match short name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4934 | break; |
| 4935 | s = NULL; |
| 4936 | } |
| 4937 | } |
| 4938 | if (s == NULL) |
| 4939 | opt_idx = -1; |
| 4940 | return opt_idx; |
| 4941 | } |
| 4942 | |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 4943 | #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME) \ |
| 4944 | || defined(FEAT_SPELL) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4945 | /* |
| 4946 | * Get the value for an option. |
| 4947 | * |
| 4948 | * Returns: |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4949 | * Number option: gov_number, *numval gets value. |
Bram Moolenaar | a725149 | 2021-01-02 16:53:13 +0100 | [diff] [blame] | 4950 | * Toggle option: gov_bool, *numval gets value. |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4951 | * String option: gov_string, *stringval gets allocated string. |
| 4952 | * Hidden Number option: gov_hidden_number. |
| 4953 | * Hidden Toggle option: gov_hidden_bool. |
| 4954 | * Hidden String option: gov_hidden_string. |
| 4955 | * Unknown option: gov_unknown. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4956 | * |
| 4957 | * "flagsp" (if not NULL) is set to the option flags (P_xxxx). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4958 | */ |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4959 | getoption_T |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 4960 | get_option_value( |
| 4961 | char_u *name, |
| 4962 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 4963 | char_u **stringval, // NULL when only checking existence |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 4964 | int *flagsp, |
| 4965 | int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4966 | { |
| 4967 | int opt_idx; |
| 4968 | char_u *varp; |
| 4969 | |
| 4970 | opt_idx = findoption(name); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4971 | if (opt_idx < 0) // option not in the table |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4972 | { |
| 4973 | int key; |
| 4974 | |
| 4975 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4976 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4977 | { |
| 4978 | char_u key_name[2]; |
| 4979 | char_u *p; |
| 4980 | |
Bram Moolenaar | 10c75c4 | 2021-12-28 20:53:30 +0000 | [diff] [blame] | 4981 | if (flagsp != NULL) |
| 4982 | *flagsp = 0; // terminal option has no flags |
| 4983 | |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 4984 | // check for a terminal option |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 4985 | if (key < 0) |
| 4986 | { |
| 4987 | key_name[0] = KEY2TERMCAP0(key); |
| 4988 | key_name[1] = KEY2TERMCAP1(key); |
| 4989 | } |
| 4990 | else |
| 4991 | { |
| 4992 | key_name[0] = KS_KEY; |
| 4993 | key_name[1] = (key & 0xff); |
| 4994 | } |
| 4995 | p = find_termcode(key_name); |
| 4996 | if (p != NULL) |
| 4997 | { |
| 4998 | if (stringval != NULL) |
| 4999 | *stringval = vim_strsave(p); |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5000 | return gov_string; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5001 | } |
| 5002 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5003 | return gov_unknown; |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5004 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5005 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 5006 | varp = get_varp_scope(&(options[opt_idx]), scope); |
| 5007 | |
| 5008 | if (flagsp != NULL) |
| 5009 | // Return the P_xxxx option flags. |
| 5010 | *flagsp = options[opt_idx].flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5011 | |
| 5012 | if (options[opt_idx].flags & P_STRING) |
| 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 gov_hidden_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5016 | if (stringval != NULL) |
| 5017 | { |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 5018 | if ((char_u **)varp == &p_pt) // 'pastetoggle' |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 5019 | *stringval = str2special_save(*(char_u **)(varp), FALSE, |
| 5020 | FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5021 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5022 | // never return the value of the crypt key |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 5023 | else if ((char_u **)varp == &curbuf->b_p_key |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 5024 | && **(char_u **)(varp) != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5025 | *stringval = vim_strsave((char_u *)"*****"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5026 | #endif |
zeertzjq | 51f0bc3 | 2022-05-09 13:33:39 +0100 | [diff] [blame] | 5027 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5028 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 5029 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5030 | return gov_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5031 | } |
| 5032 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5033 | if (varp == NULL) // hidden option |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5034 | return (options[opt_idx].flags & P_NUM) |
| 5035 | ? gov_hidden_number : gov_hidden_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5036 | if (options[opt_idx].flags & P_NUM) |
| 5037 | *numval = *(long *)varp; |
| 5038 | else |
| 5039 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5040 | // Special case: 'modified' is b_changed, but we also want to consider |
| 5041 | // it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5042 | if ((int *)varp == &curbuf->b_changed) |
| 5043 | *numval = curbufIsChanged(); |
| 5044 | else |
Bram Moolenaar | 2acfbed | 2016-07-01 23:14:02 +0200 | [diff] [blame] | 5045 | *numval = (long) *(int *)varp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5046 | } |
Bram Moolenaar | dd1f426 | 2020-12-31 17:41:01 +0100 | [diff] [blame] | 5047 | return (options[opt_idx].flags & P_NUM) ? gov_number : gov_bool; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5048 | } |
| 5049 | #endif |
| 5050 | |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5051 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5052 | /* |
| 5053 | * Returns the option attributes and its value. Unlike the above function it |
| 5054 | * will return either global value or local value of the option depending on |
| 5055 | * what was requested, but it will never return global value if it was |
| 5056 | * requested to return local one and vice versa. Neither it will return |
| 5057 | * buffer-local value if it was requested to return window-local one. |
| 5058 | * |
| 5059 | * Pretends that option is absent if it is not present in the requested scope |
| 5060 | * (i.e. has no global, window-local or buffer-local value depending on |
| 5061 | * opt_type). Uses |
| 5062 | * |
| 5063 | * Returned flags: |
Bram Moolenaar | 75a8d74 | 2014-05-07 15:10:21 +0200 | [diff] [blame] | 5064 | * 0 hidden or unknown option, also option that does not have requested |
| 5065 | * type (see SREQ_* in vim.h) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5066 | * see SOPT_* in vim.h for other flags |
| 5067 | * |
| 5068 | * Possible opt_type values: see SREQ_* in vim.h |
| 5069 | */ |
| 5070 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5071 | get_option_value_strict( |
| 5072 | char_u *name, |
| 5073 | long *numval, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5074 | char_u **stringval, // NULL when only obtaining attributes |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5075 | int opt_type, |
| 5076 | void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5077 | { |
| 5078 | int opt_idx; |
Bram Moolenaar | 6800186 | 2013-05-11 13:45:05 +0200 | [diff] [blame] | 5079 | char_u *varp = NULL; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5080 | struct vimoption *p; |
| 5081 | int r = 0; |
| 5082 | |
| 5083 | opt_idx = findoption(name); |
| 5084 | if (opt_idx < 0) |
| 5085 | return 0; |
| 5086 | |
| 5087 | p = &(options[opt_idx]); |
| 5088 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5089 | // Hidden option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5090 | if (p->var == NULL) |
| 5091 | return 0; |
| 5092 | |
| 5093 | if (p->flags & P_BOOL) |
| 5094 | r |= SOPT_BOOL; |
| 5095 | else if (p->flags & P_NUM) |
| 5096 | r |= SOPT_NUM; |
| 5097 | else if (p->flags & P_STRING) |
| 5098 | r |= SOPT_STRING; |
| 5099 | |
| 5100 | if (p->indir == PV_NONE) |
| 5101 | { |
| 5102 | if (opt_type == SREQ_GLOBAL) |
| 5103 | r |= SOPT_GLOBAL; |
| 5104 | else |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5105 | return 0; // Did not request global-only option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5106 | } |
| 5107 | else |
| 5108 | { |
| 5109 | if (p->indir & PV_BOTH) |
| 5110 | r |= SOPT_GLOBAL; |
| 5111 | else if (opt_type == SREQ_GLOBAL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5112 | return 0; // Requested global option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5113 | |
| 5114 | if (p->indir & PV_WIN) |
| 5115 | { |
| 5116 | if (opt_type == SREQ_BUF) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5117 | return 0; // Did not request window-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5118 | else |
| 5119 | r |= SOPT_WIN; |
| 5120 | } |
| 5121 | else if (p->indir & PV_BUF) |
| 5122 | { |
| 5123 | if (opt_type == SREQ_WIN) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5124 | return 0; // Did not request buffer-local option |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5125 | else |
| 5126 | r |= SOPT_BUF; |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | if (stringval == NULL) |
| 5131 | return r; |
| 5132 | |
| 5133 | if (opt_type == SREQ_GLOBAL) |
| 5134 | varp = p->var; |
| 5135 | else |
| 5136 | { |
| 5137 | if (opt_type == SREQ_BUF) |
| 5138 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5139 | // Special case: 'modified' is b_changed, but we also want to |
| 5140 | // consider it set when 'ff' or 'fenc' changed. |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5141 | if (p->indir == PV_MOD) |
| 5142 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5143 | *numval = bufIsChanged((buf_T *)from); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5144 | varp = NULL; |
| 5145 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 5146 | # ifdef FEAT_CRYPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5147 | else if (p->indir == PV_KEY) |
| 5148 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5149 | // never return the value of the crypt key |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5150 | *stringval = NULL; |
| 5151 | varp = NULL; |
| 5152 | } |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 5153 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5154 | else |
| 5155 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5156 | buf_T *save_curbuf = curbuf; |
| 5157 | |
| 5158 | // only getting a pointer, no need to use aucmd_prepbuf() |
| 5159 | curbuf = (buf_T *)from; |
| 5160 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5161 | varp = get_varp(p); |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5162 | curbuf = save_curbuf; |
| 5163 | curwin->w_buffer = curbuf; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5164 | } |
| 5165 | } |
| 5166 | else if (opt_type == SREQ_WIN) |
| 5167 | { |
Bram Moolenaar | defe642 | 2018-06-24 15:14:07 +0200 | [diff] [blame] | 5168 | win_T *save_curwin = curwin; |
| 5169 | |
| 5170 | curwin = (win_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5171 | curbuf = curwin->w_buffer; |
| 5172 | varp = get_varp(p); |
| 5173 | curwin = save_curwin; |
| 5174 | curbuf = curwin->w_buffer; |
| 5175 | } |
| 5176 | if (varp == p->var) |
| 5177 | return (r | SOPT_UNSET); |
| 5178 | } |
| 5179 | |
| 5180 | if (varp != NULL) |
| 5181 | { |
| 5182 | if (p->flags & P_STRING) |
| 5183 | *stringval = vim_strsave(*(char_u **)(varp)); |
| 5184 | else if (p->flags & P_NUM) |
| 5185 | *numval = *(long *) varp; |
| 5186 | else |
| 5187 | *numval = *(int *)varp; |
| 5188 | } |
| 5189 | |
| 5190 | return r; |
| 5191 | } |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5192 | |
| 5193 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5194 | * Iterate over options. First argument is a pointer to a pointer to a |
| 5195 | * structure inside options[] array, second is option type like in the above |
| 5196 | * function. |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5197 | * |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5198 | * 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] | 5199 | * and caller needs the very first value. |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 5200 | * 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] | 5201 | * first argument to NULL. |
| 5202 | * |
| 5203 | * Returns full option name for current option on each call. |
| 5204 | */ |
| 5205 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5206 | option_iter_next(void **option, int opt_type) |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5207 | { |
| 5208 | struct vimoption *ret = NULL; |
| 5209 | do |
| 5210 | { |
| 5211 | if (*option == NULL) |
| 5212 | *option = (void *) options; |
| 5213 | else if (((struct vimoption *) (*option))->fullname == NULL) |
| 5214 | { |
| 5215 | *option = NULL; |
| 5216 | return NULL; |
| 5217 | } |
| 5218 | else |
| 5219 | *option = (void *) (((struct vimoption *) (*option)) + 1); |
| 5220 | |
| 5221 | ret = ((struct vimoption *) (*option)); |
| 5222 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5223 | // Hidden option |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5224 | if (ret->var == NULL) |
| 5225 | { |
| 5226 | ret = NULL; |
| 5227 | continue; |
| 5228 | } |
| 5229 | |
| 5230 | switch (opt_type) |
| 5231 | { |
| 5232 | case SREQ_GLOBAL: |
| 5233 | if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH)) |
| 5234 | ret = NULL; |
| 5235 | break; |
| 5236 | case SREQ_BUF: |
| 5237 | if (!(ret->indir & PV_BUF)) |
| 5238 | ret = NULL; |
| 5239 | break; |
| 5240 | case SREQ_WIN: |
| 5241 | if (!(ret->indir & PV_WIN)) |
| 5242 | ret = NULL; |
| 5243 | break; |
| 5244 | default: |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 5245 | internal_error("option_iter_next()"); |
Bram Moolenaar | 1028f4d | 2014-01-14 16:55:00 +0100 | [diff] [blame] | 5246 | return NULL; |
| 5247 | } |
| 5248 | } |
| 5249 | while (ret == NULL); |
| 5250 | |
| 5251 | return (char_u *)ret->fullname; |
| 5252 | } |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 5253 | #endif |
| 5254 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5255 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5256 | * Return the flags for the option at 'opt_idx'. |
| 5257 | */ |
| 5258 | long_u |
| 5259 | get_option_flags(int opt_idx) |
| 5260 | { |
| 5261 | return options[opt_idx].flags; |
| 5262 | } |
| 5263 | |
| 5264 | /* |
| 5265 | * Set a flag for the option at 'opt_idx'. |
| 5266 | */ |
| 5267 | void |
| 5268 | set_option_flag(int opt_idx, long_u flag) |
| 5269 | { |
| 5270 | options[opt_idx].flags |= flag; |
| 5271 | } |
| 5272 | |
| 5273 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 5274 | * Returns TRUE if the option at 'opt_idx' is a global option |
| 5275 | */ |
| 5276 | int |
| 5277 | is_global_option(int opt_idx) |
| 5278 | { |
| 5279 | return options[opt_idx].indir == PV_NONE; |
| 5280 | } |
| 5281 | |
| 5282 | /* |
| 5283 | * Returns TRUE if the option at 'opt_idx' is a global option which also has a |
| 5284 | * local value. |
| 5285 | */ |
| 5286 | int |
| 5287 | is_global_local_option(int opt_idx) |
| 5288 | { |
| 5289 | return options[opt_idx].indir & PV_BOTH; |
| 5290 | } |
| 5291 | |
| 5292 | /* |
| 5293 | * Returns TRUE if the option at 'opt_idx' is a window-local option |
| 5294 | */ |
| 5295 | int |
| 5296 | is_window_local_option(int opt_idx) |
| 5297 | { |
| 5298 | return options[opt_idx].var == VAR_WIN; |
| 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | * Returns TRUE if the option at 'opt_idx' is a hidden option |
| 5303 | */ |
| 5304 | int |
| 5305 | is_hidden_option(int opt_idx) |
| 5306 | { |
| 5307 | return options[opt_idx].var == NULL; |
| 5308 | } |
| 5309 | |
| 5310 | #if defined(FEAT_CRYPT) || defined(PROTO) |
| 5311 | /* |
| 5312 | * Returns TRUE if the option at 'opt_idx' is a crypt key option |
| 5313 | */ |
| 5314 | int |
| 5315 | is_crypt_key_option(int opt_idx) |
| 5316 | { |
| 5317 | return options[opt_idx].indir == PV_KEY; |
| 5318 | } |
| 5319 | #endif |
| 5320 | |
| 5321 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5322 | * Set the value of option "name". |
| 5323 | * Use "string" for string options, use "number" for other options. |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5324 | * |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5325 | * Returns NULL on success or an untranslated error message on error. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5326 | */ |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 5327 | char * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5328 | set_option_value( |
| 5329 | char_u *name, |
| 5330 | long number, |
| 5331 | char_u *string, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5332 | int opt_flags) // OPT_LOCAL or 0 (both) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5333 | { |
| 5334 | int opt_idx; |
| 5335 | char_u *varp; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 5336 | long_u flags; |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5337 | static char errbuf[80]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5338 | |
| 5339 | opt_idx = findoption(name); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 5340 | if (opt_idx < 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5341 | { |
| 5342 | int key; |
| 5343 | |
| 5344 | if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5345 | && (key = find_key_option(name, FALSE)) != 0) |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5346 | { |
| 5347 | char_u key_name[2]; |
| 5348 | |
| 5349 | if (key < 0) |
| 5350 | { |
| 5351 | key_name[0] = KEY2TERMCAP0(key); |
| 5352 | key_name[1] = KEY2TERMCAP1(key); |
| 5353 | } |
| 5354 | else |
| 5355 | { |
| 5356 | key_name[0] = KS_KEY; |
| 5357 | key_name[1] = (key & 0xff); |
| 5358 | } |
| 5359 | add_termcode(key_name, string, FALSE); |
| 5360 | if (full_screen) |
| 5361 | ttest(FALSE); |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 5362 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5363 | return NULL; |
| 5364 | } |
| 5365 | |
Bram Moolenaar | ac78dd4 | 2022-01-02 19:25:26 +0000 | [diff] [blame] | 5366 | semsg(_(e_unknown_option_str_2), name); |
Bram Moolenaar | e353c40 | 2017-02-04 19:49:16 +0100 | [diff] [blame] | 5367 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5368 | else |
| 5369 | { |
| 5370 | flags = options[opt_idx].flags; |
| 5371 | #ifdef HAVE_SANDBOX |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5372 | // Disallow changing some options in the sandbox |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5373 | if (sandbox > 0 && (flags & P_SECURE)) |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5374 | { |
Bram Moolenaar | d8e4447 | 2021-07-21 22:20:33 +0200 | [diff] [blame] | 5375 | emsg(_(e_not_allowed_in_sandbox)); |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5376 | return NULL; |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5377 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5378 | #endif |
Bram Moolenaar | b71eaae | 2006-01-20 23:10:18 +0000 | [diff] [blame] | 5379 | if (flags & P_STRING) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5380 | 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] | 5381 | |
| 5382 | varp = get_varp_scope(&(options[opt_idx]), opt_flags); |
| 5383 | if (varp != NULL) // hidden option is not changed |
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 (number == 0 && string != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5386 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5387 | int idx; |
| 5388 | |
| 5389 | // Either we are given a string or we are setting option |
| 5390 | // to zero. |
| 5391 | for (idx = 0; string[idx] == '0'; ++idx) |
| 5392 | ; |
| 5393 | if (string[idx] != NUL || idx == 0) |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5394 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5395 | // There's another character after zeros or the string |
| 5396 | // is empty. In both cases, we are trying to set a |
| 5397 | // num option using a string. |
| 5398 | semsg(_(e_number_required_after_str_equal_str), |
| 5399 | name, string); |
| 5400 | return NULL; // do nothing as we hit an error |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5401 | |
Bram Moolenaar | 96bb621 | 2007-06-19 18:52:53 +0000 | [diff] [blame] | 5402 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5403 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5404 | if (flags & P_NUM) |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5405 | { |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5406 | return set_num_option(opt_idx, varp, number, |
Yegappan Lakshmanan | 32ff96e | 2023-02-13 16:10:04 +0000 | [diff] [blame] | 5407 | errbuf, sizeof(errbuf), opt_flags); |
| 5408 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5409 | else |
| 5410 | return set_bool_option(opt_idx, varp, (int)number, opt_flags); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5411 | } |
=?UTF-8?q?Dundar=20G=C3=B6c?= | f26c161 | 2022-04-07 13:26:34 +0100 | [diff] [blame] | 5412 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5413 | } |
Bram Moolenaar | c96ebe7 | 2013-05-21 22:38:18 +0200 | [diff] [blame] | 5414 | return NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | /* |
Bram Moolenaar | 31e5c60 | 2022-04-15 13:53:33 +0100 | [diff] [blame] | 5418 | * Call set_option_value() and when an error is returned report it. |
| 5419 | */ |
| 5420 | void |
| 5421 | set_option_value_give_err( |
| 5422 | char_u *name, |
| 5423 | long number, |
| 5424 | char_u *string, |
| 5425 | int opt_flags) // OPT_LOCAL or 0 (both) |
| 5426 | { |
| 5427 | char *errmsg = set_option_value(name, number, string, opt_flags); |
| 5428 | |
| 5429 | if (errmsg != NULL) |
| 5430 | emsg(_(errmsg)); |
| 5431 | } |
| 5432 | |
| 5433 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5434 | * Get the terminal code for a terminal option. |
| 5435 | * Returns NULL when not found. |
| 5436 | */ |
| 5437 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5438 | get_term_code(char_u *tname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5439 | { |
| 5440 | int opt_idx; |
| 5441 | char_u *varp; |
| 5442 | |
| 5443 | if (tname[0] != 't' || tname[1] != '_' || |
| 5444 | tname[2] == NUL || tname[3] == NUL) |
| 5445 | return NULL; |
| 5446 | if ((opt_idx = findoption(tname)) >= 0) |
| 5447 | { |
| 5448 | varp = get_varp(&(options[opt_idx])); |
| 5449 | if (varp != NULL) |
| 5450 | varp = *(char_u **)(varp); |
| 5451 | return varp; |
| 5452 | } |
| 5453 | return find_termcode(tname + 2); |
| 5454 | } |
| 5455 | |
| 5456 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5457 | get_highlight_default(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5458 | { |
| 5459 | int i; |
| 5460 | |
| 5461 | i = findoption((char_u *)"hl"); |
| 5462 | if (i >= 0) |
| 5463 | return options[i].def_val[VI_DEFAULT]; |
| 5464 | return (char_u *)NULL; |
| 5465 | } |
| 5466 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5467 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5468 | get_encoding_default(void) |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5469 | { |
| 5470 | int i; |
| 5471 | |
| 5472 | i = findoption((char_u *)"enc"); |
| 5473 | if (i >= 0) |
| 5474 | return options[i].def_val[VI_DEFAULT]; |
| 5475 | return (char_u *)NULL; |
| 5476 | } |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5477 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5478 | #if defined(FEAT_QUICKFIX) || defined(PROTO) |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5479 | int |
| 5480 | is_option_allocated(char *name) |
| 5481 | { |
| 5482 | int idx = findoption((char_u *)name); |
| 5483 | |
| 5484 | return idx >= 0 && (options[idx].flags & P_ALLOCED); |
| 5485 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 5486 | #endif |
Bram Moolenaar | 4791fcd | 2022-02-23 12:06:00 +0000 | [diff] [blame] | 5487 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5488 | /* |
| 5489 | * 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] | 5490 | * When "has_lt" is true there is a '<' before "*arg_arg". |
| 5491 | * Returns 0 when the key is not recognized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5492 | */ |
| 5493 | static int |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5494 | find_key_option(char_u *arg_arg, int has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5495 | { |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5496 | int key = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5497 | int modifiers; |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5498 | char_u *arg = arg_arg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5499 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5500 | // Don't use get_special_key_code() for t_xx, we don't want it to call |
| 5501 | // add_termcap_entry(). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5502 | if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
| 5503 | key = TERMCAP2KEY(arg[2], arg[3]); |
Bram Moolenaar | 9cf4b50 | 2018-07-23 04:12:03 +0200 | [diff] [blame] | 5504 | else if (has_lt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5505 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5506 | --arg; // put arg at the '<' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5507 | modifiers = 0; |
Bram Moolenaar | ebe9d34 | 2020-05-30 21:52:54 +0200 | [diff] [blame] | 5508 | key = find_special_key(&arg, &modifiers, |
| 5509 | FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5510 | if (modifiers) // can't handle modifiers here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5511 | key = 0; |
| 5512 | } |
| 5513 | return key; |
| 5514 | } |
| 5515 | |
| 5516 | /* |
| 5517 | * if 'all' == 0: show changed options |
| 5518 | * if 'all' == 1: show all normal options |
| 5519 | * if 'all' == 2: show all terminal options |
| 5520 | */ |
| 5521 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5522 | showoptions( |
| 5523 | int all, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5524 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5525 | { |
| 5526 | struct vimoption *p; |
| 5527 | int col; |
| 5528 | int isterm; |
| 5529 | char_u *varp; |
| 5530 | struct vimoption **items; |
| 5531 | int item_count; |
| 5532 | int run; |
| 5533 | int row, rows; |
| 5534 | int cols; |
| 5535 | int i; |
| 5536 | int len; |
| 5537 | |
| 5538 | #define INC 20 |
| 5539 | #define GAP 3 |
| 5540 | |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5541 | items = ALLOC_MULT(struct vimoption *, OPTION_COUNT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5542 | if (items == NULL) |
| 5543 | return; |
| 5544 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5545 | // Highlight title |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5546 | if (all == 2) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5547 | msg_puts_title(_("\n--- Terminal codes ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5548 | else if (opt_flags & OPT_GLOBAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5549 | msg_puts_title(_("\n--- Global option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5550 | else if (opt_flags & OPT_LOCAL) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5551 | msg_puts_title(_("\n--- Local option values ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5552 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5553 | msg_puts_title(_("\n--- Options ---")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5554 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5555 | // Do the loop two times: |
| 5556 | // 1. display the short items |
| 5557 | // 2. display the long items (only strings and numbers) |
| 5558 | // When "opt_flags" has OPT_ONECOLUMN do everything in run 2. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5559 | for (run = 1; run <= 2 && !got_int; ++run) |
| 5560 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5561 | // collect the items in items[] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5562 | item_count = 0; |
| 5563 | for (p = &options[0]; p->fullname != NULL; p++) |
| 5564 | { |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5565 | // apply :filter /pat/ |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5566 | if (message_filtered((char_u *)p->fullname)) |
Bram Moolenaar | f86db78 | 2018-10-25 13:31:37 +0200 | [diff] [blame] | 5567 | continue; |
| 5568 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5569 | varp = NULL; |
| 5570 | isterm = istermoption(p); |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5571 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5572 | { |
| 5573 | if (p->indir != PV_NONE && !isterm) |
| 5574 | varp = get_varp_scope(p, opt_flags); |
| 5575 | } |
| 5576 | else |
| 5577 | varp = get_varp(p); |
| 5578 | if (varp != NULL |
| 5579 | && ((all == 2 && isterm) |
| 5580 | || (all == 1 && !isterm) |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5581 | || (all == 0 && !optval_default(p, varp, p_cp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5582 | { |
Bram Moolenaar | 6b915c0 | 2020-01-18 15:53:19 +0100 | [diff] [blame] | 5583 | if (opt_flags & OPT_ONECOLUMN) |
| 5584 | len = Columns; |
| 5585 | else if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5586 | len = 1; // a toggle option fits always |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5587 | else |
| 5588 | { |
| 5589 | option_value2string(p, opt_flags); |
| 5590 | len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; |
| 5591 | } |
| 5592 | if ((len <= INC - GAP && run == 1) || |
| 5593 | (len > INC - GAP && run == 2)) |
| 5594 | items[item_count++] = p; |
| 5595 | } |
| 5596 | } |
| 5597 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5598 | // display the items |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5599 | if (run == 1) |
| 5600 | { |
| 5601 | cols = (Columns + GAP - 3) / INC; |
| 5602 | if (cols == 0) |
| 5603 | cols = 1; |
| 5604 | rows = (item_count + cols - 1) / cols; |
| 5605 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5606 | else // run == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5607 | rows = item_count; |
| 5608 | for (row = 0; row < rows && !got_int; ++row) |
| 5609 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5610 | msg_putchar('\n'); // go to next line |
| 5611 | if (got_int) // 'q' typed in more |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5612 | break; |
| 5613 | col = 0; |
| 5614 | for (i = row; i < item_count; i += rows) |
| 5615 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5616 | msg_col = col; // make columns |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5617 | showoneopt(items[i], opt_flags); |
| 5618 | col += INC; |
| 5619 | } |
| 5620 | out_flush(); |
| 5621 | ui_breakcheck(); |
| 5622 | } |
| 5623 | } |
| 5624 | vim_free(items); |
| 5625 | } |
| 5626 | |
| 5627 | /* |
| 5628 | * Return TRUE if option "p" has its default value. |
| 5629 | */ |
| 5630 | static int |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5631 | optval_default(struct vimoption *p, char_u *varp, int compatible) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5632 | { |
| 5633 | int dvi; |
| 5634 | |
| 5635 | if (varp == NULL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5636 | return TRUE; // hidden option is always at default |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5637 | dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5638 | if (p->flags & P_NUM) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5639 | return (*(long *)varp == (long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5640 | if (p->flags & P_BOOL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5641 | // the cast to long is required for Manx C, long_i is |
| 5642 | // needed for MSVC |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5643 | return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5644 | // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5645 | return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); |
| 5646 | } |
| 5647 | |
| 5648 | /* |
| 5649 | * showoneopt: show the value of one option |
| 5650 | * must not be called with a hidden option! |
| 5651 | */ |
| 5652 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5653 | showoneopt( |
| 5654 | struct vimoption *p, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5655 | int opt_flags) // OPT_LOCAL or OPT_GLOBAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5656 | { |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5657 | char_u *varp; |
| 5658 | int save_silent = silent_mode; |
| 5659 | |
| 5660 | silent_mode = FALSE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5661 | info_message = TRUE; // use mch_msg(), not mch_errmsg() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5662 | |
| 5663 | varp = get_varp_scope(p, opt_flags); |
| 5664 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5665 | // for 'modified' we also need to check if 'ff' or 'fenc' changed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5666 | if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed |
| 5667 | ? !curbufIsChanged() : !*(int *)varp)) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5668 | msg_puts("no"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5669 | else if ((p->flags & P_BOOL) && *(int *)varp < 0) |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5670 | msg_puts("--"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5671 | else |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 5672 | msg_puts(" "); |
| 5673 | msg_puts(p->fullname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5674 | if (!(p->flags & P_BOOL)) |
| 5675 | { |
| 5676 | msg_putchar('='); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5677 | // put value string in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5678 | option_value2string(p, opt_flags); |
| 5679 | msg_outtrans(NameBuff); |
| 5680 | } |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 5681 | |
| 5682 | silent_mode = save_silent; |
| 5683 | info_message = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | /* |
| 5687 | * Write modified options as ":set" commands to a file. |
| 5688 | * |
| 5689 | * There are three values for "opt_flags": |
| 5690 | * OPT_GLOBAL: Write global option values and fresh values of |
| 5691 | * buffer-local options (used for start of a session |
| 5692 | * file). |
| 5693 | * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for |
| 5694 | * curwin (used for a vimrc file). |
| 5695 | * OPT_LOCAL: Write buffer-local option values for curbuf, fresh |
| 5696 | * and local values for window-local options of |
| 5697 | * curwin. Local values are also written when at the |
| 5698 | * default value, because a modeline or autocommand |
| 5699 | * may have set them when doing ":edit file" and the |
| 5700 | * user has set them back at the default or fresh |
| 5701 | * value. |
| 5702 | * When "local_only" is TRUE, don't write fresh |
| 5703 | * values, only local values (for ":mkview"). |
| 5704 | * (fresh value = value used for a new buffer or window for a local option). |
| 5705 | * |
| 5706 | * Return FAIL on error, OK otherwise. |
| 5707 | */ |
| 5708 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5709 | makeset(FILE *fd, int opt_flags, int local_only) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5710 | { |
| 5711 | struct vimoption *p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5712 | char_u *varp; // currently used value |
| 5713 | char_u *varp_fresh; // local value |
| 5714 | char_u *varp_local = NULL; // fresh value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5715 | char *cmd; |
| 5716 | int round; |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5717 | int pri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5718 | |
| 5719 | /* |
| 5720 | * The options that don't have a default (terminal name, columns, lines) |
| 5721 | * are never written. Terminal options are also not written. |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5722 | * Do the loop over "options[]" twice: once for options with the |
| 5723 | * P_PRI_MKRC flag and once without. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5724 | */ |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5725 | for (pri = 1; pri >= 0; --pri) |
| 5726 | { |
| 5727 | for (p = &options[0]; !istermoption(p); p++) |
| 5728 | if (!(p->flags & P_NO_MKRC) |
| 5729 | && !istermoption(p) |
| 5730 | && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5731 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5732 | // skip global option when only doing locals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5733 | if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) |
| 5734 | continue; |
| 5735 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5736 | // Do not store options like 'bufhidden' and 'syntax' in a vimrc |
| 5737 | // file, they are always buffer-specific. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5738 | if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) |
| 5739 | continue; |
| 5740 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5741 | // Global values are only written when not at the default value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5742 | varp = get_varp_scope(p, opt_flags); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5743 | if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5744 | continue; |
| 5745 | |
Bram Moolenaar | d23b714 | 2021-04-17 21:04:34 +0200 | [diff] [blame] | 5746 | if ((opt_flags & OPT_SKIPRTP) && (p->var == (char_u *)&p_rtp |
| 5747 | || p->var == (char_u *)&p_pp)) |
Bram Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 5748 | continue; |
| 5749 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5750 | round = 2; |
| 5751 | if (p->indir != PV_NONE) |
| 5752 | { |
| 5753 | if (p->var == VAR_WIN) |
| 5754 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5755 | // skip window-local option when only doing globals |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5756 | if (!(opt_flags & OPT_LOCAL)) |
| 5757 | continue; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5758 | // When fresh value of window-local option is not at the |
| 5759 | // default, need to write it too. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5760 | if (!(opt_flags & OPT_GLOBAL) && !local_only) |
| 5761 | { |
| 5762 | varp_fresh = get_varp_scope(p, OPT_GLOBAL); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 5763 | if (!optval_default(p, varp_fresh, p_cp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5764 | { |
| 5765 | round = 1; |
| 5766 | varp_local = varp; |
| 5767 | varp = varp_fresh; |
| 5768 | } |
| 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5773 | // Round 1: fresh value for window-local options. |
| 5774 | // Round 2: other values |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5775 | for ( ; round <= 2; varp = varp_local, ++round) |
| 5776 | { |
| 5777 | if (round == 1 || (opt_flags & OPT_GLOBAL)) |
| 5778 | cmd = "set"; |
| 5779 | else |
| 5780 | cmd = "setlocal"; |
| 5781 | |
| 5782 | if (p->flags & P_BOOL) |
| 5783 | { |
| 5784 | if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) |
| 5785 | return FAIL; |
| 5786 | } |
| 5787 | else if (p->flags & P_NUM) |
| 5788 | { |
| 5789 | if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) |
| 5790 | return FAIL; |
| 5791 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5792 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5793 | { |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5794 | int do_endif = FALSE; |
| 5795 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5796 | // Don't set 'syntax' and 'filetype' again if the value is |
| 5797 | // already right, avoids reloading the syntax file. |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5798 | if ( |
Bram Moolenaar | f2bd8ef | 2018-03-04 18:08:14 +0100 | [diff] [blame] | 5799 | #if defined(FEAT_SYN_HL) |
| 5800 | p->indir == PV_SYN || |
| 5801 | #endif |
| 5802 | p->indir == PV_FT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5803 | { |
| 5804 | if (fprintf(fd, "if &%s != '%s'", p->fullname, |
| 5805 | *(char_u **)(varp)) < 0 |
| 5806 | || put_eol(fd) < 0) |
| 5807 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5808 | do_endif = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5809 | } |
| 5810 | if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5811 | p->flags) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5812 | return FAIL; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5813 | if (do_endif) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5814 | { |
| 5815 | if (put_line(fd, "endif") == FAIL) |
| 5816 | return FAIL; |
| 5817 | } |
| 5818 | } |
| 5819 | } |
| 5820 | } |
Bram Moolenaar | 7fd1602 | 2007-09-06 14:35:35 +0000 | [diff] [blame] | 5821 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5822 | return OK; |
| 5823 | } |
| 5824 | |
| 5825 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 5826 | /* |
| 5827 | * Generate set commands for the local fold options only. Used when |
| 5828 | * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". |
| 5829 | */ |
| 5830 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5831 | makefoldset(FILE *fd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5832 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5833 | if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5834 | # ifdef FEAT_EVAL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5835 | || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5836 | == FAIL |
| 5837 | # endif |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5838 | || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5839 | == FAIL |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5840 | || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5841 | == FAIL |
| 5842 | || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL |
| 5843 | || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL |
| 5844 | || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL |
| 5845 | || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL |
| 5846 | ) |
| 5847 | return FAIL; |
| 5848 | |
| 5849 | return OK; |
| 5850 | } |
| 5851 | #endif |
| 5852 | |
| 5853 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5854 | put_setstring( |
| 5855 | FILE *fd, |
| 5856 | char *cmd, |
| 5857 | char *name, |
| 5858 | char_u **valuep, |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5859 | long_u flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5860 | { |
| 5861 | char_u *s; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5862 | char_u *buf = NULL; |
| 5863 | char_u *part = NULL; |
| 5864 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5865 | |
| 5866 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5867 | return FAIL; |
| 5868 | if (*valuep != NULL) |
| 5869 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5870 | // Output 'pastetoggle' as key names. For other |
| 5871 | // options some characters have to be escaped with |
| 5872 | // CTRL-V or backslash |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5873 | if (valuep == &p_pt) |
| 5874 | { |
| 5875 | s = *valuep; |
| 5876 | while (*s != NUL) |
zeertzjq | cdc8393 | 2022-09-12 13:38:41 +0100 | [diff] [blame] | 5877 | if (put_escstr(fd, str2special(&s, FALSE, FALSE), 2) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5878 | return FAIL; |
| 5879 | } |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5880 | // expand the option value, replace $HOME by ~ |
| 5881 | else if ((flags & P_EXPAND) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5882 | { |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5883 | int size = (int)STRLEN(*valuep) + 1; |
| 5884 | |
| 5885 | // replace home directory in the whole option value into "buf" |
| 5886 | buf = alloc(size); |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5887 | if (buf == NULL) |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5888 | goto fail; |
| 5889 | home_replace(NULL, *valuep, buf, size, FALSE); |
| 5890 | |
| 5891 | // If the option value is longer than MAXPATHL, we need to append |
Bram Moolenaar | 32aa102 | 2019-11-02 22:54:41 +0100 | [diff] [blame] | 5892 | // each comma separated part of the option separately, so that it |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5893 | // can be expanded when read back. |
| 5894 | if (size >= MAXPATHL && (flags & P_COMMA) != 0 |
| 5895 | && vim_strchr(*valuep, ',') != NULL) |
| 5896 | { |
| 5897 | part = alloc(size); |
| 5898 | if (part == NULL) |
| 5899 | goto fail; |
| 5900 | |
| 5901 | // write line break to clear the option, e.g. ':set rtp=' |
| 5902 | if (put_eol(fd) == FAIL) |
| 5903 | goto fail; |
| 5904 | |
| 5905 | p = buf; |
| 5906 | while (*p != NUL) |
| 5907 | { |
| 5908 | // for each comma separated option part, append value to |
| 5909 | // the option, :set rtp+=value |
| 5910 | if (fprintf(fd, "%s %s+=", cmd, name) < 0) |
| 5911 | goto fail; |
| 5912 | (void)copy_option_part(&p, part, size, ","); |
| 5913 | if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) |
| 5914 | goto fail; |
| 5915 | } |
| 5916 | vim_free(buf); |
| 5917 | vim_free(part); |
| 5918 | return OK; |
| 5919 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5920 | if (put_escstr(fd, buf, 2) == FAIL) |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5921 | { |
| 5922 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5923 | return FAIL; |
Bram Moolenaar | f844147 | 2011-04-28 17:24:58 +0200 | [diff] [blame] | 5924 | } |
| 5925 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5926 | } |
| 5927 | else if (put_escstr(fd, *valuep, 2) == FAIL) |
| 5928 | return FAIL; |
| 5929 | } |
| 5930 | if (put_eol(fd) < 0) |
| 5931 | return FAIL; |
| 5932 | return OK; |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 5933 | fail: |
| 5934 | vim_free(buf); |
| 5935 | vim_free(part); |
| 5936 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5940 | put_setnum( |
| 5941 | FILE *fd, |
| 5942 | char *cmd, |
| 5943 | char *name, |
| 5944 | long *valuep) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5945 | { |
| 5946 | long wc; |
| 5947 | |
| 5948 | if (fprintf(fd, "%s %s=", cmd, name) < 0) |
| 5949 | return FAIL; |
| 5950 | if (wc_use_keyname((char_u *)valuep, &wc)) |
| 5951 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5952 | // print 'wildchar' and 'wildcharm' as a key name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5953 | if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) |
| 5954 | return FAIL; |
| 5955 | } |
| 5956 | else if (fprintf(fd, "%ld", *valuep) < 0) |
| 5957 | return FAIL; |
| 5958 | if (put_eol(fd) < 0) |
| 5959 | return FAIL; |
| 5960 | return OK; |
| 5961 | } |
| 5962 | |
| 5963 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5964 | put_setbool( |
| 5965 | FILE *fd, |
| 5966 | char *cmd, |
| 5967 | char *name, |
| 5968 | int value) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5969 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5970 | if (value < 0) // global/local option using global value |
Bram Moolenaar | 893de92 | 2007-10-02 18:40:57 +0000 | [diff] [blame] | 5971 | return OK; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5972 | if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 |
| 5973 | || put_eol(fd) < 0) |
| 5974 | return FAIL; |
| 5975 | return OK; |
| 5976 | } |
| 5977 | |
| 5978 | /* |
| 5979 | * Clear all the terminal options. |
| 5980 | * If the option has been allocated, free the memory. |
| 5981 | * Terminal options are never hidden or indirect. |
| 5982 | */ |
| 5983 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 5984 | clear_termoptions(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5985 | { |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 5986 | // Reset a few things before clearing the old options. This may cause |
| 5987 | // outputting a few things that the terminal doesn't understand, but the |
| 5988 | // screen will be cleared later, so this is OK. |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 5989 | mch_setmouse(FALSE); // switch mouse off |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5990 | mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5991 | #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5992 | // When starting the GUI close the display opened for the clipboard. |
| 5993 | // After restoring the title, because that will need the display. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5994 | if (gui.starting) |
| 5995 | clear_xterm_clip(); |
| 5996 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 5997 | stoptermcap(); // stop termcap mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5998 | |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 5999 | free_termoptions(); |
| 6000 | } |
| 6001 | |
| 6002 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6003 | free_termoptions(void) |
Bram Moolenaar | f461c8e | 2005-06-25 23:04:51 +0000 | [diff] [blame] | 6004 | { |
| 6005 | struct vimoption *p; |
| 6006 | |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 6007 | for (p = options; p->fullname != NULL; p++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6008 | if (istermoption(p)) |
| 6009 | { |
| 6010 | if (p->flags & P_ALLOCED) |
| 6011 | free_string_option(*(char_u **)(p->var)); |
| 6012 | if (p->flags & P_DEF_ALLOCED) |
| 6013 | free_string_option(p->def_val[VI_DEFAULT]); |
| 6014 | *(char_u **)(p->var) = empty_option; |
| 6015 | p->def_val[VI_DEFAULT] = empty_option; |
| 6016 | p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); |
Bram Moolenaar | 35bc7d6 | 2018-10-02 14:45:10 +0200 | [diff] [blame] | 6017 | #ifdef FEAT_EVAL |
| 6018 | // remember where the option was cleared |
| 6019 | set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx); |
| 6020 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6021 | } |
| 6022 | clear_termcodes(); |
| 6023 | } |
| 6024 | |
| 6025 | /* |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 6026 | * Free the string for one term option, if it was allocated. |
| 6027 | * Set the string to empty_option and clear allocated flag. |
| 6028 | * "var" points to the option value. |
| 6029 | */ |
| 6030 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6031 | free_one_termoption(char_u *var) |
Bram Moolenaar | 363cb67 | 2009-07-22 12:28:17 +0000 | [diff] [blame] | 6032 | { |
| 6033 | struct vimoption *p; |
| 6034 | |
| 6035 | for (p = &options[0]; p->fullname != NULL; p++) |
| 6036 | if (p->var == var) |
| 6037 | { |
| 6038 | if (p->flags & P_ALLOCED) |
| 6039 | free_string_option(*(char_u **)(p->var)); |
| 6040 | *(char_u **)(p->var) = empty_option; |
| 6041 | p->flags &= ~P_ALLOCED; |
| 6042 | break; |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6047 | * Set the terminal option defaults to the current value. |
| 6048 | * Used after setting the terminal name. |
| 6049 | */ |
| 6050 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6051 | set_term_defaults(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6052 | { |
| 6053 | struct vimoption *p; |
| 6054 | |
| 6055 | for (p = &options[0]; p->fullname != NULL; p++) |
| 6056 | { |
| 6057 | if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) |
| 6058 | { |
| 6059 | if (p->flags & P_DEF_ALLOCED) |
| 6060 | { |
| 6061 | free_string_option(p->def_val[VI_DEFAULT]); |
| 6062 | p->flags &= ~P_DEF_ALLOCED; |
| 6063 | } |
| 6064 | p->def_val[VI_DEFAULT] = *(char_u **)(p->var); |
| 6065 | if (p->flags & P_ALLOCED) |
| 6066 | { |
| 6067 | p->flags |= P_DEF_ALLOCED; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6068 | p->flags &= ~P_ALLOCED; // don't free the value now |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6069 | } |
| 6070 | } |
| 6071 | } |
| 6072 | } |
| 6073 | |
| 6074 | /* |
| 6075 | * return TRUE if 'p' starts with 't_' |
| 6076 | */ |
| 6077 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6078 | istermoption(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6079 | { |
| 6080 | return (p->fullname[0] == 't' && p->fullname[1] == '_'); |
| 6081 | } |
| 6082 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6083 | /* |
| 6084 | * Returns TRUE if the option at 'opt_idx' starts with 't_' |
| 6085 | */ |
| 6086 | int |
| 6087 | istermoption_idx(int opt_idx) |
| 6088 | { |
| 6089 | return istermoption(&options[opt_idx]); |
| 6090 | } |
| 6091 | |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 6092 | #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6093 | /* |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6094 | * Unset local option value, similar to ":set opt<". |
| 6095 | */ |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6096 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6097 | unset_global_local_option(char_u *name, void *from) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6098 | { |
| 6099 | struct vimoption *p; |
| 6100 | int opt_idx; |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6101 | buf_T *buf = (buf_T *)from; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6102 | |
| 6103 | opt_idx = findoption(name); |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 6104 | if (opt_idx < 0) |
| 6105 | return; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6106 | p = &(options[opt_idx]); |
| 6107 | |
| 6108 | switch ((int)p->indir) |
| 6109 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6110 | // 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] | 6111 | case PV_EP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6112 | clear_string_option(&buf->b_p_ep); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6113 | break; |
| 6114 | case PV_KP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6115 | clear_string_option(&buf->b_p_kp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6116 | break; |
| 6117 | case PV_PATH: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6118 | clear_string_option(&buf->b_p_path); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6119 | break; |
| 6120 | case PV_AR: |
| 6121 | buf->b_p_ar = -1; |
| 6122 | break; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6123 | case PV_BKC: |
| 6124 | clear_string_option(&buf->b_p_bkc); |
| 6125 | buf->b_bkc_flags = 0; |
| 6126 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6127 | case PV_TAGS: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6128 | clear_string_option(&buf->b_p_tags); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6129 | break; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6130 | case PV_TC: |
| 6131 | clear_string_option(&buf->b_p_tc); |
| 6132 | buf->b_tc_flags = 0; |
| 6133 | break; |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6134 | case PV_SISO: |
| 6135 | curwin->w_p_siso = -1; |
| 6136 | break; |
| 6137 | case PV_SO: |
| 6138 | curwin->w_p_so = -1; |
| 6139 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6140 | # ifdef FEAT_FIND_ID |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6141 | case PV_DEF: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6142 | clear_string_option(&buf->b_p_def); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6143 | break; |
| 6144 | case PV_INC: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6145 | clear_string_option(&buf->b_p_inc); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6146 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6147 | # endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6148 | case PV_DICT: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6149 | clear_string_option(&buf->b_p_dict); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6150 | break; |
| 6151 | case PV_TSR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6152 | clear_string_option(&buf->b_p_tsr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6153 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6154 | # ifdef FEAT_COMPL_FUNC |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6155 | case PV_TSRFU: |
| 6156 | clear_string_option(&buf->b_p_tsrfu); |
| 6157 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6158 | # endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6159 | case PV_FP: |
| 6160 | clear_string_option(&buf->b_p_fp); |
| 6161 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6162 | # ifdef FEAT_QUICKFIX |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6163 | case PV_EFM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6164 | clear_string_option(&buf->b_p_efm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6165 | break; |
| 6166 | case PV_GP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6167 | clear_string_option(&buf->b_p_gp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6168 | break; |
| 6169 | case PV_MP: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6170 | clear_string_option(&buf->b_p_mp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6171 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6172 | # endif |
| 6173 | # if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6174 | case PV_BEXPR: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6175 | clear_string_option(&buf->b_p_bexpr); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6176 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6177 | # endif |
| 6178 | # if defined(FEAT_CRYPT) |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6179 | case PV_CM: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6180 | clear_string_option(&buf->b_p_cm); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6181 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6182 | # endif |
| 6183 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6184 | case PV_SBR: |
| 6185 | clear_string_option(&((win_T *)from)->w_p_sbr); |
| 6186 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6187 | # endif |
| 6188 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6189 | case PV_STL: |
Bram Moolenaar | 51ac8a2 | 2013-05-06 06:45:47 +0200 | [diff] [blame] | 6190 | clear_string_option(&((win_T *)from)->w_p_stl); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6191 | break; |
Bram Moolenaar | 9af2ea8 | 2022-11-22 18:18:38 +0000 | [diff] [blame] | 6192 | # endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6193 | case PV_UL: |
| 6194 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
| 6195 | break; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6196 | case PV_LW: |
| 6197 | clear_string_option(&buf->b_p_lw); |
| 6198 | break; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6199 | case PV_MENC: |
| 6200 | clear_string_option(&buf->b_p_menc); |
| 6201 | break; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6202 | case PV_LCS: |
| 6203 | clear_string_option(&((win_T *)from)->w_p_lcs); |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6204 | 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] | 6205 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6206 | break; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6207 | case PV_FCS: |
| 6208 | clear_string_option(&((win_T *)from)->w_p_fcs); |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6209 | 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] | 6210 | redraw_later(UPD_NOT_VALID); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6211 | break; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6212 | case PV_VE: |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6213 | clear_string_option(&((win_T *)from)->w_p_ve); |
| 6214 | ((win_T *)from)->w_ve_flags = 0; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6215 | break; |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6216 | } |
| 6217 | } |
Bram Moolenaar | 113e107 | 2019-01-20 15:30:40 +0100 | [diff] [blame] | 6218 | #endif |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 6219 | |
| 6220 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6221 | * Get pointer to option variable, depending on local or global scope. |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6222 | * "scope" can be OPT_LOCAL, OPT_GLOBAL or a combination. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6223 | */ |
| 6224 | static char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6225 | get_varp_scope(struct vimoption *p, int scope) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6226 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6227 | if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6228 | { |
| 6229 | if (p->var == VAR_WIN) |
| 6230 | return (char_u *)GLOBAL_WO(get_varp(p)); |
| 6231 | return p->var; |
| 6232 | } |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6233 | if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6234 | { |
| 6235 | switch ((int)p->indir) |
| 6236 | { |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6237 | case PV_FP: return (char_u *)&(curbuf->b_p_fp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6238 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6239 | case PV_EFM: return (char_u *)&(curbuf->b_p_efm); |
| 6240 | case PV_GP: return (char_u *)&(curbuf->b_p_gp); |
| 6241 | case PV_MP: return (char_u *)&(curbuf->b_p_mp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6242 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6243 | case PV_EP: return (char_u *)&(curbuf->b_p_ep); |
| 6244 | case PV_KP: return (char_u *)&(curbuf->b_p_kp); |
| 6245 | case PV_PATH: return (char_u *)&(curbuf->b_p_path); |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6246 | case PV_AR: return (char_u *)&(curbuf->b_p_ar); |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6247 | case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6248 | case PV_TC: return (char_u *)&(curbuf->b_p_tc); |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 6249 | case PV_SISO: return (char_u *)&(curwin->w_p_siso); |
| 6250 | case PV_SO: return (char_u *)&(curwin->w_p_so); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6251 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6252 | case PV_DEF: return (char_u *)&(curbuf->b_p_def); |
| 6253 | case PV_INC: return (char_u *)&(curbuf->b_p_inc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6254 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6255 | case PV_DICT: return (char_u *)&(curbuf->b_p_dict); |
| 6256 | case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6257 | #ifdef FEAT_COMPL_FUNC |
| 6258 | case PV_TSRFU: return (char_u *)&(curbuf->b_p_tsrfu); |
| 6259 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6260 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6261 | case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr); |
| 6262 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6263 | #if defined(FEAT_CRYPT) |
| 6264 | case PV_CM: return (char_u *)&(curbuf->b_p_cm); |
| 6265 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6266 | #ifdef FEAT_LINEBREAK |
| 6267 | case PV_SBR: return (char_u *)&(curwin->w_p_sbr); |
| 6268 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6269 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6270 | case PV_STL: return (char_u *)&(curwin->w_p_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6271 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6272 | case PV_UL: return (char_u *)&(curbuf->b_p_ul); |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6273 | case PV_LW: return (char_u *)&(curbuf->b_p_lw); |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6274 | case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6275 | case PV_MENC: return (char_u *)&(curbuf->b_p_menc); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 6276 | case PV_LCS: return (char_u *)&(curwin->w_p_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6277 | case PV_FCS: return (char_u *)&(curwin->w_p_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6278 | case PV_VE: return (char_u *)&(curwin->w_p_ve); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6279 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6280 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6281 | return NULL; // "cannot happen" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6282 | } |
| 6283 | return get_varp(p); |
| 6284 | } |
| 6285 | |
| 6286 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6287 | * Get pointer to option variable at 'opt_idx', depending on local or global |
| 6288 | * scope. |
| 6289 | */ |
| 6290 | char_u * |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6291 | get_option_varp_scope(int opt_idx, int scope) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6292 | { |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 6293 | return get_varp_scope(&(options[opt_idx]), scope); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6297 | * Get pointer to option variable. |
| 6298 | */ |
| 6299 | static char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6300 | get_varp(struct vimoption *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6301 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6302 | // hidden option, always return NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6303 | if (p->var == NULL) |
| 6304 | return NULL; |
| 6305 | |
| 6306 | switch ((int)p->indir) |
| 6307 | { |
| 6308 | case PV_NONE: return p->var; |
| 6309 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6310 | // 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] | 6311 | case PV_EP: return *curbuf->b_p_ep != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6312 | ? (char_u *)&curbuf->b_p_ep : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6313 | case PV_KP: return *curbuf->b_p_kp != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6314 | ? (char_u *)&curbuf->b_p_kp : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6315 | case PV_PATH: return *curbuf->b_p_path != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6316 | ? (char_u *)&(curbuf->b_p_path) : p->var; |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 6317 | case PV_AR: return curbuf->b_p_ar >= 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6318 | ? (char_u *)&(curbuf->b_p_ar) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6319 | case PV_TAGS: return *curbuf->b_p_tags != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6320 | ? (char_u *)&(curbuf->b_p_tags) : p->var; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 6321 | case PV_TC: return *curbuf->b_p_tc != NUL |
| 6322 | ? (char_u *)&(curbuf->b_p_tc) : p->var; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 6323 | case PV_BKC: return *curbuf->b_p_bkc != NUL |
| 6324 | ? (char_u *)&(curbuf->b_p_bkc) : p->var; |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 6325 | case PV_SISO: return curwin->w_p_siso >= 0 |
| 6326 | ? (char_u *)&(curwin->w_p_siso) : p->var; |
| 6327 | case PV_SO: return curwin->w_p_so >= 0 |
| 6328 | ? (char_u *)&(curwin->w_p_so) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6329 | #ifdef FEAT_FIND_ID |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6330 | case PV_DEF: return *curbuf->b_p_def != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6331 | ? (char_u *)&(curbuf->b_p_def) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6332 | case PV_INC: return *curbuf->b_p_inc != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6333 | ? (char_u *)&(curbuf->b_p_inc) : p->var; |
| 6334 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6335 | case PV_DICT: return *curbuf->b_p_dict != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6336 | ? (char_u *)&(curbuf->b_p_dict) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6337 | case PV_TSR: return *curbuf->b_p_tsr != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6338 | ? (char_u *)&(curbuf->b_p_tsr) : p->var; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 6339 | #ifdef FEAT_COMPL_FUNC |
| 6340 | case PV_TSRFU: return *curbuf->b_p_tsrfu != NUL |
| 6341 | ? (char_u *)&(curbuf->b_p_tsrfu) : p->var; |
| 6342 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 6343 | case PV_FP: return *curbuf->b_p_fp != NUL |
| 6344 | ? (char_u *)&(curbuf->b_p_fp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6345 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6346 | case PV_EFM: return *curbuf->b_p_efm != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6347 | ? (char_u *)&(curbuf->b_p_efm) : p->var; |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6348 | case PV_GP: return *curbuf->b_p_gp != NUL |
| 6349 | ? (char_u *)&(curbuf->b_p_gp) : p->var; |
| 6350 | case PV_MP: return *curbuf->b_p_mp != NUL |
| 6351 | ? (char_u *)&(curbuf->b_p_mp) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6352 | #endif |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 6353 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 6354 | case PV_BEXPR: return *curbuf->b_p_bexpr != NUL |
| 6355 | ? (char_u *)&(curbuf->b_p_bexpr) : p->var; |
| 6356 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 6357 | #if defined(FEAT_CRYPT) |
| 6358 | case PV_CM: return *curbuf->b_p_cm != NUL |
| 6359 | ? (char_u *)&(curbuf->b_p_cm) : p->var; |
| 6360 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6361 | #ifdef FEAT_LINEBREAK |
| 6362 | case PV_SBR: return *curwin->w_p_sbr != NUL |
| 6363 | ? (char_u *)&(curwin->w_p_sbr) : p->var; |
| 6364 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6365 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6366 | case PV_STL: return *curwin->w_p_stl != NUL |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6367 | ? (char_u *)&(curwin->w_p_stl) : p->var; |
| 6368 | #endif |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 6369 | case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL |
| 6370 | ? (char_u *)&(curbuf->b_p_ul) : p->var; |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 6371 | case PV_LW: return *curbuf->b_p_lw != NUL |
| 6372 | ? (char_u *)&(curbuf->b_p_lw) : p->var; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 6373 | case PV_MENC: return *curbuf->b_p_menc != NUL |
| 6374 | ? (char_u *)&(curbuf->b_p_menc) : p->var; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6375 | #ifdef FEAT_ARABIC |
| 6376 | case PV_ARAB: return (char_u *)&(curwin->w_p_arab); |
| 6377 | #endif |
| 6378 | case PV_LIST: return (char_u *)&(curwin->w_p_list); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6379 | case PV_LCS: return *curwin->w_p_lcs != NUL |
| 6380 | ? (char_u *)&(curwin->w_p_lcs) : p->var; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6381 | case PV_FCS: return *curwin->w_p_fcs != NUL |
| 6382 | ? (char_u *)&(curwin->w_p_fcs) : p->var; |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6383 | case PV_VE: return *curwin->w_p_ve != NUL |
| 6384 | ? (char_u *)&(curwin->w_p_ve) : p->var; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6385 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6386 | case PV_SPELL: return (char_u *)&(curwin->w_p_spell); |
| 6387 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6388 | #ifdef FEAT_SYN_HL |
| 6389 | case PV_CUC: return (char_u *)&(curwin->w_p_cuc); |
| 6390 | case PV_CUL: return (char_u *)&(curwin->w_p_cul); |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6391 | case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6392 | case PV_CC: return (char_u *)&(curwin->w_p_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6393 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6394 | #ifdef FEAT_DIFF |
| 6395 | case PV_DIFF: return (char_u *)&(curwin->w_p_diff); |
| 6396 | #endif |
| 6397 | #ifdef FEAT_FOLDING |
| 6398 | case PV_FDC: return (char_u *)&(curwin->w_p_fdc); |
| 6399 | case PV_FEN: return (char_u *)&(curwin->w_p_fen); |
| 6400 | case PV_FDI: return (char_u *)&(curwin->w_p_fdi); |
| 6401 | case PV_FDL: return (char_u *)&(curwin->w_p_fdl); |
| 6402 | case PV_FDM: return (char_u *)&(curwin->w_p_fdm); |
| 6403 | case PV_FML: return (char_u *)&(curwin->w_p_fml); |
| 6404 | case PV_FDN: return (char_u *)&(curwin->w_p_fdn); |
| 6405 | # ifdef FEAT_EVAL |
| 6406 | case PV_FDE: return (char_u *)&(curwin->w_p_fde); |
| 6407 | case PV_FDT: return (char_u *)&(curwin->w_p_fdt); |
| 6408 | # endif |
| 6409 | case PV_FMR: return (char_u *)&(curwin->w_p_fmr); |
| 6410 | #endif |
| 6411 | case PV_NU: return (char_u *)&(curwin->w_p_nu); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6412 | case PV_RNU: return (char_u *)&(curwin->w_p_rnu); |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6413 | #ifdef FEAT_LINEBREAK |
| 6414 | case PV_NUW: return (char_u *)&(curwin->w_p_nuw); |
| 6415 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6416 | case PV_WFH: return (char_u *)&(curwin->w_p_wfh); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 6417 | case PV_WFW: return (char_u *)&(curwin->w_p_wfw); |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 6418 | #if defined(FEAT_QUICKFIX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6419 | case PV_PVW: return (char_u *)&(curwin->w_p_pvw); |
| 6420 | #endif |
| 6421 | #ifdef FEAT_RIGHTLEFT |
| 6422 | case PV_RL: return (char_u *)&(curwin->w_p_rl); |
| 6423 | case PV_RLC: return (char_u *)&(curwin->w_p_rlc); |
| 6424 | #endif |
| 6425 | case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 6426 | case PV_SMS: return (char_u *)&(curwin->w_p_sms); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6427 | case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); |
| 6428 | #ifdef FEAT_LINEBREAK |
| 6429 | case PV_LBR: return (char_u *)&(curwin->w_p_lbr); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6430 | case PV_BRI: return (char_u *)&(curwin->w_p_bri); |
| 6431 | case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6432 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6433 | case PV_WCR: return (char_u *)&(curwin->w_p_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6434 | case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6435 | case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6436 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6437 | case PV_COCU: return (char_u *)&(curwin->w_p_cocu); |
| 6438 | case PV_COLE: return (char_u *)&(curwin->w_p_cole); |
| 6439 | #endif |
| 6440 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6441 | case PV_TWK: return (char_u *)&(curwin->w_p_twk); |
| 6442 | case PV_TWS: return (char_u *)&(curwin->w_p_tws); |
| 6443 | case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6444 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6445 | |
| 6446 | case PV_AI: return (char_u *)&(curbuf->b_p_ai); |
| 6447 | case PV_BIN: return (char_u *)&(curbuf->b_p_bin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6448 | case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6449 | case PV_BH: return (char_u *)&(curbuf->b_p_bh); |
| 6450 | case PV_BT: return (char_u *)&(curbuf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6451 | case PV_BL: return (char_u *)&(curbuf->b_p_bl); |
| 6452 | case PV_CI: return (char_u *)&(curbuf->b_p_ci); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6453 | case PV_CIN: return (char_u *)&(curbuf->b_p_cin); |
| 6454 | case PV_CINK: return (char_u *)&(curbuf->b_p_cink); |
| 6455 | case PV_CINO: return (char_u *)&(curbuf->b_p_cino); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 6456 | case PV_CINSD: return (char_u *)&(curbuf->b_p_cinsd); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6457 | case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6458 | case PV_COM: return (char_u *)&(curbuf->b_p_com); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6459 | #ifdef FEAT_FOLDING |
| 6460 | case PV_CMS: return (char_u *)&(curbuf->b_p_cms); |
| 6461 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6462 | case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6463 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6464 | case PV_CSL: return (char_u *)&(curbuf->b_p_csl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6465 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6466 | #ifdef FEAT_COMPL_FUNC |
| 6467 | case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6468 | case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6469 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6470 | #ifdef FEAT_EVAL |
| 6471 | case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); |
| 6472 | #endif |
Bram Moolenaar | 3f68a41 | 2022-10-28 17:04:21 +0100 | [diff] [blame] | 6473 | case PV_EOF: return (char_u *)&(curbuf->b_p_eof); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6474 | case PV_EOL: return (char_u *)&(curbuf->b_p_eol); |
Bram Moolenaar | 34d72d4 | 2015-07-17 14:18:08 +0200 | [diff] [blame] | 6475 | case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6476 | case PV_ET: return (char_u *)&(curbuf->b_p_et); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6477 | case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6478 | case PV_FF: return (char_u *)&(curbuf->b_p_ff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6479 | case PV_FT: return (char_u *)&(curbuf->b_p_ft); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6480 | case PV_FO: return (char_u *)&(curbuf->b_p_fo); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 6481 | case PV_FLP: return (char_u *)&(curbuf->b_p_flp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6482 | case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); |
| 6483 | case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); |
| 6484 | case PV_INF: return (char_u *)&(curbuf->b_p_inf); |
| 6485 | case PV_ISK: return (char_u *)&(curbuf->b_p_isk); |
| 6486 | #ifdef FEAT_FIND_ID |
| 6487 | # ifdef FEAT_EVAL |
| 6488 | case PV_INEX: return (char_u *)&(curbuf->b_p_inex); |
| 6489 | # endif |
| 6490 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 6491 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6492 | case PV_INDE: return (char_u *)&(curbuf->b_p_inde); |
| 6493 | case PV_INDK: return (char_u *)&(curbuf->b_p_indk); |
| 6494 | #endif |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6495 | #ifdef FEAT_EVAL |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 6496 | case PV_FEX: return (char_u *)&(curbuf->b_p_fex); |
| 6497 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6498 | #ifdef FEAT_CRYPT |
| 6499 | case PV_KEY: return (char_u *)&(curbuf->b_p_key); |
| 6500 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6501 | case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 6502 | case PV_LOP: return (char_u *)&(curbuf->b_p_lop); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6503 | case PV_ML: return (char_u *)&(curbuf->b_p_ml); |
| 6504 | case PV_MPS: return (char_u *)&(curbuf->b_p_mps); |
| 6505 | case PV_MA: return (char_u *)&(curbuf->b_p_ma); |
| 6506 | case PV_MOD: return (char_u *)&(curbuf->b_changed); |
| 6507 | case PV_NF: return (char_u *)&(curbuf->b_p_nf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6508 | case PV_PI: return (char_u *)&(curbuf->b_p_pi); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6509 | case PV_QE: return (char_u *)&(curbuf->b_p_qe); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6510 | case PV_RO: return (char_u *)&(curbuf->b_p_ro); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6511 | case PV_SI: return (char_u *)&(curbuf->b_p_si); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6512 | case PV_SN: return (char_u *)&(curbuf->b_p_sn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6513 | case PV_STS: return (char_u *)&(curbuf->b_p_sts); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6514 | case PV_SUA: return (char_u *)&(curbuf->b_p_sua); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6515 | case PV_SWF: return (char_u *)&(curbuf->b_p_swf); |
| 6516 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 6517 | case PV_SMC: return (char_u *)&(curbuf->b_p_smc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6518 | case PV_SYN: return (char_u *)&(curbuf->b_p_syn); |
| 6519 | #endif |
| 6520 | #ifdef FEAT_SPELL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 6521 | case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); |
| 6522 | case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); |
| 6523 | case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 6524 | case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6525 | #endif |
| 6526 | case PV_SW: return (char_u *)&(curbuf->b_p_sw); |
| 6527 | case PV_TS: return (char_u *)&(curbuf->b_p_ts); |
| 6528 | case PV_TW: return (char_u *)&(curbuf->b_p_tw); |
| 6529 | case PV_TX: return (char_u *)&(curbuf->b_p_tx); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 6530 | #ifdef FEAT_PERSISTENT_UNDO |
| 6531 | case PV_UDF: return (char_u *)&(curbuf->b_p_udf); |
| 6532 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6533 | case PV_WM: return (char_u *)&(curbuf->b_p_wm); |
| 6534 | #ifdef FEAT_KEYMAP |
| 6535 | case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); |
| 6536 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6537 | #ifdef FEAT_SIGNS |
| 6538 | case PV_SCL: return (char_u *)&(curwin->w_p_scl); |
| 6539 | #endif |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6540 | #ifdef FEAT_VARTABS |
| 6541 | case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); |
| 6542 | case PV_VTS: return (char_u *)&(curbuf->b_p_vts); |
| 6543 | #endif |
RestorerZ | 68ebcee | 2023-05-31 17:12:14 +0100 | [diff] [blame] | 6544 | default: iemsg(e_get_varp_error); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6545 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6546 | // always return a valid pointer to avoid a crash! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6547 | return (char_u *)&(curbuf->b_p_wm); |
| 6548 | } |
| 6549 | |
| 6550 | /* |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6551 | * Return a pointer to the variable for option at 'opt_idx' |
| 6552 | */ |
| 6553 | char_u * |
| 6554 | get_option_var(int opt_idx) |
| 6555 | { |
| 6556 | return options[opt_idx].var; |
| 6557 | } |
| 6558 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6559 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6560 | /* |
| 6561 | * Return the full name of the option at 'opt_idx' |
| 6562 | */ |
| 6563 | char_u * |
| 6564 | get_option_fullname(int opt_idx) |
| 6565 | { |
| 6566 | return (char_u *)options[opt_idx].fullname; |
| 6567 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 6568 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 6569 | |
| 6570 | /* |
Yegappan Lakshmanan | af93691 | 2023-02-20 12:16:39 +0000 | [diff] [blame] | 6571 | * Return the did_set callback function for the option at 'opt_idx' |
| 6572 | */ |
| 6573 | opt_did_set_cb_T |
| 6574 | get_option_did_set_cb(int opt_idx) |
| 6575 | { |
| 6576 | return options[opt_idx].opt_did_set_cb; |
| 6577 | } |
| 6578 | |
| 6579 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6580 | * Get the value of 'equalprg', either the buffer-local one or the global one. |
| 6581 | */ |
| 6582 | char_u * |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6583 | get_equalprg(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6584 | { |
| 6585 | if (*curbuf->b_p_ep == NUL) |
| 6586 | return p_ep; |
| 6587 | return curbuf->b_p_ep; |
| 6588 | } |
| 6589 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6590 | /* |
| 6591 | * Copy options from one window to another. |
| 6592 | * Used when splitting a window. |
| 6593 | */ |
| 6594 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6595 | win_copy_options(win_T *wp_from, win_T *wp_to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6596 | { |
| 6597 | copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); |
| 6598 | copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6599 | after_copy_winopt(wp_to); |
| 6600 | } |
| 6601 | |
| 6602 | /* |
| 6603 | * After copying window options: update variables depending on options. |
| 6604 | */ |
| 6605 | void |
Sean Dewar | 0f7ff85 | 2022-02-12 11:51:25 +0000 | [diff] [blame] | 6606 | after_copy_winopt(win_T *wp) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6607 | { |
| 6608 | #ifdef FEAT_LINEBREAK |
| 6609 | briopt_check(wp); |
Bram Moolenaar | 285ed7e | 2014-08-24 21:39:49 +0200 | [diff] [blame] | 6610 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6611 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 6612 | fill_culopt_flags(NULL, wp); |
| 6613 | check_colorcolumn(wp); |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 6614 | #endif |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6615 | set_listchars_option(wp, wp->w_p_lcs, TRUE); |
| 6616 | set_fillchars_option(wp, wp->w_p_fcs, TRUE); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | static char_u * |
| 6620 | copy_option_val(char_u *val) |
| 6621 | { |
| 6622 | if (val == empty_option) |
| 6623 | return empty_option; // no need to allocate memory |
| 6624 | return vim_strsave(val); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6625 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6626 | |
| 6627 | /* |
| 6628 | * Copy the options from one winopt_T to another. |
| 6629 | * Doesn't free the old option values in "to", use clear_winopt() for that. |
| 6630 | * The 'scroll' option is not copied, because it depends on the window height. |
| 6631 | * The 'previewwindow' option is reset, there can be only one preview window. |
| 6632 | */ |
| 6633 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6634 | copy_winopt(winopt_T *from, winopt_T *to) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6635 | { |
| 6636 | #ifdef FEAT_ARABIC |
| 6637 | to->wo_arab = from->wo_arab; |
| 6638 | #endif |
| 6639 | to->wo_list = from->wo_list; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6640 | to->wo_lcs = copy_option_val(from->wo_lcs); |
| 6641 | to->wo_fcs = copy_option_val(from->wo_fcs); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6642 | to->wo_nu = from->wo_nu; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 6643 | to->wo_rnu = from->wo_rnu; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6644 | to->wo_ve = copy_option_val(from->wo_ve); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6645 | to->wo_ve_flags = from->wo_ve_flags; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 6646 | #ifdef FEAT_LINEBREAK |
| 6647 | to->wo_nuw = from->wo_nuw; |
| 6648 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6649 | #ifdef FEAT_RIGHTLEFT |
| 6650 | to->wo_rl = from->wo_rl; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6651 | to->wo_rlc = copy_option_val(from->wo_rlc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6652 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6653 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6654 | to->wo_sbr = copy_option_val(from->wo_sbr); |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6655 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6656 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6657 | to->wo_stl = copy_option_val(from->wo_stl); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6658 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6659 | to->wo_wrap = from->wo_wrap; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6660 | #ifdef FEAT_DIFF |
| 6661 | to->wo_wrap_save = from->wo_wrap_save; |
| 6662 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6663 | #ifdef FEAT_LINEBREAK |
| 6664 | to->wo_lbr = from->wo_lbr; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6665 | to->wo_bri = from->wo_bri; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6666 | to->wo_briopt = copy_option_val(from->wo_briopt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6667 | #endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6668 | to->wo_wcr = copy_option_val(from->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6669 | to->wo_scb = from->wo_scb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6670 | to->wo_scb_save = from->wo_scb_save; |
Bram Moolenaar | b1fd26d | 2022-10-03 11:23:02 +0100 | [diff] [blame] | 6671 | to->wo_sms = from->wo_sms; |
Bram Moolenaar | 4161dcc | 2010-12-02 15:33:21 +0100 | [diff] [blame] | 6672 | to->wo_crb = from->wo_crb; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6673 | to->wo_crb_save = from->wo_crb_save; |
Christian Brabandt | 4a8eb6e | 2023-08-13 19:43:42 +0200 | [diff] [blame] | 6674 | to->wo_siso = from->wo_siso; |
| 6675 | to->wo_so = from->wo_so; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6676 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 6677 | to->wo_spell = from->wo_spell; |
| 6678 | #endif |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6679 | #ifdef FEAT_SYN_HL |
| 6680 | to->wo_cuc = from->wo_cuc; |
| 6681 | to->wo_cul = from->wo_cul; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6682 | to->wo_culopt = copy_option_val(from->wo_culopt); |
| 6683 | to->wo_cc = copy_option_val(from->wo_cc); |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 6684 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6685 | #ifdef FEAT_DIFF |
| 6686 | to->wo_diff = from->wo_diff; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6687 | to->wo_diff_saved = from->wo_diff_saved; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6688 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6689 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6690 | to->wo_cocu = copy_option_val(from->wo_cocu); |
Bram Moolenaar | d497a30 | 2010-07-23 22:27:03 +0200 | [diff] [blame] | 6691 | to->wo_cole = from->wo_cole; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6692 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6693 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6694 | to->wo_twk = copy_option_val(from->wo_twk); |
| 6695 | to->wo_tws = copy_option_val(from->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6696 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6697 | #ifdef FEAT_FOLDING |
| 6698 | to->wo_fdc = from->wo_fdc; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6699 | to->wo_fdc_save = from->wo_fdc_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6700 | to->wo_fen = from->wo_fen; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6701 | to->wo_fen_save = from->wo_fen_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6702 | to->wo_fdi = copy_option_val(from->wo_fdi); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6703 | to->wo_fml = from->wo_fml; |
| 6704 | to->wo_fdl = from->wo_fdl; |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6705 | to->wo_fdl_save = from->wo_fdl_save; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6706 | to->wo_fdm = copy_option_val(from->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6707 | to->wo_fdm_save = from->wo_diff_saved |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6708 | ? vim_strsave(from->wo_fdm_save) : empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6709 | to->wo_fdn = from->wo_fdn; |
| 6710 | # ifdef FEAT_EVAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6711 | to->wo_fde = copy_option_val(from->wo_fde); |
| 6712 | to->wo_fdt = copy_option_val(from->wo_fdt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6713 | # endif |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6714 | to->wo_fmr = copy_option_val(from->wo_fmr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6715 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6716 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6717 | to->wo_scl = copy_option_val(from->wo_scl); |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6718 | #endif |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6719 | |
| 6720 | #ifdef FEAT_EVAL |
| 6721 | // Copy the script context so that we know where the value was last set. |
| 6722 | mch_memmove(to->wo_script_ctx, from->wo_script_ctx, |
| 6723 | sizeof(to->wo_script_ctx)); |
| 6724 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6725 | check_winopt(to); // don't want NULL pointers |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | /* |
| 6729 | * Check string options in a window for a NULL value. |
| 6730 | */ |
Bram Moolenaar | 5843f5f | 2019-08-20 20:13:45 +0200 | [diff] [blame] | 6731 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6732 | check_win_options(win_T *win) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6733 | { |
| 6734 | check_winopt(&win->w_onebuf_opt); |
| 6735 | check_winopt(&win->w_allbuf_opt); |
| 6736 | } |
| 6737 | |
| 6738 | /* |
| 6739 | * Check for NULL pointers in a winopt_T and replace them with empty_option. |
| 6740 | */ |
Bram Moolenaar | 8dc907d | 2014-06-25 14:44:10 +0200 | [diff] [blame] | 6741 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6742 | check_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6743 | { |
| 6744 | #ifdef FEAT_FOLDING |
| 6745 | check_string_option(&wop->wo_fdi); |
| 6746 | check_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6747 | check_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6748 | # ifdef FEAT_EVAL |
| 6749 | check_string_option(&wop->wo_fde); |
| 6750 | check_string_option(&wop->wo_fdt); |
| 6751 | # endif |
| 6752 | check_string_option(&wop->wo_fmr); |
| 6753 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6754 | #ifdef FEAT_SIGNS |
| 6755 | check_string_option(&wop->wo_scl); |
| 6756 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6757 | #ifdef FEAT_RIGHTLEFT |
| 6758 | check_string_option(&wop->wo_rlc); |
| 6759 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6760 | #ifdef FEAT_LINEBREAK |
| 6761 | check_string_option(&wop->wo_sbr); |
| 6762 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6763 | #ifdef FEAT_STL_OPT |
| 6764 | check_string_option(&wop->wo_stl); |
| 6765 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6766 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6767 | check_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6768 | check_string_option(&wop->wo_cc); |
| 6769 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6770 | #ifdef FEAT_CONCEAL |
| 6771 | check_string_option(&wop->wo_cocu); |
| 6772 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6773 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6774 | check_string_option(&wop->wo_twk); |
| 6775 | check_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6776 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6777 | #ifdef FEAT_LINEBREAK |
| 6778 | check_string_option(&wop->wo_briopt); |
| 6779 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6780 | check_string_option(&wop->wo_wcr); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6781 | check_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6782 | check_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6783 | check_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | /* |
| 6787 | * Free the allocated memory inside a winopt_T. |
| 6788 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6789 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6790 | clear_winopt(winopt_T *wop UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6791 | { |
| 6792 | #ifdef FEAT_FOLDING |
| 6793 | clear_string_option(&wop->wo_fdi); |
| 6794 | clear_string_option(&wop->wo_fdm); |
Bram Moolenaar | a87aa80 | 2013-07-03 15:47:03 +0200 | [diff] [blame] | 6795 | clear_string_option(&wop->wo_fdm_save); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6796 | # ifdef FEAT_EVAL |
| 6797 | clear_string_option(&wop->wo_fde); |
| 6798 | clear_string_option(&wop->wo_fdt); |
| 6799 | # endif |
| 6800 | clear_string_option(&wop->wo_fmr); |
| 6801 | #endif |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 6802 | #ifdef FEAT_SIGNS |
| 6803 | clear_string_option(&wop->wo_scl); |
| 6804 | #endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 6805 | #ifdef FEAT_LINEBREAK |
| 6806 | clear_string_option(&wop->wo_briopt); |
| 6807 | #endif |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 6808 | clear_string_option(&wop->wo_wcr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6809 | #ifdef FEAT_RIGHTLEFT |
| 6810 | clear_string_option(&wop->wo_rlc); |
| 6811 | #endif |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 6812 | #ifdef FEAT_LINEBREAK |
| 6813 | clear_string_option(&wop->wo_sbr); |
| 6814 | #endif |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6815 | #ifdef FEAT_STL_OPT |
| 6816 | clear_string_option(&wop->wo_stl); |
| 6817 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6818 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 410e98a | 2019-09-09 22:05:49 +0200 | [diff] [blame] | 6819 | clear_string_option(&wop->wo_culopt); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 6820 | clear_string_option(&wop->wo_cc); |
| 6821 | #endif |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 6822 | #ifdef FEAT_CONCEAL |
| 6823 | clear_string_option(&wop->wo_cocu); |
| 6824 | #endif |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6825 | #ifdef FEAT_TERMINAL |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 6826 | clear_string_option(&wop->wo_twk); |
| 6827 | clear_string_option(&wop->wo_tws); |
Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 6828 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 6829 | clear_string_option(&wop->wo_lcs); |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 6830 | clear_string_option(&wop->wo_fcs); |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 6831 | clear_string_option(&wop->wo_ve); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6832 | } |
| 6833 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6834 | #ifdef FEAT_EVAL |
| 6835 | // Index into the options table for a buffer-local option enum. |
| 6836 | static int buf_opt_idx[BV_COUNT]; |
| 6837 | # define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].script_ctx |
| 6838 | |
| 6839 | /* |
| 6840 | * Initialize buf_opt_idx[] if not done already. |
| 6841 | */ |
| 6842 | static void |
| 6843 | init_buf_opt_idx(void) |
| 6844 | { |
| 6845 | static int did_init_buf_opt_idx = FALSE; |
| 6846 | int i; |
| 6847 | |
| 6848 | if (did_init_buf_opt_idx) |
| 6849 | return; |
| 6850 | did_init_buf_opt_idx = TRUE; |
| 6851 | for (i = 0; !istermoption_idx(i); i++) |
| 6852 | if (options[i].indir & PV_BUF) |
| 6853 | buf_opt_idx[options[i].indir & PV_MASK] = i; |
| 6854 | } |
| 6855 | #else |
| 6856 | # define COPY_OPT_SCTX(buf, bv) |
| 6857 | #endif |
| 6858 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6859 | /* |
| 6860 | * Copy global option values to local options for one buffer. |
| 6861 | * Used when creating a new buffer and sometimes when entering a buffer. |
| 6862 | * flags: |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6863 | * BCO_ENTER We will enter the buffer "buf". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6864 | * BCO_ALWAYS Always copy the options, but only set b_p_initialized when |
| 6865 | * appropriate. |
| 6866 | * BCO_NOHELP Don't copy the values to a help buffer. |
| 6867 | */ |
| 6868 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 6869 | buf_copy_options(buf_T *buf, int flags) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6870 | { |
| 6871 | int should_copy = TRUE; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6872 | char_u *save_p_isk = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6873 | int dont_do_help; |
| 6874 | int did_isk = FALSE; |
| 6875 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6876 | // Skip this when the option defaults have not been set yet. Happens when |
| 6877 | // main() allocates the first buffer. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6878 | if (p_cpo != NULL) |
| 6879 | { |
| 6880 | /* |
| 6881 | * Always copy when entering and 'cpo' contains 'S'. |
| 6882 | * Don't copy when already initialized. |
| 6883 | * Don't copy when 'cpo' contains 's' and not entering. |
| 6884 | * 'S' BCO_ENTER initialized 's' should_copy |
| 6885 | * yes yes X X TRUE |
| 6886 | * yes no yes X FALSE |
| 6887 | * no X yes X FALSE |
| 6888 | * X no no yes FALSE |
| 6889 | * X no no no TRUE |
| 6890 | * no yes no X TRUE |
| 6891 | */ |
| 6892 | if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) |
| 6893 | && (buf->b_p_initialized |
| 6894 | || (!(flags & BCO_ENTER) |
| 6895 | && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) |
| 6896 | should_copy = FALSE; |
| 6897 | |
| 6898 | if (should_copy || (flags & BCO_ALWAYS)) |
| 6899 | { |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6900 | #ifdef FEAT_EVAL |
Bram Moolenaar | a80faa8 | 2020-04-12 19:37:17 +0200 | [diff] [blame] | 6901 | CLEAR_FIELD(buf->b_p_script_ctx); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6902 | init_buf_opt_idx(); |
| 6903 | #endif |
| 6904 | // Don't copy the options specific to a help buffer when |
| 6905 | // BCO_NOHELP is given or the options were initialized already |
| 6906 | // (jumping back to a help file with CTRL-T or CTRL-O) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6907 | dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) |
| 6908 | || buf->b_p_initialized; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6909 | if (dont_do_help) // don't free b_p_isk |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6910 | { |
| 6911 | save_p_isk = buf->b_p_isk; |
| 6912 | buf->b_p_isk = NULL; |
| 6913 | } |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 6914 | // Always free the allocated strings. If not already initialized, |
| 6915 | // reset 'readonly' and copy 'fileformat'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6916 | if (!buf->b_p_initialized) |
| 6917 | { |
| 6918 | free_buf_options(buf, TRUE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 6919 | buf->b_p_ro = FALSE; // don't copy readonly |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6920 | buf->b_p_tx = p_tx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6921 | buf->b_p_fenc = vim_strsave(p_fenc); |
Bram Moolenaar | e8ef3a0 | 2016-10-12 17:45:29 +0200 | [diff] [blame] | 6922 | switch (*p_ffs) |
| 6923 | { |
| 6924 | case 'm': |
| 6925 | buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break; |
| 6926 | case 'd': |
| 6927 | buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break; |
| 6928 | case 'u': |
| 6929 | buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break; |
| 6930 | default: |
| 6931 | buf->b_p_ff = vim_strsave(p_ff); |
| 6932 | } |
| 6933 | if (buf->b_p_ff != NULL) |
| 6934 | buf->b_start_ffc = *buf->b_p_ff; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6935 | buf->b_p_bh = empty_option; |
| 6936 | buf->b_p_bt = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6937 | } |
| 6938 | else |
| 6939 | free_buf_options(buf, FALSE); |
| 6940 | |
| 6941 | buf->b_p_ai = p_ai; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6942 | COPY_OPT_SCTX(buf, BV_AI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6943 | buf->b_p_ai_nopaste = p_ai_nopaste; |
| 6944 | buf->b_p_sw = p_sw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6945 | COPY_OPT_SCTX(buf, BV_SW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6946 | buf->b_p_tw = p_tw; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6947 | COPY_OPT_SCTX(buf, BV_TW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6948 | buf->b_p_tw_nopaste = p_tw_nopaste; |
| 6949 | buf->b_p_tw_nobin = p_tw_nobin; |
| 6950 | buf->b_p_wm = p_wm; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6951 | COPY_OPT_SCTX(buf, BV_WM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6952 | buf->b_p_wm_nopaste = p_wm_nopaste; |
| 6953 | buf->b_p_wm_nobin = p_wm_nobin; |
| 6954 | buf->b_p_bin = p_bin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6955 | COPY_OPT_SCTX(buf, BV_BIN); |
Bram Moolenaar | e8bb255 | 2005-07-08 22:26:47 +0000 | [diff] [blame] | 6956 | buf->b_p_bomb = p_bomb; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6957 | COPY_OPT_SCTX(buf, BV_BOMB); |
Bram Moolenaar | b388be0 | 2015-07-22 22:19:38 +0200 | [diff] [blame] | 6958 | buf->b_p_fixeol = p_fixeol; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6959 | COPY_OPT_SCTX(buf, BV_FIXEOL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6960 | buf->b_p_et = p_et; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6961 | COPY_OPT_SCTX(buf, BV_ET); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6962 | buf->b_p_et_nobin = p_et_nobin; |
Bram Moolenaar | 54f018c | 2015-09-15 17:30:40 +0200 | [diff] [blame] | 6963 | buf->b_p_et_nopaste = p_et_nopaste; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6964 | buf->b_p_ml = p_ml; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6965 | COPY_OPT_SCTX(buf, BV_ML); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | buf->b_p_ml_nobin = p_ml_nobin; |
| 6967 | buf->b_p_inf = p_inf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6968 | COPY_OPT_SCTX(buf, BV_INF); |
Bram Moolenaar | e100440 | 2020-10-24 20:49:43 +0200 | [diff] [blame] | 6969 | if (cmdmod.cmod_flags & CMOD_NOSWAPFILE) |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6970 | buf->b_p_swf = FALSE; |
| 6971 | else |
| 6972 | { |
| 6973 | buf->b_p_swf = p_swf; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 6974 | COPY_OPT_SCTX(buf, BV_SWF); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6975 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6976 | buf->b_p_cpt = vim_strsave(p_cpt); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6977 | COPY_OPT_SCTX(buf, BV_CPT); |
Bram Moolenaar | e2c453d | 2019-08-21 14:37:09 +0200 | [diff] [blame] | 6978 | #ifdef BACKSLASH_IN_FILENAME |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 6979 | buf->b_p_csl = vim_strsave(p_csl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6980 | COPY_OPT_SCTX(buf, BV_CSL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6981 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6982 | #ifdef FEAT_COMPL_FUNC |
| 6983 | buf->b_p_cfu = vim_strsave(p_cfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6984 | COPY_OPT_SCTX(buf, BV_CFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6985 | set_buflocal_cfu_callback(buf); |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 6986 | buf->b_p_ofu = vim_strsave(p_ofu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6987 | COPY_OPT_SCTX(buf, BV_OFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6988 | set_buflocal_ofu_callback(buf); |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6989 | #endif |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6990 | #ifdef FEAT_EVAL |
| 6991 | buf->b_p_tfu = vim_strsave(p_tfu); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6992 | COPY_OPT_SCTX(buf, BV_TFU); |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 6993 | set_buflocal_tfu_callback(buf); |
Bram Moolenaar | 45e18cb | 2019-04-28 18:05:35 +0200 | [diff] [blame] | 6994 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6995 | buf->b_p_sts = p_sts; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 6996 | COPY_OPT_SCTX(buf, BV_STS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6997 | buf->b_p_sts_nopaste = p_sts_nopaste; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 6998 | #ifdef FEAT_VARTABS |
| 6999 | buf->b_p_vsts = vim_strsave(p_vsts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7000 | COPY_OPT_SCTX(buf, BV_VSTS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7001 | if (p_vsts && p_vsts != empty_option) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7002 | (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7003 | else |
Bram Moolenaar | 652dee4 | 2022-01-28 20:47:49 +0000 | [diff] [blame] | 7004 | buf->b_p_vsts_array = NULL; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7005 | buf->b_p_vsts_nopaste = p_vsts_nopaste |
| 7006 | ? vim_strsave(p_vsts_nopaste) : NULL; |
| 7007 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7008 | buf->b_p_sn = p_sn; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7009 | COPY_OPT_SCTX(buf, BV_SN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7010 | buf->b_p_com = vim_strsave(p_com); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7011 | COPY_OPT_SCTX(buf, BV_COM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7012 | #ifdef FEAT_FOLDING |
| 7013 | buf->b_p_cms = vim_strsave(p_cms); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7014 | COPY_OPT_SCTX(buf, BV_CMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7015 | #endif |
| 7016 | buf->b_p_fo = vim_strsave(p_fo); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7017 | COPY_OPT_SCTX(buf, BV_FO); |
Bram Moolenaar | 86b6835 | 2004-12-27 21:59:20 +0000 | [diff] [blame] | 7018 | buf->b_p_flp = vim_strsave(p_flp); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7019 | COPY_OPT_SCTX(buf, BV_FLP); |
Bram Moolenaar | 473952e | 2019-09-28 16:30:04 +0200 | [diff] [blame] | 7020 | // NOTE: Valgrind may report a bogus memory leak for 'nrformats' |
| 7021 | // when it is set to 8 bytes in defaults.vim. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7022 | buf->b_p_nf = vim_strsave(p_nf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7023 | COPY_OPT_SCTX(buf, BV_NF); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7024 | buf->b_p_mps = vim_strsave(p_mps); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7025 | COPY_OPT_SCTX(buf, BV_MPS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7026 | buf->b_p_si = p_si; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7027 | COPY_OPT_SCTX(buf, BV_SI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7028 | buf->b_p_ci = p_ci; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7029 | COPY_OPT_SCTX(buf, BV_CI); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7030 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7031 | buf->b_p_cin = p_cin; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7032 | COPY_OPT_SCTX(buf, BV_CIN); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7033 | buf->b_p_cink = vim_strsave(p_cink); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7034 | COPY_OPT_SCTX(buf, BV_CINK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7035 | buf->b_p_cino = vim_strsave(p_cino); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7036 | COPY_OPT_SCTX(buf, BV_CINO); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 7037 | buf->b_p_cinsd = vim_strsave(p_cinsd); |
| 7038 | COPY_OPT_SCTX(buf, BV_CINSD); |
Bram Moolenaar | 49846fb | 2022-10-15 16:05:33 +0100 | [diff] [blame] | 7039 | buf->b_p_lop = vim_strsave(p_lop); |
| 7040 | COPY_OPT_SCTX(buf, BV_LOP); |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7041 | |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7042 | // Don't copy 'filetype', it must be detected |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7043 | buf->b_p_ft = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7044 | buf->b_p_pi = p_pi; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7045 | COPY_OPT_SCTX(buf, BV_PI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7046 | buf->b_p_cinw = vim_strsave(p_cinw); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7047 | COPY_OPT_SCTX(buf, BV_CINW); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7048 | buf->b_p_lisp = p_lisp; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7049 | COPY_OPT_SCTX(buf, BV_LISP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7050 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7051 | // Don't copy 'syntax', it must be set |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7052 | buf->b_p_syn = empty_option; |
Bram Moolenaar | 3b56eb3 | 2005-07-11 22:40:32 +0000 | [diff] [blame] | 7053 | buf->b_p_smc = p_smc; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7054 | COPY_OPT_SCTX(buf, BV_SMC); |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 7055 | buf->b_s.b_syn_isk = empty_option; |
Bram Moolenaar | b9a02fc | 2006-03-12 22:08:12 +0000 | [diff] [blame] | 7056 | #endif |
| 7057 | #ifdef FEAT_SPELL |
Bram Moolenaar | d5784f9 | 2010-10-13 14:05:35 +0200 | [diff] [blame] | 7058 | buf->b_s.b_p_spc = vim_strsave(p_spc); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7059 | COPY_OPT_SCTX(buf, BV_SPC); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 7060 | (void)compile_cap_prog(&buf->b_s); |
| 7061 | buf->b_s.b_p_spf = vim_strsave(p_spf); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7062 | COPY_OPT_SCTX(buf, BV_SPF); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 7063 | buf->b_s.b_p_spl = vim_strsave(p_spl); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7064 | COPY_OPT_SCTX(buf, BV_SPL); |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 7065 | buf->b_s.b_p_spo = vim_strsave(p_spo); |
| 7066 | COPY_OPT_SCTX(buf, BV_SPO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7067 | #endif |
Bram Moolenaar | 8e145b8 | 2022-05-21 20:17:31 +0100 | [diff] [blame] | 7068 | #if defined(FEAT_EVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7069 | buf->b_p_inde = vim_strsave(p_inde); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7070 | COPY_OPT_SCTX(buf, BV_INDE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7071 | buf->b_p_indk = vim_strsave(p_indk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7072 | COPY_OPT_SCTX(buf, BV_INDK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7073 | #endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 7074 | buf->b_p_fp = empty_option; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 7075 | #if defined(FEAT_EVAL) |
| 7076 | buf->b_p_fex = vim_strsave(p_fex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7077 | COPY_OPT_SCTX(buf, BV_FEX); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 7078 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7079 | #ifdef FEAT_CRYPT |
| 7080 | buf->b_p_key = vim_strsave(p_key); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7081 | COPY_OPT_SCTX(buf, BV_KEY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7082 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7083 | buf->b_p_sua = vim_strsave(p_sua); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7084 | COPY_OPT_SCTX(buf, BV_SUA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7085 | #ifdef FEAT_KEYMAP |
| 7086 | buf->b_p_keymap = vim_strsave(p_keymap); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7087 | COPY_OPT_SCTX(buf, BV_KMAP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7088 | buf->b_kmap_state |= KEYMAP_INIT; |
| 7089 | #endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 7090 | #ifdef FEAT_TERMINAL |
| 7091 | buf->b_p_twsl = p_twsl; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7092 | COPY_OPT_SCTX(buf, BV_TWSL); |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 7093 | #endif |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7094 | // This isn't really an option, but copying the langmap and IME |
| 7095 | // state from the current buffer is better than resetting it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7096 | buf->b_p_iminsert = p_iminsert; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7097 | COPY_OPT_SCTX(buf, BV_IMI); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7098 | buf->b_p_imsearch = p_imsearch; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7099 | COPY_OPT_SCTX(buf, BV_IMS); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7100 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7101 | // options that are normally global but also have a local value |
| 7102 | // are not copied, start using the global value |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7103 | buf->b_p_ar = -1; |
Bram Moolenaar | f5a2fd8 | 2013-11-06 05:26:15 +0100 | [diff] [blame] | 7104 | buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 7105 | buf->b_p_bkc = empty_option; |
| 7106 | buf->b_bkc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7107 | #ifdef FEAT_QUICKFIX |
| 7108 | buf->b_p_gp = empty_option; |
| 7109 | buf->b_p_mp = empty_option; |
| 7110 | buf->b_p_efm = empty_option; |
| 7111 | #endif |
| 7112 | buf->b_p_ep = empty_option; |
| 7113 | buf->b_p_kp = empty_option; |
| 7114 | buf->b_p_path = empty_option; |
| 7115 | buf->b_p_tags = empty_option; |
Bram Moolenaar | 0f6562e | 2015-11-24 18:48:14 +0100 | [diff] [blame] | 7116 | buf->b_p_tc = empty_option; |
| 7117 | buf->b_tc_flags = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7118 | #ifdef FEAT_FIND_ID |
| 7119 | buf->b_p_def = empty_option; |
| 7120 | buf->b_p_inc = empty_option; |
| 7121 | # ifdef FEAT_EVAL |
| 7122 | buf->b_p_inex = vim_strsave(p_inex); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7123 | COPY_OPT_SCTX(buf, BV_INEX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7124 | # endif |
| 7125 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7126 | buf->b_p_dict = empty_option; |
| 7127 | buf->b_p_tsr = empty_option; |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 7128 | #ifdef FEAT_COMPL_FUNC |
| 7129 | buf->b_p_tsrfu = empty_option; |
| 7130 | #endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 7131 | buf->b_p_qe = vim_strsave(p_qe); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7132 | COPY_OPT_SCTX(buf, BV_QE); |
Bram Moolenaar | 9b2200a | 2006-03-20 21:55:45 +0000 | [diff] [blame] | 7133 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 7134 | buf->b_p_bexpr = empty_option; |
| 7135 | #endif |
Bram Moolenaar | 49771f4 | 2010-07-20 17:32:38 +0200 | [diff] [blame] | 7136 | #if defined(FEAT_CRYPT) |
| 7137 | buf->b_p_cm = empty_option; |
| 7138 | #endif |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7139 | #ifdef FEAT_PERSISTENT_UNDO |
| 7140 | buf->b_p_udf = p_udf; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7141 | COPY_OPT_SCTX(buf, BV_UDF); |
Bram Moolenaar | 55debbe | 2010-05-23 23:34:36 +0200 | [diff] [blame] | 7142 | #endif |
Bram Moolenaar | af6c131 | 2014-03-12 18:55:58 +0100 | [diff] [blame] | 7143 | buf->b_p_lw = empty_option; |
Bram Moolenaar | 2c7292d | 2017-03-05 17:43:31 +0100 | [diff] [blame] | 7144 | buf->b_p_menc = empty_option; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7145 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7146 | // Don't copy the options set by ex_help(), use the saved values, |
| 7147 | // when going from a help buffer to a non-help buffer. |
| 7148 | // Don't touch these at all when BCO_NOHELP is used and going from |
| 7149 | // or to a help buffer. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7150 | if (dont_do_help) |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7151 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7152 | buf->b_p_isk = save_p_isk; |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7153 | #ifdef FEAT_VARTABS |
Yegappan Lakshmanan | 960dcbd | 2023-03-07 17:45:11 +0000 | [diff] [blame] | 7154 | if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7155 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7156 | else |
| 7157 | buf->b_p_vts_array = NULL; |
| 7158 | #endif |
| 7159 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7160 | else |
| 7161 | { |
| 7162 | buf->b_p_isk = vim_strsave(p_isk); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7163 | COPY_OPT_SCTX(buf, BV_ISK); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7164 | did_isk = TRUE; |
| 7165 | buf->b_p_ts = p_ts; |
Bram Moolenaar | 6206877 | 2021-12-14 09:01:38 +0000 | [diff] [blame] | 7166 | COPY_OPT_SCTX(buf, BV_TS); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7167 | #ifdef FEAT_VARTABS |
| 7168 | buf->b_p_vts = vim_strsave(p_vts); |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7169 | COPY_OPT_SCTX(buf, BV_VTS); |
Yegappan Lakshmanan | 960dcbd | 2023-03-07 17:45:11 +0000 | [diff] [blame] | 7170 | if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 7171 | (void)tabstop_set(p_vts, &buf->b_p_vts_array); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 7172 | else |
| 7173 | buf->b_p_vts_array = NULL; |
| 7174 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7175 | buf->b_help = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7176 | if (buf->b_p_bt[0] == 'h') |
| 7177 | clear_string_option(&buf->b_p_bt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7178 | buf->b_p_ma = p_ma; |
Bram Moolenaar | cfb3814 | 2019-10-19 20:18:47 +0200 | [diff] [blame] | 7179 | COPY_OPT_SCTX(buf, BV_MA); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7180 | } |
| 7181 | } |
| 7182 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7183 | // When the options should be copied (ignoring BCO_ALWAYS), set the |
| 7184 | // flag that indicates that the options have been initialized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7185 | if (should_copy) |
| 7186 | buf->b_p_initialized = TRUE; |
| 7187 | } |
| 7188 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7189 | check_buf_options(buf); // make sure we don't have NULLs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7190 | if (did_isk) |
| 7191 | (void)buf_init_chartab(buf, FALSE); |
| 7192 | } |
| 7193 | |
| 7194 | /* |
| 7195 | * Reset the 'modifiable' option and its default value. |
| 7196 | */ |
| 7197 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7198 | reset_modifiable(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7199 | { |
| 7200 | int opt_idx; |
| 7201 | |
| 7202 | curbuf->b_p_ma = FALSE; |
| 7203 | p_ma = FALSE; |
| 7204 | opt_idx = findoption((char_u *)"ma"); |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 7205 | if (opt_idx >= 0) |
| 7206 | options[opt_idx].def_val[VI_DEFAULT] = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | /* |
| 7210 | * Set the global value for 'iminsert' to the local value. |
| 7211 | */ |
| 7212 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7213 | set_iminsert_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7214 | { |
| 7215 | p_iminsert = curbuf->b_p_iminsert; |
| 7216 | } |
| 7217 | |
| 7218 | /* |
| 7219 | * Set the global value for 'imsearch' to the local value. |
| 7220 | */ |
| 7221 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7222 | set_imsearch_global(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7223 | { |
| 7224 | p_imsearch = curbuf->b_p_imsearch; |
| 7225 | } |
| 7226 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7227 | static int expand_option_idx = -1; |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7228 | static int expand_option_start_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7229 | static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; |
| 7230 | static int expand_option_flags = 0; |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7231 | static int expand_option_append = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7232 | |
| 7233 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7234 | set_context_in_set_cmd( |
| 7235 | expand_T *xp, |
| 7236 | char_u *arg, |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7237 | int opt_flags) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7238 | { |
| 7239 | int nextchar; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7240 | long_u flags = 0; // init for GCC |
| 7241 | int opt_idx = 0; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7242 | char_u *p; |
| 7243 | char_u *s; |
| 7244 | int is_term_option = FALSE; |
| 7245 | int key; |
| 7246 | |
| 7247 | expand_option_flags = opt_flags; |
| 7248 | |
| 7249 | xp->xp_context = EXPAND_SETTINGS; |
| 7250 | if (*arg == NUL) |
| 7251 | { |
| 7252 | xp->xp_pattern = arg; |
| 7253 | return; |
| 7254 | } |
| 7255 | p = arg + STRLEN(arg) - 1; |
| 7256 | if (*p == ' ' && *(p - 1) != '\\') |
| 7257 | { |
| 7258 | xp->xp_pattern = p + 1; |
| 7259 | return; |
| 7260 | } |
| 7261 | while (p > arg) |
| 7262 | { |
| 7263 | s = p; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7264 | // count number of backslashes before ' ' or ',' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7265 | if (*p == ' ' || *p == ',') |
| 7266 | { |
| 7267 | while (s > arg && *(s - 1) == '\\') |
| 7268 | --s; |
| 7269 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7270 | // break at a space with an even number of backslashes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7271 | if (*p == ' ' && ((p - s) & 1) == 0) |
| 7272 | { |
| 7273 | ++p; |
| 7274 | break; |
| 7275 | } |
| 7276 | --p; |
| 7277 | } |
Bram Moolenaar | 2a7b9ee | 2009-06-16 15:50:33 +0000 | [diff] [blame] | 7278 | if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7279 | { |
| 7280 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7281 | xp->xp_prefix = XP_PREFIX_NO; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7282 | p += 2; |
| 7283 | } |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7284 | else if (STRNCMP(p, "inv", 3) == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7285 | { |
| 7286 | xp->xp_context = EXPAND_BOOL_SETTINGS; |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7287 | xp->xp_prefix = XP_PREFIX_INV; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | p += 3; |
| 7289 | } |
| 7290 | xp->xp_pattern = arg = p; |
| 7291 | if (*arg == '<') |
| 7292 | { |
| 7293 | while (*p != '>') |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7294 | if (*p++ == NUL) // expand terminal option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7295 | return; |
| 7296 | key = get_special_key_code(arg + 1); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7297 | if (key == 0) // unknown name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7298 | { |
| 7299 | xp->xp_context = EXPAND_NOTHING; |
| 7300 | return; |
| 7301 | } |
| 7302 | nextchar = *++p; |
| 7303 | is_term_option = TRUE; |
| 7304 | expand_option_name[2] = KEY2TERMCAP0(key); |
| 7305 | expand_option_name[3] = KEY2TERMCAP1(key); |
| 7306 | } |
| 7307 | else |
| 7308 | { |
| 7309 | if (p[0] == 't' && p[1] == '_') |
| 7310 | { |
| 7311 | p += 2; |
| 7312 | if (*p != NUL) |
| 7313 | ++p; |
| 7314 | if (*p == NUL) |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7315 | return; // expand option name |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7316 | nextchar = *++p; |
| 7317 | is_term_option = TRUE; |
| 7318 | expand_option_name[2] = p[-2]; |
| 7319 | expand_option_name[3] = p[-1]; |
| 7320 | } |
| 7321 | else |
| 7322 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7323 | // Allow * wildcard |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7324 | while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') |
| 7325 | p++; |
| 7326 | if (*p == NUL) |
| 7327 | return; |
| 7328 | nextchar = *p; |
| 7329 | *p = NUL; |
| 7330 | opt_idx = findoption(arg); |
| 7331 | *p = nextchar; |
| 7332 | if (opt_idx == -1 || options[opt_idx].var == NULL) |
| 7333 | { |
| 7334 | xp->xp_context = EXPAND_NOTHING; |
| 7335 | return; |
| 7336 | } |
| 7337 | flags = options[opt_idx].flags; |
| 7338 | if (flags & P_BOOL) |
| 7339 | { |
| 7340 | xp->xp_context = EXPAND_NOTHING; |
| 7341 | return; |
| 7342 | } |
| 7343 | } |
| 7344 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7345 | // handle "-=" and "+=" |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7346 | expand_option_append = FALSE; |
| 7347 | int expand_option_subtract = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7348 | if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') |
| 7349 | { |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7350 | if (nextchar == '-') |
| 7351 | expand_option_subtract = TRUE; |
| 7352 | if (nextchar == '+' || nextchar == '^') |
| 7353 | expand_option_append = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7354 | ++p; |
| 7355 | nextchar = '='; |
| 7356 | } |
| 7357 | if ((nextchar != '=' && nextchar != ':') |
| 7358 | || xp->xp_context == EXPAND_BOOL_SETTINGS) |
| 7359 | { |
| 7360 | xp->xp_context = EXPAND_UNSUCCESSFUL; |
| 7361 | return; |
| 7362 | } |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7363 | |
| 7364 | // Below are for handling expanding a specific option's value after the '=' |
| 7365 | // or ':' |
| 7366 | |
| 7367 | if (is_term_option) |
| 7368 | expand_option_idx = -1; |
| 7369 | else |
| 7370 | expand_option_idx = opt_idx; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7371 | |
Yee Cheng Chin | 6ee7b52 | 2023-10-01 09:13:22 +0200 | [diff] [blame] | 7372 | if (!is_term_option) |
| 7373 | { |
| 7374 | if (options[opt_idx].flags & P_NO_CMD_EXPAND) |
| 7375 | { |
| 7376 | xp->xp_context=EXPAND_UNSUCCESSFUL; |
| 7377 | return; |
| 7378 | } |
| 7379 | } |
| 7380 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7381 | xp->xp_pattern = p + 1; |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7382 | expand_option_start_col = (int)(p + 1 - xp->xp_line); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7383 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7384 | // Certain options currently have special case handling to reuse the |
| 7385 | // expansion logic with other commands. |
Doug Kearns | 6dfdff3 | 2023-08-27 18:48:51 +0200 | [diff] [blame] | 7386 | #ifdef FEAT_SYN_HL |
| 7387 | if (options[opt_idx].var == (char_u *)&p_syn) |
| 7388 | { |
| 7389 | xp->xp_context = EXPAND_OWNSYNTAX; |
| 7390 | return; |
| 7391 | } |
| 7392 | #endif |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7393 | if (options[opt_idx].var == (char_u *)&p_ft) |
| 7394 | { |
| 7395 | xp->xp_context = EXPAND_FILETYPE; |
| 7396 | return; |
| 7397 | } |
Doug Kearns | 6dfdff3 | 2023-08-27 18:48:51 +0200 | [diff] [blame] | 7398 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7399 | // Now pick. If the option has a custom expander, use that. Otherwise, just |
| 7400 | // fill with the existing option value. |
| 7401 | if (expand_option_subtract) |
| 7402 | { |
| 7403 | xp->xp_context = EXPAND_SETTING_SUBTRACT; |
| 7404 | return; |
| 7405 | } |
| 7406 | else if (expand_option_idx >= 0 && |
| 7407 | options[expand_option_idx].opt_expand_cb != NULL) |
| 7408 | { |
| 7409 | xp->xp_context = EXPAND_STRING_SETTING; |
| 7410 | } |
| 7411 | else if (*xp->xp_pattern == NUL) |
| 7412 | { |
| 7413 | xp->xp_context = EXPAND_OLD_SETTING; |
| 7414 | return; |
| 7415 | } |
| 7416 | else |
| 7417 | xp->xp_context = EXPAND_NOTHING; |
| 7418 | |
| 7419 | if (is_term_option || (flags & P_NUM)) |
| 7420 | return; |
| 7421 | |
| 7422 | // Only string options below |
| 7423 | |
| 7424 | // Options that have P_EXPAND are considered to all use file/dir expansion. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7425 | if (flags & P_EXPAND) |
| 7426 | { |
| 7427 | p = options[opt_idx].var; |
| 7428 | if (p == (char_u *)&p_bdir |
| 7429 | || p == (char_u *)&p_dir |
| 7430 | || p == (char_u *)&p_path |
Bram Moolenaar | f6fee0e | 2016-02-21 23:02:49 +0100 | [diff] [blame] | 7431 | || p == (char_u *)&p_pp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7432 | || p == (char_u *)&p_rtp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7433 | || p == (char_u *)&p_cdpath |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7434 | #ifdef FEAT_SESSION |
| 7435 | || p == (char_u *)&p_vdir |
| 7436 | #endif |
| 7437 | ) |
| 7438 | { |
| 7439 | xp->xp_context = EXPAND_DIRECTORIES; |
Bram Moolenaar | f80f40a | 2022-08-25 16:02:23 +0100 | [diff] [blame] | 7440 | if (p == (char_u *)&p_path || p == (char_u *)&p_cdpath) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7441 | xp->xp_backslash = XP_BS_THREE; |
| 7442 | else |
| 7443 | xp->xp_backslash = XP_BS_ONE; |
| 7444 | } |
| 7445 | else |
| 7446 | { |
| 7447 | xp->xp_context = EXPAND_FILES; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7448 | // for 'tags' need three backslashes for a space |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7449 | if (p == (char_u *)&p_tags) |
| 7450 | xp->xp_backslash = XP_BS_THREE; |
| 7451 | else |
| 7452 | xp->xp_backslash = XP_BS_ONE; |
| 7453 | } |
| 7454 | } |
| 7455 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7456 | // For an option that is a list of file names, or comma/colon-separated |
| 7457 | // values, split it by the delimiter and find the start of the current |
| 7458 | // pattern, while accounting for backslash-escaped space/commas/colons. |
| 7459 | // Triple-backslashed escaped file names (e.g. 'path') can also be |
| 7460 | // delimited by space. |
| 7461 | if ((flags & P_EXPAND) || (flags & P_COMMA) || (flags & P_COLON)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7462 | { |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7463 | for (p = arg + STRLEN(arg) - 1; p >= xp->xp_pattern; --p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7464 | { |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7465 | // count number of backslashes before ' ' or ',' or ':' |
| 7466 | if (*p == ' ' || *p == ',' || |
| 7467 | (*p == ':' && (flags & P_COLON))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7468 | { |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7469 | s = p; |
| 7470 | while (s > xp->xp_pattern && *(s - 1) == '\\') |
| 7471 | --s; |
| 7472 | if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) |
| 7473 | || (*p == ',' && (flags & P_COMMA) && ((p - s) % 1) == 0) |
| 7474 | || (*p == ':' && (flags & P_COLON))) |
| 7475 | { |
| 7476 | xp->xp_pattern = p + 1; |
| 7477 | break; |
| 7478 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7479 | } |
| 7480 | } |
| 7481 | } |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7482 | |
| 7483 | // An option that is a list of single-character flags should always start |
| 7484 | // at the end as we don't complete words. |
| 7485 | if (flags & P_FLAGLIST) |
| 7486 | xp->xp_pattern = arg + STRLEN(arg); |
| 7487 | |
| 7488 | // Some options can either be using file/dir expansions, or custom value |
| 7489 | // expansion depending on what the user typed. Unfortunately we have to |
| 7490 | // manually handle it here to make sure we have the correct xp_context set. |
| 7491 | #ifdef FEAT_SPELL |
| 7492 | if (options[opt_idx].var == (char_u *)&p_sps) |
| 7493 | { |
| 7494 | if (STRNCMP(xp->xp_pattern, "file:", 5) == 0) |
| 7495 | { |
| 7496 | xp->xp_pattern += 5; |
| 7497 | return; |
| 7498 | } |
| 7499 | else if (options[expand_option_idx].opt_expand_cb != NULL) |
| 7500 | { |
| 7501 | xp->xp_context = EXPAND_STRING_SETTING; |
| 7502 | } |
| 7503 | } |
| 7504 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7507 | /* |
| 7508 | * Returns TRUE if 'str' either matches 'regmatch' or fuzzy matches 'pat'. |
| 7509 | * |
| 7510 | * If 'test_only' is TRUE and 'fuzzy' is FALSE and if 'str' matches the regular |
| 7511 | * expression 'regmatch', then returns TRUE. Otherwise returns FALSE. |
| 7512 | * |
| 7513 | * If 'test_only' is FALSE and 'fuzzy' is FALSE and if 'str' matches the |
| 7514 | * regular expression 'regmatch', then stores the match in matches[idx] and |
| 7515 | * returns TRUE. |
| 7516 | * |
| 7517 | * If 'test_only' is TRUE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7518 | * 'fuzzystr', then returns TRUE. Otherwise returns FALSE. |
| 7519 | * |
| 7520 | * If 'test_only' is FALSE and 'fuzzy' is TRUE and if 'str' fuzzy matches |
| 7521 | * 'fuzzystr', then stores the match details in fuzmatch[idx] and returns TRUE. |
| 7522 | */ |
Yee Cheng Chin | f7f746b | 2023-09-30 12:28:50 +0200 | [diff] [blame] | 7523 | static int |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7524 | match_str( |
| 7525 | char_u *str, |
| 7526 | regmatch_T *regmatch, |
| 7527 | char_u **matches, |
| 7528 | int idx, |
| 7529 | int test_only, |
| 7530 | int fuzzy, |
| 7531 | char_u *fuzzystr, |
| 7532 | fuzmatch_str_T *fuzmatch) |
| 7533 | { |
| 7534 | if (!fuzzy) |
| 7535 | { |
| 7536 | if (vim_regexec(regmatch, str, (colnr_T)0)) |
| 7537 | { |
| 7538 | if (!test_only) |
| 7539 | matches[idx] = vim_strsave(str); |
| 7540 | return TRUE; |
| 7541 | } |
| 7542 | } |
| 7543 | else |
| 7544 | { |
| 7545 | int score; |
| 7546 | |
| 7547 | score = fuzzy_match_str(str, fuzzystr); |
| 7548 | if (score != 0) |
| 7549 | { |
| 7550 | if (!test_only) |
| 7551 | { |
| 7552 | fuzmatch[idx].idx = idx; |
| 7553 | fuzmatch[idx].str = vim_strsave(str); |
| 7554 | fuzmatch[idx].score = score; |
| 7555 | } |
| 7556 | |
| 7557 | return TRUE; |
| 7558 | } |
| 7559 | } |
| 7560 | |
| 7561 | return FALSE; |
| 7562 | } |
| 7563 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7564 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 7565 | ExpandSettings( |
| 7566 | expand_T *xp, |
| 7567 | regmatch_T *regmatch, |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7568 | char_u *fuzzystr, |
| 7569 | int *numMatches, |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7570 | char_u ***matches, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7571 | int can_fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7572 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7573 | int num_normal = 0; // Nr of matching non-term-code settings |
| 7574 | int num_term = 0; // Nr of matching terminal code settings |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7575 | int opt_idx; |
| 7576 | int match; |
| 7577 | int count = 0; |
| 7578 | char_u *str; |
| 7579 | int loop; |
| 7580 | int is_term_opt; |
| 7581 | char_u name_buf[MAX_KEY_NAME_LEN]; |
| 7582 | static char *(names[]) = {"all", "termcap"}; |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7583 | int ic = regmatch->rm_ic; // remember the ignore-case flag |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7584 | int fuzzy; |
| 7585 | fuzmatch_str_T *fuzmatch = NULL; |
| 7586 | |
Christian Brabandt | cb74789 | 2022-05-08 21:10:56 +0100 | [diff] [blame] | 7587 | fuzzy = can_fuzzy && cmdline_fuzzy_complete(fuzzystr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7588 | |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7589 | // do this loop twice: |
| 7590 | // loop == 0: count the number of matching options |
| 7591 | // loop == 1: copy the matching options into allocated memory |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7592 | for (loop = 0; loop <= 1; ++loop) |
| 7593 | { |
| 7594 | regmatch->rm_ic = ic; |
| 7595 | if (xp->xp_context != EXPAND_BOOL_SETTINGS) |
| 7596 | { |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 7597 | for (match = 0; match < (int)ARRAY_LENGTH(names); ++match) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7598 | { |
| 7599 | if (match_str((char_u *)names[match], regmatch, *matches, |
| 7600 | count, (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7601 | { |
| 7602 | if (loop == 0) |
| 7603 | num_normal++; |
| 7604 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7605 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7606 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7607 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7608 | } |
| 7609 | for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; |
| 7610 | opt_idx++) |
| 7611 | { |
| 7612 | if (options[opt_idx].var == NULL) |
| 7613 | continue; |
| 7614 | if (xp->xp_context == EXPAND_BOOL_SETTINGS |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7615 | && !(options[opt_idx].flags & P_BOOL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7616 | continue; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 7617 | is_term_opt = istermoption_idx(opt_idx); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7618 | if (is_term_opt && num_normal > 0) |
| 7619 | continue; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7620 | |
| 7621 | if (match_str(str, regmatch, *matches, count, (loop == 0), |
| 7622 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7623 | { |
| 7624 | if (loop == 0) |
| 7625 | { |
| 7626 | if (is_term_opt) |
| 7627 | num_term++; |
| 7628 | else |
| 7629 | num_normal++; |
| 7630 | } |
| 7631 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7632 | count++; |
| 7633 | } |
| 7634 | else if (!fuzzy && options[opt_idx].shortname != NULL |
| 7635 | && vim_regexec(regmatch, |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 7636 | (char_u *)options[opt_idx].shortname, (colnr_T)0)) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7637 | { |
| 7638 | // Compare against the abbreviated option name (for regular |
| 7639 | // expression match). Fuzzy matching (previous if) already |
| 7640 | // matches against both the expanded and abbreviated names. |
| 7641 | if (loop == 0) |
| 7642 | { |
| 7643 | if (is_term_opt) |
| 7644 | num_term++; |
| 7645 | else |
| 7646 | num_normal++; |
| 7647 | } |
| 7648 | else |
| 7649 | (*matches)[count++] = vim_strsave(str); |
| 7650 | } |
| 7651 | else if (is_term_opt) |
| 7652 | { |
| 7653 | name_buf[0] = '<'; |
| 7654 | name_buf[1] = 't'; |
| 7655 | name_buf[2] = '_'; |
| 7656 | name_buf[3] = str[2]; |
| 7657 | name_buf[4] = str[3]; |
| 7658 | name_buf[5] = '>'; |
| 7659 | name_buf[6] = NUL; |
| 7660 | |
| 7661 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7662 | fuzzy, fuzzystr, fuzmatch)) |
| 7663 | { |
| 7664 | if (loop == 0) |
| 7665 | num_term++; |
| 7666 | else |
| 7667 | count++; |
| 7668 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7669 | } |
| 7670 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7671 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7672 | // Check terminal key codes, these are not in the option table |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7673 | if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) |
| 7674 | { |
| 7675 | for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) |
| 7676 | { |
| 7677 | if (!isprint(str[0]) || !isprint(str[1])) |
| 7678 | continue; |
| 7679 | |
| 7680 | name_buf[0] = 't'; |
| 7681 | name_buf[1] = '_'; |
| 7682 | name_buf[2] = str[0]; |
| 7683 | name_buf[3] = str[1]; |
| 7684 | name_buf[4] = NUL; |
| 7685 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7686 | if (match_str(name_buf, regmatch, *matches, count, |
Bram Moolenaar | 048d9d2 | 2023-05-06 22:21:11 +0100 | [diff] [blame] | 7687 | (loop == 0), fuzzy, fuzzystr, fuzmatch)) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7688 | { |
| 7689 | if (loop == 0) |
| 7690 | num_term++; |
| 7691 | else |
| 7692 | count++; |
| 7693 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7694 | else |
| 7695 | { |
| 7696 | name_buf[0] = '<'; |
| 7697 | name_buf[1] = 't'; |
| 7698 | name_buf[2] = '_'; |
| 7699 | name_buf[3] = str[0]; |
| 7700 | name_buf[4] = str[1]; |
| 7701 | name_buf[5] = '>'; |
| 7702 | name_buf[6] = NUL; |
| 7703 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7704 | if (match_str(name_buf, regmatch, *matches, count, |
| 7705 | (loop == 0), fuzzy, fuzzystr, |
| 7706 | fuzmatch)) |
| 7707 | { |
| 7708 | if (loop == 0) |
| 7709 | num_term++; |
| 7710 | else |
| 7711 | count++; |
| 7712 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7713 | } |
| 7714 | } |
| 7715 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7716 | // Check special key names. |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7717 | regmatch->rm_ic = TRUE; // ignore case here |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7718 | for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) |
| 7719 | { |
| 7720 | name_buf[0] = '<'; |
| 7721 | STRCPY(name_buf + 1, str); |
| 7722 | STRCAT(name_buf, ">"); |
| 7723 | |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7724 | if (match_str(name_buf, regmatch, *matches, count, (loop == 0), |
| 7725 | fuzzy, fuzzystr, fuzmatch)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7726 | { |
| 7727 | if (loop == 0) |
| 7728 | num_term++; |
| 7729 | else |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7730 | count++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7731 | } |
| 7732 | } |
| 7733 | } |
| 7734 | if (loop == 0) |
| 7735 | { |
| 7736 | if (num_normal > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7737 | *numMatches = num_normal; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7738 | else if (num_term > 0) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7739 | *numMatches = num_term; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7740 | else |
| 7741 | return OK; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7742 | if (!fuzzy) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7743 | { |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7744 | *matches = ALLOC_MULT(char_u *, *numMatches); |
| 7745 | if (*matches == NULL) |
| 7746 | { |
| 7747 | *matches = (char_u **)""; |
| 7748 | return FAIL; |
| 7749 | } |
| 7750 | } |
| 7751 | else |
| 7752 | { |
| 7753 | fuzmatch = ALLOC_MULT(fuzmatch_str_T, *numMatches); |
| 7754 | if (fuzmatch == NULL) |
| 7755 | { |
| 7756 | *matches = (char_u **)""; |
| 7757 | return FAIL; |
| 7758 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7759 | } |
| 7760 | } |
| 7761 | } |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 7762 | |
| 7763 | if (fuzzy && |
| 7764 | fuzzymatches_to_strmatches(fuzmatch, matches, count, FALSE) == FAIL) |
| 7765 | return FAIL; |
| 7766 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7767 | return OK; |
| 7768 | } |
| 7769 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7770 | // Escape an option value that can be used on the command-line with :set. |
| 7771 | // Caller needs to free the returned string, unless NULL is returned. |
| 7772 | static char_u* |
| 7773 | escape_option_str_cmdline(char_u *var) |
| 7774 | { |
| 7775 | char_u *buf; |
| 7776 | |
| 7777 | // A backslash is required before some characters. This is the reverse of |
| 7778 | // what happens in do_set(). |
| 7779 | buf = vim_strsave_escaped(var, escape_chars); |
| 7780 | if (buf == NULL) |
| 7781 | return NULL; |
| 7782 | |
| 7783 | #ifdef BACKSLASH_IN_FILENAME |
| 7784 | // For MS-Windows et al. we don't double backslashes at the start and |
| 7785 | // before a file name character. |
| 7786 | // The reverse is found at stropt_copy_value(). |
| 7787 | for (var = buf; *var != NUL; MB_PTR_ADV(var)) |
| 7788 | if (var[0] == '\\' && var[1] == '\\' |
| 7789 | && expand_option_idx >= 0 |
| 7790 | && (options[expand_option_idx].flags & P_EXPAND) |
| 7791 | && vim_isfilec(var[2]) |
| 7792 | && (var[2] != '\\' || (var == buf && var[4] != '\\'))) |
| 7793 | STRMOVE(var, var + 1); |
| 7794 | #endif |
| 7795 | return buf; |
| 7796 | } |
| 7797 | |
| 7798 | /* |
| 7799 | * Expansion handler for :set= when we just want to fill in with the existing value. |
| 7800 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7801 | int |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7802 | ExpandOldSetting(int *numMatches, char_u ***matches) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7803 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7804 | char_u *var = NULL; // init for GCC |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7805 | char_u *buf; |
| 7806 | |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7807 | *numMatches = 0; |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7808 | *matches = ALLOC_MULT(char_u *, 1); |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7809 | if (*matches == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7810 | return FAIL; |
| 7811 | |
Yegappan Lakshmanan | c6ff21e | 2023-03-02 14:46:48 +0000 | [diff] [blame] | 7812 | // For a terminal key code expand_option_idx is < 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7813 | if (expand_option_idx < 0) |
| 7814 | { |
| 7815 | var = find_termcode(expand_option_name + 2); |
| 7816 | if (var == NULL) |
| 7817 | expand_option_idx = findoption(expand_option_name); |
| 7818 | } |
| 7819 | |
| 7820 | if (expand_option_idx >= 0) |
| 7821 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 7822 | // put string of option value in NameBuff |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7823 | option_value2string(&options[expand_option_idx], expand_option_flags); |
| 7824 | var = NameBuff; |
| 7825 | } |
| 7826 | else if (var == NULL) |
| 7827 | var = (char_u *)""; |
| 7828 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7829 | buf = escape_option_str_cmdline(var); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7830 | if (buf == NULL) |
| 7831 | { |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7832 | VIM_CLEAR(*matches); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7833 | return FAIL; |
| 7834 | } |
| 7835 | |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7836 | (*matches)[0] = buf; |
zeertzjq | b0d45ec | 2023-01-25 15:04:22 +0000 | [diff] [blame] | 7837 | *numMatches = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7838 | return OK; |
| 7839 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7840 | |
| 7841 | /* |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7842 | * Expansion handler for :set=/:set+= when the option has a custom expansion handler. |
| 7843 | */ |
| 7844 | int |
| 7845 | ExpandStringSetting( |
| 7846 | expand_T *xp, |
| 7847 | regmatch_T *regmatch, |
| 7848 | int *numMatches, |
| 7849 | char_u ***matches) |
| 7850 | { |
| 7851 | char_u *var = NULL; // init for GCC |
| 7852 | char_u *buf; |
| 7853 | |
| 7854 | if (expand_option_idx < 0 || |
| 7855 | options[expand_option_idx].opt_expand_cb == NULL) |
| 7856 | { |
| 7857 | // Not supposed to reach this. This function is only for options with |
| 7858 | // custom expansion callbacks. |
| 7859 | return FAIL; |
| 7860 | } |
| 7861 | |
| 7862 | optexpand_T args; |
| 7863 | args.oe_varp = get_varp_scope(&options[expand_option_idx], expand_option_flags); |
| 7864 | args.oe_append = expand_option_append; |
| 7865 | args.oe_regmatch = regmatch; |
| 7866 | args.oe_xp = xp; |
| 7867 | args.oe_set_arg = xp->xp_line + expand_option_start_col; |
| 7868 | args.oe_include_orig_val = |
| 7869 | !expand_option_append && |
| 7870 | (*args.oe_set_arg == NUL); |
| 7871 | |
| 7872 | // Retrieve the existing value, but escape it as a reverse of setting it. |
| 7873 | // We technically only need to do this when oe_append or |
| 7874 | // oe_include_orig_val is true. |
| 7875 | option_value2string(&options[expand_option_idx], expand_option_flags); |
| 7876 | var = NameBuff; |
| 7877 | buf = escape_option_str_cmdline(var); |
| 7878 | if (buf == NULL) |
| 7879 | return FAIL; |
| 7880 | |
| 7881 | args.oe_opt_value = buf; |
| 7882 | |
| 7883 | int num_ret = options[expand_option_idx].opt_expand_cb(&args, numMatches, matches); |
| 7884 | |
| 7885 | vim_free(buf); |
| 7886 | return num_ret; |
| 7887 | } |
| 7888 | |
| 7889 | /* |
| 7890 | * Expansion handler for :set-= |
| 7891 | */ |
| 7892 | int |
| 7893 | ExpandSettingSubtract( |
| 7894 | expand_T *xp, |
| 7895 | regmatch_T *regmatch, |
| 7896 | int *numMatches, |
| 7897 | char_u ***matches) |
| 7898 | { |
| 7899 | if (expand_option_idx < 0) |
| 7900 | // term option |
| 7901 | return ExpandOldSetting(numMatches, matches); |
| 7902 | |
| 7903 | char_u *option_val = *(char_u**)get_option_varp_scope( |
| 7904 | expand_option_idx, expand_option_flags); |
| 7905 | |
| 7906 | long_u option_flags = options[expand_option_idx].flags; |
| 7907 | |
| 7908 | if (option_flags & P_NUM) |
| 7909 | return ExpandOldSetting(numMatches, matches); |
| 7910 | else if (option_flags & P_COMMA) |
| 7911 | { |
| 7912 | // Split the option by comma, then present each option to the user if |
| 7913 | // it matches the pattern. |
| 7914 | // This condition needs to go first, because 'whichwrap' has both |
| 7915 | // P_COMMA and P_FLAGLIST. |
| 7916 | garray_T ga; |
| 7917 | |
| 7918 | char_u *item; |
| 7919 | char_u *option_copy; |
| 7920 | char_u *next_val; |
| 7921 | char_u *comma; |
| 7922 | |
| 7923 | if (*option_val == NUL) |
| 7924 | return FAIL; |
| 7925 | |
| 7926 | // Make a copy as we need to inject null characters destructively. |
| 7927 | option_copy = vim_strsave(option_val); |
| 7928 | if (option_copy == NULL) |
| 7929 | return FAIL; |
| 7930 | next_val = option_copy; |
| 7931 | |
| 7932 | ga_init2(&ga, sizeof(char_u *), 10); |
| 7933 | |
| 7934 | do |
| 7935 | { |
| 7936 | item = next_val; |
| 7937 | comma = vim_strchr(next_val, ','); |
| 7938 | while (comma != NULL && comma != next_val && *(comma - 1) == '\\') |
| 7939 | { |
| 7940 | // "\," is interpreted as a literal comma rather than option |
| 7941 | // separator when reading options in copy_option_part(). Skip |
| 7942 | // it. |
| 7943 | comma = vim_strchr(comma + 1, ','); |
| 7944 | } |
| 7945 | if (comma != NULL) |
| 7946 | { |
| 7947 | *comma = NUL; // null-terminate this value, required by later functions |
| 7948 | next_val = comma + 1; |
| 7949 | } |
| 7950 | else |
| 7951 | next_val = NULL; |
| 7952 | |
| 7953 | if (*item == NUL) |
| 7954 | // empty value, don't add to list |
| 7955 | continue; |
| 7956 | |
| 7957 | if (!vim_regexec(regmatch, item, (colnr_T)0)) |
| 7958 | continue; |
| 7959 | |
| 7960 | char_u *buf = escape_option_str_cmdline(item); |
| 7961 | if (buf == NULL) |
| 7962 | { |
| 7963 | vim_free(option_copy); |
| 7964 | ga_clear_strings(&ga); |
| 7965 | return FAIL; |
| 7966 | } |
| 7967 | if (ga_add_string(&ga, buf) != OK) |
| 7968 | { |
| 7969 | vim_free(buf); |
| 7970 | break; |
| 7971 | } |
| 7972 | } while (next_val != NULL); |
| 7973 | |
| 7974 | vim_free(option_copy); |
| 7975 | |
| 7976 | *matches = ga.ga_data; |
| 7977 | *numMatches = ga.ga_len; |
| 7978 | return OK; |
| 7979 | } |
| 7980 | else if (option_flags & P_FLAGLIST) |
| 7981 | { |
| 7982 | // Only present the flags that are set on the option as the other flags |
| 7983 | // are not meaningful to do set-= on. |
| 7984 | |
| 7985 | if (*xp->xp_pattern != NUL) |
| 7986 | { |
| 7987 | // Don't suggest anything if cmdline is non-empty. Vim's set-= |
| 7988 | // behavior requires consecutive strings and it's usually |
| 7989 | // unintuitive to users if ther try to subtract multiple flags at |
| 7990 | // once. |
| 7991 | return FAIL; |
| 7992 | } |
| 7993 | |
Yee Cheng Chin | 6d11347 | 2023-10-02 21:38:39 +0200 | [diff] [blame] | 7994 | size_t num_flags = STRLEN(option_val); |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 7995 | if (num_flags == 0) |
| 7996 | return FAIL; |
| 7997 | |
| 7998 | *matches = ALLOC_MULT(char_u *, num_flags + 1); |
| 7999 | if (*matches == NULL) |
| 8000 | return FAIL; |
| 8001 | |
| 8002 | int count = 0; |
| 8003 | char_u *p; |
| 8004 | |
| 8005 | p = vim_strsave(option_val); |
| 8006 | if (p == NULL) |
| 8007 | { |
| 8008 | VIM_CLEAR(*matches); |
| 8009 | return FAIL; |
| 8010 | } |
| 8011 | (*matches)[count++] = p; |
| 8012 | |
| 8013 | if (num_flags > 1) |
| 8014 | { |
| 8015 | // If more than one flags, split the flags up and expose each |
| 8016 | // character as individual choice. |
| 8017 | for (char_u *flag = option_val; *flag != NUL; flag++) |
| 8018 | { |
Yee Cheng Chin | f7f746b | 2023-09-30 12:28:50 +0200 | [diff] [blame] | 8019 | p = vim_strnsave(flag, 1); |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 8020 | if (p == NULL) |
| 8021 | break; |
| 8022 | (*matches)[count++] = p; |
| 8023 | } |
| 8024 | } |
| 8025 | |
| 8026 | *numMatches = count; |
| 8027 | return OK; |
| 8028 | } |
| 8029 | |
| 8030 | return ExpandOldSetting(numMatches, matches); |
| 8031 | } |
| 8032 | |
| 8033 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8034 | * Get the value for the numeric or string option *opp in a nice format into |
| 8035 | * NameBuff[]. Must not be called with a hidden option! |
| 8036 | */ |
| 8037 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8038 | option_value2string( |
| 8039 | struct vimoption *opp, |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 8040 | int scope) // OPT_GLOBAL and/or OPT_LOCAL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8041 | { |
| 8042 | char_u *varp; |
| 8043 | |
Yegappan Lakshmanan | 6409553 | 2021-12-06 11:03:55 +0000 | [diff] [blame] | 8044 | varp = get_varp_scope(opp, scope); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8045 | |
| 8046 | if (opp->flags & P_NUM) |
| 8047 | { |
| 8048 | long wc = 0; |
| 8049 | |
| 8050 | if (wc_use_keyname(varp, &wc)) |
| 8051 | STRCPY(NameBuff, get_special_key_name((int)wc, 0)); |
| 8052 | else if (wc != 0) |
| 8053 | STRCPY(NameBuff, transchar((int)wc)); |
| 8054 | else |
| 8055 | sprintf((char *)NameBuff, "%ld", *(long *)varp); |
| 8056 | } |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8057 | else // P_STRING |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8058 | { |
| 8059 | varp = *(char_u **)(varp); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8060 | if (varp == NULL) // just in case |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8061 | NameBuff[0] = NUL; |
| 8062 | #ifdef FEAT_CRYPT |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8063 | // 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] | 8064 | else if (opp->var == (char_u *)&p_key && *varp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8065 | STRCPY(NameBuff, "*****"); |
| 8066 | #endif |
| 8067 | else if (opp->flags & P_EXPAND) |
| 8068 | home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8069 | // Translate 'pastetoggle' into special key names |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8070 | else if ((char_u **)opp->var == &p_pt) |
| 8071 | str2specialbuf(p_pt, NameBuff, MAXPATHL); |
| 8072 | else |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 8073 | vim_strncpy(NameBuff, varp, MAXPATHL - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8074 | } |
| 8075 | } |
| 8076 | |
| 8077 | /* |
| 8078 | * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be |
| 8079 | * printed as a keyname. |
| 8080 | * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. |
| 8081 | */ |
| 8082 | static int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8083 | wc_use_keyname(char_u *varp, long *wcp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8084 | { |
| 8085 | if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) |
| 8086 | { |
| 8087 | *wcp = *(long *)varp; |
| 8088 | if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) |
| 8089 | return TRUE; |
| 8090 | } |
| 8091 | return FALSE; |
| 8092 | } |
| 8093 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8094 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8095 | * Return TRUE if "x" is present in 'shortmess' option, or |
| 8096 | * 'shortmess' contains 'a' and "x" is present in SHM_A. |
| 8097 | */ |
| 8098 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8099 | shortmess(int x) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8100 | { |
Bram Moolenaar | 7f29f7a | 2012-02-29 13:51:37 +0100 | [diff] [blame] | 8101 | return p_shm != NULL && |
| 8102 | ( vim_strchr(p_shm, x) != NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8103 | || (vim_strchr(p_shm, 'a') != NULL |
| 8104 | && vim_strchr((char_u *)SHM_A, x) != NULL)); |
| 8105 | } |
| 8106 | |
| 8107 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8108 | * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. |
| 8109 | * |
| 8110 | * Reset 'compatible' and set the values for options that didn't get set yet |
| 8111 | * to the Vim defaults. |
| 8112 | * 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] | 8113 | * 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] | 8114 | */ |
| 8115 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8116 | vimrc_found(char_u *fname, char_u *envname) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8117 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8118 | int opt_idx; |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 8119 | int dofree = FALSE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8120 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8121 | |
| 8122 | if (!option_was_set((char_u *)"cp")) |
| 8123 | { |
| 8124 | p_cp = FALSE; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8125 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8126 | if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) |
| 8127 | set_option_default(opt_idx, OPT_FREE, FALSE); |
| 8128 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 8129 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8130 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8131 | |
| 8132 | if (fname != NULL) |
| 8133 | { |
| 8134 | p = vim_getenv(envname, &dofree); |
| 8135 | if (p == NULL) |
| 8136 | { |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8137 | // Set $MYVIMRC to the first vimrc file found. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8138 | p = FullName_save(fname, FALSE); |
| 8139 | if (p != NULL) |
| 8140 | { |
| 8141 | vim_setenv(envname, p); |
| 8142 | vim_free(p); |
| 8143 | } |
| 8144 | } |
| 8145 | else if (dofree) |
| 8146 | vim_free(p); |
| 8147 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8148 | } |
| 8149 | |
| 8150 | /* |
| 8151 | * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. |
| 8152 | */ |
| 8153 | void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8154 | change_compatible(int on) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8155 | { |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 8156 | int opt_idx; |
| 8157 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8158 | if (p_cp != on) |
| 8159 | { |
| 8160 | p_cp = on; |
| 8161 | compatible_set(); |
| 8162 | } |
Bram Moolenaar | fc1421e | 2006-04-20 22:17:20 +0000 | [diff] [blame] | 8163 | opt_idx = findoption((char_u *)"cp"); |
| 8164 | if (opt_idx >= 0) |
| 8165 | options[opt_idx].flags |= P_WAS_SET; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | /* |
| 8169 | * Return TRUE when option "name" has been set. |
Bram Moolenaar | 1a4a75c | 2013-07-28 16:03:06 +0200 | [diff] [blame] | 8170 | * Only works correctly for global options. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8171 | */ |
| 8172 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8173 | option_was_set(char_u *name) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8174 | { |
| 8175 | int idx; |
| 8176 | |
| 8177 | idx = findoption(name); |
Bram Moolenaar | 6e0ce17 | 2019-12-05 20:12:41 +0100 | [diff] [blame] | 8178 | if (idx < 0) // unknown option |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8179 | return FALSE; |
| 8180 | if (options[idx].flags & P_WAS_SET) |
| 8181 | return TRUE; |
| 8182 | return FALSE; |
| 8183 | } |
| 8184 | |
| 8185 | /* |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 8186 | * Reset the flag indicating option "name" was set. |
| 8187 | */ |
Bram Moolenaar | fe8ef98 | 2018-09-13 20:31:54 +0200 | [diff] [blame] | 8188 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8189 | reset_option_was_set(char_u *name) |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 8190 | { |
| 8191 | int idx = findoption(name); |
| 8192 | |
Yegappan Lakshmanan | a41e221 | 2023-01-16 18:19:05 +0000 | [diff] [blame] | 8193 | if (idx < 0) |
| 8194 | return FAIL; |
| 8195 | |
| 8196 | options[idx].flags &= ~P_WAS_SET; |
| 8197 | return OK; |
Bram Moolenaar | 15d55de | 2012-12-05 14:43:02 +0100 | [diff] [blame] | 8198 | } |
| 8199 | |
| 8200 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8201 | * compatible_set() - Called when 'compatible' has been set or unset. |
| 8202 | * |
| 8203 | * When 'compatible' set: Set all relevant options (those that have the P_VIM) |
| 8204 | * flag) to a Vi compatible value. |
| 8205 | * When 'compatible' is unset: Set all options that have a different default |
| 8206 | * for Vim (without the P_VI_DEF flag) to that default. |
| 8207 | */ |
| 8208 | static void |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8209 | compatible_set(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8210 | { |
| 8211 | int opt_idx; |
| 8212 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8213 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8214 | if ( ((options[opt_idx].flags & P_VIM) && p_cp) |
| 8215 | || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) |
| 8216 | set_option_default(opt_idx, OPT_FREE, p_cp); |
| 8217 | didset_options(); |
Bram Moolenaar | e68c25c | 2015-08-25 15:39:55 +0200 | [diff] [blame] | 8218 | didset_options2(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8219 | } |
| 8220 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8221 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8222 | * Check if backspacing over something is allowed. |
| 8223 | */ |
| 8224 | int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8225 | can_bs( |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 8226 | int what) // BS_INDENT, BS_EOL, BS_START or BS_NOSTOP |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8227 | { |
Bram Moolenaar | 6b810d9 | 2018-06-04 17:28:44 +0200 | [diff] [blame] | 8228 | #ifdef FEAT_JOB_CHANNEL |
| 8229 | if (what == BS_START && bt_prompt(curbuf)) |
| 8230 | return FALSE; |
| 8231 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8232 | switch (*p_bs) |
| 8233 | { |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 8234 | case '3': return TRUE; |
| 8235 | case '2': return (what != BS_NOSTOP); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8236 | case '1': return (what != BS_START); |
| 8237 | case '0': return FALSE; |
| 8238 | } |
| 8239 | return vim_strchr(p_bs, what) != NULL; |
| 8240 | } |
| 8241 | |
| 8242 | /* |
Bram Moolenaar | 375e339 | 2019-01-31 18:26:10 +0100 | [diff] [blame] | 8243 | * Return the effective 'scrolloff' value for the current window, using the |
| 8244 | * global value when appropriate. |
| 8245 | */ |
| 8246 | long |
| 8247 | get_scrolloff_value(void) |
| 8248 | { |
| 8249 | return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; |
| 8250 | } |
| 8251 | |
| 8252 | /* |
| 8253 | * Return the effective 'sidescrolloff' value for the current window, using the |
| 8254 | * global value when appropriate. |
| 8255 | */ |
| 8256 | long |
| 8257 | get_sidescrolloff_value(void) |
| 8258 | { |
| 8259 | return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; |
| 8260 | } |
| 8261 | |
| 8262 | /* |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 8263 | * Get the local or global value of 'backupcopy'. |
| 8264 | */ |
| 8265 | unsigned int |
Bram Moolenaar | 9b57814 | 2016-01-30 19:39:49 +0100 | [diff] [blame] | 8266 | get_bkc_value(buf_T *buf) |
Bram Moolenaar | b8ee25a | 2014-09-23 15:45:08 +0200 | [diff] [blame] | 8267 | { |
| 8268 | return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; |
| 8269 | } |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 8270 | |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 8271 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8272 | /* |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8273 | * Get the local or global value of 'formatlistpat'. |
| 8274 | */ |
| 8275 | char_u * |
| 8276 | get_flp_value(buf_T *buf) |
| 8277 | { |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8278 | if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL) |
| 8279 | return p_flp; |
| 8280 | return buf->b_p_flp; |
| 8281 | } |
Dominique Pelle | 7765f5c | 2022-04-10 11:26:53 +0100 | [diff] [blame] | 8282 | #endif |
Christian Brabandt | c53b467 | 2022-01-15 10:01:05 +0000 | [diff] [blame] | 8283 | |
| 8284 | /* |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8285 | * Get the local or global value of the 'virtualedit' flags. |
| 8286 | */ |
| 8287 | unsigned int |
| 8288 | get_ve_flags(void) |
| 8289 | { |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 8290 | return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) |
| 8291 | & ~(VE_NONE | VE_NONEU); |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 8292 | } |
| 8293 | |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 8294 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 8295 | /* |
| 8296 | * Get the local or global value of 'showbreak'. |
| 8297 | */ |
| 8298 | char_u * |
| 8299 | get_showbreak_value(win_T *win) |
| 8300 | { |
| 8301 | if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) |
| 8302 | return p_sbr; |
| 8303 | if (STRCMP(win->w_p_sbr, "NONE") == 0) |
| 8304 | return empty_option; |
| 8305 | return win->w_p_sbr; |
| 8306 | } |
| 8307 | #endif |
| 8308 | |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8309 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 8310 | /* |
| 8311 | * Get window or buffer local options. |
| 8312 | */ |
| 8313 | dict_T * |
| 8314 | get_winbuf_options(int bufopt) |
| 8315 | { |
| 8316 | dict_T *d; |
| 8317 | int opt_idx; |
| 8318 | |
| 8319 | d = dict_alloc(); |
| 8320 | if (d == NULL) |
| 8321 | return NULL; |
| 8322 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8323 | for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8324 | { |
| 8325 | struct vimoption *opt = &options[opt_idx]; |
| 8326 | |
| 8327 | if ((bufopt && (opt->indir & PV_BUF)) |
| 8328 | || (!bufopt && (opt->indir & PV_WIN))) |
| 8329 | { |
| 8330 | char_u *varp = get_varp(opt); |
| 8331 | |
| 8332 | if (varp != NULL) |
| 8333 | { |
| 8334 | if (opt->flags & P_STRING) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8335 | dict_add_string(d, opt->fullname, *(char_u **)varp); |
Bram Moolenaar | 789a5c0 | 2016-09-12 19:51:11 +0200 | [diff] [blame] | 8336 | else if (opt->flags & P_NUM) |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8337 | dict_add_number(d, opt->fullname, *(long *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8338 | else |
Bram Moolenaar | e0be167 | 2018-07-08 16:50:37 +0200 | [diff] [blame] | 8339 | dict_add_number(d, opt->fullname, *(int *)varp); |
Bram Moolenaar | b5ae48e | 2016-08-12 22:23:25 +0200 | [diff] [blame] | 8340 | } |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | return d; |
| 8345 | } |
| 8346 | #endif |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8347 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8348 | #if defined(FEAT_SYN_HL) || defined(PROTO) |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8349 | /* |
| 8350 | * This is called when 'culopt' is changed |
| 8351 | */ |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 8352 | int |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8353 | fill_culopt_flags(char_u *val, win_T *wp) |
| 8354 | { |
| 8355 | char_u *p; |
| 8356 | char_u culopt_flags_new = 0; |
| 8357 | |
| 8358 | if (val == NULL) |
| 8359 | p = wp->w_p_culopt; |
| 8360 | else |
| 8361 | p = val; |
| 8362 | while (*p != NUL) |
| 8363 | { |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 8364 | // Note: Keep this in sync with p_culopt_values. |
Bram Moolenaar | 017ba07 | 2019-09-14 21:01:23 +0200 | [diff] [blame] | 8365 | if (STRNCMP(p, "line", 4) == 0) |
| 8366 | { |
| 8367 | p += 4; |
| 8368 | culopt_flags_new |= CULOPT_LINE; |
| 8369 | } |
| 8370 | else if (STRNCMP(p, "both", 4) == 0) |
| 8371 | { |
| 8372 | p += 4; |
| 8373 | culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; |
| 8374 | } |
| 8375 | else if (STRNCMP(p, "number", 6) == 0) |
| 8376 | { |
| 8377 | p += 6; |
| 8378 | culopt_flags_new |= CULOPT_NBR; |
| 8379 | } |
| 8380 | else if (STRNCMP(p, "screenline", 10) == 0) |
| 8381 | { |
| 8382 | p += 10; |
| 8383 | culopt_flags_new |= CULOPT_SCRLINE; |
| 8384 | } |
| 8385 | |
| 8386 | if (*p != ',' && *p != NUL) |
| 8387 | return FAIL; |
| 8388 | if (*p == ',') |
| 8389 | ++p; |
| 8390 | } |
| 8391 | |
| 8392 | // Can't have both "line" and "screenline". |
| 8393 | if ((culopt_flags_new & CULOPT_LINE) && (culopt_flags_new & CULOPT_SCRLINE)) |
| 8394 | return FAIL; |
| 8395 | wp->w_p_culopt_flags = culopt_flags_new; |
| 8396 | |
| 8397 | return OK; |
| 8398 | } |
| 8399 | #endif |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8400 | |
| 8401 | /* |
| 8402 | * Get the value of 'magic' adjusted for Vim9 script. |
| 8403 | */ |
| 8404 | int |
| 8405 | magic_isset(void) |
| 8406 | { |
| 8407 | switch (magic_overruled) |
| 8408 | { |
Bram Moolenaar | d93a7fc | 2021-01-04 12:42:13 +0100 | [diff] [blame] | 8409 | case OPTION_MAGIC_ON: return TRUE; |
| 8410 | case OPTION_MAGIC_OFF: return FALSE; |
| 8411 | case OPTION_MAGIC_NOT_SET: break; |
Bram Moolenaar | f4e2099 | 2020-12-21 19:59:08 +0100 | [diff] [blame] | 8412 | } |
| 8413 | #ifdef FEAT_EVAL |
| 8414 | if (in_vim9script()) |
| 8415 | return TRUE; |
| 8416 | #endif |
| 8417 | return p_magic; |
| 8418 | } |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8419 | |
| 8420 | /* |
| 8421 | * Set the callback function value for an option that accepts a function name, |
| 8422 | * lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.) |
| 8423 | * Returns OK if the option is successfully set to a function, otherwise |
| 8424 | * returns FAIL. |
| 8425 | */ |
| 8426 | int |
| 8427 | option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED) |
| 8428 | { |
| 8429 | #ifdef FEAT_EVAL |
| 8430 | typval_T *tv; |
| 8431 | callback_T cb; |
| 8432 | |
| 8433 | if (optval == NULL || *optval == NUL) |
| 8434 | { |
| 8435 | free_callback(optcb); |
| 8436 | return OK; |
| 8437 | } |
| 8438 | |
Yegappan Lakshmanan | 05e59e3 | 2021-12-01 10:30:07 +0000 | [diff] [blame] | 8439 | if (*optval == '{' || (in_vim9script() && *optval == '(') |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8440 | || (STRNCMP(optval, "function(", 9) == 0) |
| 8441 | || (STRNCMP(optval, "funcref(", 8) == 0)) |
| 8442 | // Lambda expression or a funcref |
| 8443 | tv = eval_expr(optval, NULL); |
| 8444 | else |
| 8445 | // treat everything else as a function name string |
Yegappan Lakshmanan | e7f4abd | 2021-12-24 20:47:38 +0000 | [diff] [blame] | 8446 | tv = alloc_string_tv(vim_strsave(optval)); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8447 | if (tv == NULL) |
| 8448 | return FAIL; |
| 8449 | |
| 8450 | cb = get_callback(tv); |
Yegappan Lakshmanan | 4dc24eb | 2021-12-07 12:23:57 +0000 | [diff] [blame] | 8451 | if (cb.cb_name == NULL || *cb.cb_name == NUL) |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8452 | { |
| 8453 | free_tv(tv); |
| 8454 | return FAIL; |
| 8455 | } |
| 8456 | |
| 8457 | free_callback(optcb); |
| 8458 | set_callback(optcb, &cb); |
Bram Moolenaar | c96b7f5 | 2022-12-02 15:58:38 +0000 | [diff] [blame] | 8459 | if (cb.cb_free_name) |
| 8460 | vim_free(cb.cb_name); |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8461 | free_tv(tv); |
Bram Moolenaar | f0e7e63 | 2022-01-21 13:29:56 +0000 | [diff] [blame] | 8462 | |
| 8463 | // when using Vim9 style "import.funcname" it needs to be expanded to |
| 8464 | // "import#funcname". |
| 8465 | expand_autload_callback(optcb); |
| 8466 | |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 8467 | return OK; |
| 8468 | #else |
| 8469 | return FAIL; |
| 8470 | #endif |
| 8471 | } |
Christian Brabandt | 757593c | 2023-08-22 21:44:10 +0200 | [diff] [blame] | 8472 | |
| 8473 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 8474 | static void |
| 8475 | didset_options_sctx(int opt_flags, char **buf) |
| 8476 | { |
| 8477 | for (int i = 0; ; ++i) |
| 8478 | { |
| 8479 | if (buf[i] == NULL) |
| 8480 | break; |
| 8481 | |
| 8482 | int idx = findoption((char_u *)buf[i]); |
| 8483 | if (idx >= 0) |
| 8484 | set_option_sctx_idx(idx, opt_flags, current_sctx); |
| 8485 | } |
| 8486 | } |
| 8487 | #endif |