summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1123
blob: ad96b193206df1b92ba768d47ef98d994325320c (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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1123
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.1123
Problem:    No way to avoid filtering for autocomplete function, causing
            flickering of the popup menu.
Solution:   Add the "equal" field to complete items. (closes #3887)
Files:	    runtime/doc/insert.txt, src/insexpand.c,
            src/testdir/test_popup.vim


*** ../vim-8.1.1122/runtime/doc/insert.txt	2019-03-29 12:19:34.949348952 +0100
--- runtime/doc/insert.txt	2019-04-06 13:28:26.273579773 +0200
***************
*** 1104,1109 ****
--- 1105,1113 ----
  	icase		when non-zero case is to be ignored when comparing
  			items to be equal; when omitted zero is used, thus
  			items that only differ in case are added
+ 	equal		when non-zero, always treat this item to be equal when
+ 			comparing. Which means, "equal=1" disables filtering
+ 			of this item.
  	dup		when non-zero this match will be added even when an
  			item with the same word is already present.
  	empty		when non-zero this match will be added even when it is
***************
*** 1111,1120 ****
  	user_data 	custom data which is associated with the item and
  			available in |v:completed_item|
  
! All of these except "icase", "dup" and "empty" must be a string.  If an item
! does not meet these requirements then an error message is given and further
! items in the list are not used.  You can mix string and Dictionary items in
! the returned list.
  
  The "menu" item is used in the popup menu and may be truncated, thus it should
  be relatively short.  The "info" item can be longer, it will  be displayed in
--- 1115,1124 ----
  	user_data 	custom data which is associated with the item and
  			available in |v:completed_item|
  
! All of these except "icase", "equal", "dup" and "empty" must be a string.  If
! an item does not meet these requirements then an error message is given and
! further items in the list are not used.  You can mix string and Dictionary
! items in the returned list.
  
  The "menu" item is used in the popup menu and may be truncated, thus it should
  be relatively short.  The "info" item can be longer, it will  be displayed in
*** ../vim-8.1.1122/src/insexpand.c	2019-03-30 18:46:57.344077426 +0100
--- src/insexpand.c	2019-04-06 13:37:17.079078108 +0200
***************
*** 101,116 ****
  {
      compl_T	*cp_next;
      compl_T	*cp_prev;
!     char_u	*cp_str;	/* matched text */
!     char	cp_icase;	/* TRUE or FALSE: ignore case */
!     char_u	*(cp_text[CPT_COUNT]);	/* text for the menu */
!     char_u	*cp_fname;	/* file containing the match, allocated when
! 				 * cp_flags has FREE_FNAME */
!     int		cp_flags;	/* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
!     int		cp_number;	/* sequence number */
  };
  
! # define ORIGINAL_TEXT	(1)   /* the original text when the expansion begun */
  # define FREE_FNAME	(2)
  
  static char e_hitend[] = N_("Hit end of paragraph");
--- 101,118 ----
  {
      compl_T	*cp_next;
      compl_T	*cp_prev;
!     char_u	*cp_str;	// matched text
!     char	cp_icase;	// TRUE or FALSE: ignore case
!     char	cp_equal;       // TRUE or FALSE: ins_compl_equal always ok
!     char_u	*(cp_text[CPT_COUNT]);	// text for the menu
!     char_u	*cp_fname;	// file containing the match, allocated when
! 				// cp_flags has FREE_FNAME
!     int		cp_flags;	// ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME
!     int		cp_number;	// sequence number
  };
  
! // flags for ins_compl_add()
! # define ORIGINAL_TEXT	(1)   // the original text when the expansion begun
  # define FREE_FNAME	(2)
  
  static char e_hitend[] = N_("Hit end of paragraph");
***************
*** 183,189 ****
  static int	  compl_opt_refresh_always = FALSE;
  static int	  compl_opt_suppress_empty = FALSE;
  
! static int ins_compl_add(char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int adup);
  static void ins_compl_longest_match(compl_T *match);
  static void ins_compl_del_pum(void);
  static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
--- 185,191 ----
  static int	  compl_opt_refresh_always = FALSE;
  static int	  compl_opt_suppress_empty = FALSE;
  
! static int ins_compl_add(char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int adup, int equal);
  static void ins_compl_longest_match(compl_T *match);
  static void ins_compl_del_pum(void);
  static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
***************
*** 413,425 ****
   */
      int
  ins_compl_add_infercase(
!     char_u	*str,
      int		len,
      int		icase,
      char_u	*fname,
      int		dir,
      int		flags)
  {
      char_u	*p;
      int		i, c;
      int		actual_len;		// Take multi-byte characters
--- 415,428 ----
   */
      int
  ins_compl_add_infercase(
!     char_u	*str_arg,
      int		len,
      int		icase,
      char_u	*fname,
      int		dir,
      int		flags)
  {
+     char_u	*str = str_arg;
      char_u	*p;
      int		i, c;
      int		actual_len;		// Take multi-byte characters
***************
*** 550,559 ****
  	    vim_free(wca);
  	}
  
! 	return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
! 								flags, FALSE);
      }
!     return ins_compl_add(str, len, icase, fname, NULL, dir, flags, FALSE);
  }
  
  /*
--- 553,563 ----
  	    vim_free(wca);
  	}
  
! 	str = IObuff;
      }
! 
!     return ins_compl_add(str, len, icase, fname, NULL, dir,
! 							  flags, FALSE, FALSE);
  }
  
  /*
***************
*** 571,577 ****
      char_u	**cptext,   // extra text for popup menu or NULL
      int		cdir,
      int		flags,
!     int		adup)	    // accept duplicate match
  {
      compl_T	*match;
      int		dir = (cdir == 0 ? compl_direction : cdir);
--- 575,582 ----
      char_u	**cptext,   // extra text for popup menu or NULL
      int		cdir,
      int		flags,
!     int		adup,	    // accept duplicate match
!     int		equal)      // match is always accepted by ins_compl_equal
  {
      compl_T	*match;
      int		dir = (cdir == 0 ? compl_direction : cdir);
***************
*** 613,618 ****
--- 618,624 ----
  	return FAIL;
      }
      match->cp_icase = icase;
+     match->cp_equal = equal;
  
      // match-fname is:
      // - compl_curr_match->cp_fname if it is a string equal to fname.
***************
*** 676,681 ****
--- 682,689 ----
      static int
  ins_compl_equal(compl_T *match, char_u *str, int len)
  {
+     if (match->cp_equal)
+ 	return TRUE;
      if (match->cp_icase)
  	return STRNICMP(match->cp_str, str, (size_t)len) == 0;
      return STRNCMP(match->cp_str, str, (size_t)len) == 0;
***************
*** 776,782 ****
  
      for (i = 0; i < num_matches && add_r != FAIL; i++)
  	if ((add_r = ins_compl_add(matches[i], -1, icase,
! 					    NULL, NULL, dir, 0, FALSE)) == OK)
  	    // if dir was BACKWARD then honor it just once
  	    dir = FORWARD;
      FreeWild(num_matches, matches);
--- 784,790 ----
  
      for (i = 0; i < num_matches && add_r != FAIL; i++)
  	if ((add_r = ins_compl_add(matches[i], -1, icase,
! 				      NULL, NULL, dir, 0, FALSE, FALSE)) == OK)
  	    // if dir was BACKWARD then honor it just once
  	    dir = FORWARD;
      FreeWild(num_matches, matches);
***************
*** 868,874 ****
      // compl_pattern doesn't need to be set
      compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
      if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
! 			-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
  	return;
  
      ctrl_x_mode = CTRL_X_EVAL;
--- 876,882 ----
      // compl_pattern doesn't need to be set
      compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
      if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
! 		   -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE, FALSE) != OK)
  	return;
  
      ctrl_x_mode = CTRL_X_EVAL;
***************
*** 2365,2370 ****
--- 2373,2379 ----
      int		icase = FALSE;
      int		adup = FALSE;
      int		aempty = FALSE;
+     int		aequal = FALSE;
      char_u	*(cptext[CPT_COUNT]);
  
      if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
***************
*** 2386,2391 ****
--- 2395,2402 ----
  	    adup = dict_get_number(tv->vval.v_dict, (char_u *)"dup");
  	if (dict_get_string(tv->vval.v_dict, (char_u *)"empty", FALSE) != NULL)
  	    aempty = dict_get_number(tv->vval.v_dict, (char_u *)"empty");
+ 	if (dict_get_string(tv->vval.v_dict, (char_u *)"equal", FALSE) != NULL)
+ 	    aequal = dict_get_number(tv->vval.v_dict, (char_u *)"equal");
      }
      else
      {
***************
*** 2394,2400 ****
      }
      if (word == NULL || (!aempty && *word == NUL))
  	return FAIL;
!     return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, adup);
  }
  #endif
  
--- 2405,2411 ----
      }
      if (word == NULL || (!aempty && *word == NUL))
  	return FAIL;
!     return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, adup, aequal);
  }
  #endif
  
***************
*** 3694,3700 ****
  	vim_free(compl_orig_text);
  	compl_orig_text = vim_strnsave(line + compl_col, compl_length);
  	if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
! 			-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
  	{
  	    VIM_CLEAR(compl_pattern);
  	    VIM_CLEAR(compl_orig_text);
--- 3705,3711 ----
  	vim_free(compl_orig_text);
  	compl_orig_text = vim_strnsave(line + compl_col, compl_length);
  	if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
! 		   -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE, FALSE) != OK)
  	{
  	    VIM_CLEAR(compl_pattern);
  	    VIM_CLEAR(compl_orig_text);
*** ../vim-8.1.1122/src/testdir/test_popup.vim	2019-03-29 12:19:34.953348924 +0100
--- src/testdir/test_popup.vim	2019-04-06 13:34:17.403736197 +0200
***************
*** 276,281 ****
--- 276,313 ----
    iunmap <F5>
  endfunc
  
+ func Test_complete_no_filter()
+   func! s:complTest1() abort
+     call complete(1, [{'word': 'foobar'}])
+     return ''
+   endfunc
+   func! s:complTest2() abort
+     call complete(1, [{'word': 'foobar', 'equal': 1}])
+     return ''
+   endfunc
+ 
+   let completeopt = &completeopt
+ 
+   " without equal=1
+   new
+   set completeopt=menuone,noinsert,menu
+   inoremap <F5>  <C-R>=s:complTest1()<CR>
+   call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx')
+   call assert_equal('z', getline(1))
+   bwipe!
+ 
+   " with equal=1
+   new
+   set completeopt=menuone,noinsert,menu
+   inoremap <F5>  <C-R>=s:complTest2()<CR>
+   call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx')
+   call assert_equal('foobar', getline(1))
+   bwipe!
+ 
+   let &completeopt = completeopt
+   iunmap <F5>
+ endfunc
+ 
  func Test_compl_vim_cmds_after_register_expr()
    func! s:test_func()
      return 'autocmd '
*** ../vim-8.1.1122/src/version.c	2019-04-06 13:18:06.737335067 +0200
--- src/version.c	2019-04-06 13:27:34.729885207 +0200
***************
*** 773,774 ****
--- 773,776 ----
  {   /* Add new patch number below this line */
+ /**/
+     1123,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
210. When you get a divorce, you don't care about who gets the children,
     but discuss endlessly who can use the email address.

 /// 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    ///