comparison src/option.c @ 16843:283037126560 v8.1.1423

patch 8.1.1423: popup windows use options from current window and buffer commit https://github.com/vim/vim/commit/cacc6a5c986fbc716bf53b6916f076dd7b388142 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 30 15:22:43 2019 +0200 patch 8.1.1423: popup windows use options from current window and buffer Problem: Popup windows use options from current window and buffer. Solution: Clear all local options when creating a popup window.
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 May 2019 15:30:05 +0200
parents ce04ebdf26b8
children d726d8cce996
comparison
equal deleted inserted replaced
16842:a3555dcb63cd 16843:283037126560
3267 static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags); 3267 static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
3268 static void check_redraw(long_u flags); 3268 static void check_redraw(long_u flags);
3269 static int findoption(char_u *); 3269 static int findoption(char_u *);
3270 static int find_key_option(char_u *arg_arg, int has_lt); 3270 static int find_key_option(char_u *arg_arg, int has_lt);
3271 static void showoptions(int all, int opt_flags); 3271 static void showoptions(int all, int opt_flags);
3272 static int optval_default(struct vimoption *, char_u *varp); 3272 static int optval_default(struct vimoption *, char_u *varp, int compatible);
3273 static void showoneopt(struct vimoption *, int opt_flags); 3273 static void showoneopt(struct vimoption *, int opt_flags);
3274 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags); 3274 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
3275 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); 3275 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3276 static int put_setbool(FILE *fd, char *cmd, char *name, int value); 3276 static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3277 static int istermoption(struct vimoption *); 3277 static int istermoption(struct vimoption *);
3889 int opt_idx; 3889 int opt_idx;
3890 3890
3891 opt_idx = findoption((char_u *)name); 3891 opt_idx = findoption((char_u *)name);
3892 if (opt_idx >= 0) 3892 if (opt_idx >= 0)
3893 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; 3893 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3894 }
3895
3896 /*
3897 * Set all window-local and buffer-local options to the Vim default.
3898 * local-global options will use the global value.
3899 */
3900 void
3901 set_local_options_default(win_T *wp)
3902 {
3903 win_T *save_curwin = curwin;
3904 int i;
3905
3906 curwin = wp;
3907 curbuf = curwin->w_buffer;
3908 block_autocmds();
3909
3910 for (i = 0; !istermoption(&options[i]); i++)
3911 {
3912 struct vimoption *p = &(options[i]);
3913 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3914
3915 if (p->indir != PV_NONE
3916 && !(options[i].flags & P_NODEFAULT)
3917 && !optval_default(p, varp, FALSE))
3918 set_option_default(i, OPT_LOCAL, FALSE);
3919 }
3920
3921 unblock_autocmds();
3922 curwin = save_curwin;
3923 curbuf = curwin->w_buffer;
3894 } 3924 }
3895 3925
3896 #if defined(EXITFREE) || defined(PROTO) 3926 #if defined(EXITFREE) || defined(PROTO)
3897 /* 3927 /*
3898 * Free all options. 3928 * Free all options.
10147 else 10177 else
10148 varp = get_varp(p); 10178 varp = get_varp(p);
10149 if (varp != NULL 10179 if (varp != NULL
10150 && ((all == 2 && isterm) 10180 && ((all == 2 && isterm)
10151 || (all == 1 && !isterm) 10181 || (all == 1 && !isterm)
10152 || (all == 0 && !optval_default(p, varp)))) 10182 || (all == 0 && !optval_default(p, varp, p_cp))))
10153 { 10183 {
10154 if (p->flags & P_BOOL) 10184 if (p->flags & P_BOOL)
10155 len = 1; /* a toggle option fits always */ 10185 len = 1; /* a toggle option fits always */
10156 else 10186 else
10157 { 10187 {
10197 10227
10198 /* 10228 /*
10199 * Return TRUE if option "p" has its default value. 10229 * Return TRUE if option "p" has its default value.
10200 */ 10230 */
10201 static int 10231 static int
10202 optval_default(struct vimoption *p, char_u *varp) 10232 optval_default(struct vimoption *p, char_u *varp, int compatible)
10203 { 10233 {
10204 int dvi; 10234 int dvi;
10205 10235
10206 if (varp == NULL) 10236 if (varp == NULL)
10207 return TRUE; /* hidden option is always at default */ 10237 return TRUE; /* hidden option is always at default */
10208 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT; 10238 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
10209 if (p->flags & P_NUM) 10239 if (p->flags & P_NUM)
10210 return (*(long *)varp == (long)(long_i)p->def_val[dvi]); 10240 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
10211 if (p->flags & P_BOOL) 10241 if (p->flags & P_BOOL)
10212 /* the cast to long is required for Manx C, long_i is 10242 /* the cast to long is required for Manx C, long_i is
10213 * needed for MSVC */ 10243 * needed for MSVC */
10309 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) 10339 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10310 continue; 10340 continue;
10311 10341
10312 /* Global values are only written when not at the default value. */ 10342 /* Global values are only written when not at the default value. */
10313 varp = get_varp_scope(p, opt_flags); 10343 varp = get_varp_scope(p, opt_flags);
10314 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) 10344 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
10315 continue; 10345 continue;
10316 10346
10317 round = 2; 10347 round = 2;
10318 if (p->indir != PV_NONE) 10348 if (p->indir != PV_NONE)
10319 { 10349 {
10325 /* When fresh value of window-local option is not at the 10355 /* When fresh value of window-local option is not at the
10326 * default, need to write it too. */ 10356 * default, need to write it too. */
10327 if (!(opt_flags & OPT_GLOBAL) && !local_only) 10357 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10328 { 10358 {
10329 varp_fresh = get_varp_scope(p, OPT_GLOBAL); 10359 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10330 if (!optval_default(p, varp_fresh)) 10360 if (!optval_default(p, varp_fresh, p_cp))
10331 { 10361 {
10332 round = 1; 10362 round = 1;
10333 varp_local = varp; 10363 varp_local = varp;
10334 varp = varp_fresh; 10364 varp = varp_fresh;
10335 } 10365 }