summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1423
blob: db04c4d5f72ba6462d718197a7cb14ee379bc308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1423
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.1423
Problem:    Popup windows use options from current window and buffer.
Solution:   Clear all local options when creating a popup window.
Files:	    src/popupwin.c, src/option.c, src/proto/option.pro,
            src/testdir/test_popupwin.vim


*** ../vim-8.1.1422/src/popupwin.c	2019-05-30 14:29:42.597507636 +0200
--- src/popupwin.c	2019-05-30 15:00:03.807391833 +0200
***************
*** 253,258 ****
--- 253,262 ----
      if (buf == NULL)
  	return;
      ml_open(buf);
+ 
+     win_init_popup_win(wp, buf);
+ 
+     set_local_options_default(wp);
      set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1,
  				     (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0);
      set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1,
***************
*** 262,269 ****
      buf->b_p_bl = FALSE;    // unlisted buffer
      buf->b_locked = TRUE;
  
-     win_init_popup_win(wp, buf);
- 
      nr = (int)dict_get_number(d, (char_u *)"tab");
      if (nr == 0)
      {
--- 266,271 ----
*** ../vim-8.1.1422/src/option.c	2019-05-28 23:08:12.072648675 +0200
--- src/option.c	2019-05-30 15:17:11.233968834 +0200
***************
*** 3269,3275 ****
  static int findoption(char_u *);
  static int find_key_option(char_u *arg_arg, int has_lt);
  static void showoptions(int all, int opt_flags);
! static int optval_default(struct vimoption *, char_u *varp);
  static void showoneopt(struct vimoption *, int opt_flags);
  static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
  static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
--- 3269,3275 ----
  static int findoption(char_u *);
  static int find_key_option(char_u *arg_arg, int has_lt);
  static void showoptions(int all, int opt_flags);
! static int optval_default(struct vimoption *, char_u *varp, int compatible);
  static void showoneopt(struct vimoption *, int opt_flags);
  static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
  static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
***************
*** 3893,3898 ****
--- 3893,3928 ----
  	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
  }
  
+ /*
+  * Set all window-local and buffer-local options to the Vim default.
+  * local-global options will use the global value.
+  */
+     void
+ set_local_options_default(win_T *wp)
+ {
+     win_T	*save_curwin = curwin;
+     int		i;
+ 
+     curwin = wp;
+     curbuf = curwin->w_buffer;
+     block_autocmds();
+ 
+     for (i = 0; !istermoption(&options[i]); i++)
+     {
+ 	struct vimoption    *p = &(options[i]);
+ 	char_u		    *varp = get_varp_scope(p, OPT_LOCAL);
+ 
+ 	if (p->indir != PV_NONE
+ 		&& !(options[i].flags & P_NODEFAULT)
+ 		&& !optval_default(p, varp, FALSE))
+ 	    set_option_default(i, OPT_LOCAL, FALSE);
+     }
+ 
+     unblock_autocmds();
+     curwin = save_curwin;
+     curbuf = curwin->w_buffer;
+ }
+ 
  #if defined(EXITFREE) || defined(PROTO)
  /*
   * Free all options.
***************
*** 10149,10155 ****
  	    if (varp != NULL
  		    && ((all == 2 && isterm)
  			|| (all == 1 && !isterm)
! 			|| (all == 0 && !optval_default(p, varp))))
  	    {
  		if (p->flags & P_BOOL)
  		    len = 1;		/* a toggle option fits always */
--- 10179,10185 ----
  	    if (varp != NULL
  		    && ((all == 2 && isterm)
  			|| (all == 1 && !isterm)
! 			|| (all == 0 && !optval_default(p, varp, p_cp))))
  	    {
  		if (p->flags & P_BOOL)
  		    len = 1;		/* a toggle option fits always */
***************
*** 10199,10211 ****
   * Return TRUE if option "p" has its default value.
   */
      static int
! optval_default(struct vimoption *p, char_u *varp)
  {
      int		dvi;
  
      if (varp == NULL)
  	return TRUE;	    /* hidden option is always at default */
!     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
      if (p->flags & P_NUM)
  	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
      if (p->flags & P_BOOL)
--- 10229,10241 ----
   * Return TRUE if option "p" has its default value.
   */
      static int
! optval_default(struct vimoption *p, char_u *varp, int compatible)
  {
      int		dvi;
  
      if (varp == NULL)
  	return TRUE;	    /* hidden option is always at default */
!     dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
      if (p->flags & P_NUM)
  	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
      if (p->flags & P_BOOL)
***************
*** 10311,10317 ****
  
  	    /* Global values are only written when not at the default value. */
  	    varp = get_varp_scope(p, opt_flags);
! 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
  		continue;
  
  	    round = 2;
--- 10341,10347 ----
  
  	    /* Global values are only written when not at the default value. */
  	    varp = get_varp_scope(p, opt_flags);
! 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
  		continue;
  
  	    round = 2;
***************
*** 10327,10333 ****
  		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
  		    {
  			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
! 			if (!optval_default(p, varp_fresh))
  			{
  			    round = 1;
  			    varp_local = varp;
--- 10357,10363 ----
  		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
  		    {
  			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
! 			if (!optval_default(p, varp_fresh, p_cp))
  			{
  			    round = 1;
  			    varp_local = varp;
*** ../vim-8.1.1422/src/proto/option.pro	2019-05-26 21:03:19.940073927 +0200
--- src/proto/option.pro	2019-05-30 14:42:45.737186164 +0200
***************
*** 2,7 ****
--- 2,8 ----
  void set_init_1(int clean_arg);
  void set_string_default(char *name, char_u *val);
  void set_number_default(char *name, long val);
+ void set_local_options_default(win_T *wp);
  void free_all_options(void);
  void set_init_2(void);
  void set_init_3(void);
*** ../vim-8.1.1422/src/testdir/test_popupwin.vim	2019-05-30 14:29:42.597507636 +0200
--- src/testdir/test_popupwin.vim	2019-05-30 15:18:36.037507243 +0200
***************
*** 264,266 ****
--- 264,289 ----
    call popup_close(winid)
    call assert_equal({}, popup_getoptions(winid))
  endfunc
+ 
+ func Test_popup_option_values()
+   new
+   " window-local
+   setlocal number
+   setlocal nowrap
+   " buffer-local
+   setlocal omnifunc=Something
+   " global/buffer-local
+   setlocal path=/there
+   " global/window-local
+   setlocal scrolloff=9
+ 
+   let winid = popup_create('hello', {})
+   call assert_equal(0, getwinvar(winid, '&number'))
+   call assert_equal(1, getwinvar(winid, '&wrap'))
+   call assert_equal('', getwinvar(winid, '&omnifunc'))
+   call assert_equal(&g:path, getwinvar(winid, '&path'))
+   call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
+ 
+   call popup_close(winid)
+   bwipe
+ endfunc
*** ../vim-8.1.1422/src/version.c	2019-05-30 14:29:42.597507636 +0200
--- src/version.c	2019-05-30 14:42:37.873229921 +0200
***************
*** 769,770 ****
--- 769,772 ----
  {   /* Add new patch number below this line */
+ /**/
+     1423,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
51. You put a pillow case over your laptop so your lover doesn't see it while
    you are pretending to catch your breath.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///