summaryrefslogtreecommitdiffstats
path: root/source/ap/vim/patches/7.3.311
blob: 13aec74a9e08a106bdf951fb8675e58a46c77760 (plain) (blame)
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
To: vim_dev@googlegroups.com
Subject: Patch 7.3.311
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.311 (replaces 7.3.289)
Problem:    Complete function isn't called when the leader changed.
Solution:   Allow the complete function to return a dictionary with a flag
	    that indicates ins_compl_restart() is to be called when the leader
	    changes. (Taro Muraoka)
Files:	    runtime/insert.txt, src/edit.c, src/eval.c, src/proto/eval.pro


*** ../vim-7.3.310/src/edit.c	2011-09-05 20:13:37.000000000 +0200
--- src/edit.c	2011-09-14 16:43:14.000000000 +0200
***************
*** 135,140 ****
--- 135,142 ----
  static int	  compl_cont_mode = 0;
  static expand_T	  compl_xp;
  
+ static int	  compl_opt_refresh_always = FALSE;
+ 
  static void ins_ctrl_x __ARGS((void));
  static int  has_compl_option __ARGS((int dict_opt));
  static int  ins_compl_accept_char __ARGS((int c));
***************
*** 153,161 ****
  static void ins_compl_free __ARGS((void));
  static void ins_compl_clear __ARGS((void));
  static int  ins_compl_bs __ARGS((void));
  static void ins_compl_new_leader __ARGS((void));
  static void ins_compl_addleader __ARGS((int c));
! static int ins_compl_len __ARGS((void));
  static void ins_compl_restart __ARGS((void));
  static void ins_compl_set_original_text __ARGS((char_u *str));
  static void ins_compl_addfrommatch __ARGS((void));
--- 155,164 ----
  static void ins_compl_free __ARGS((void));
  static void ins_compl_clear __ARGS((void));
  static int  ins_compl_bs __ARGS((void));
+ static int  ins_compl_need_restart __ARGS((void));
  static void ins_compl_new_leader __ARGS((void));
  static void ins_compl_addleader __ARGS((int c));
! static int  ins_compl_len __ARGS((void));
  static void ins_compl_restart __ARGS((void));
  static void ins_compl_set_original_text __ARGS((char_u *str));
  static void ins_compl_addfrommatch __ARGS((void));
***************
*** 163,168 ****
--- 166,172 ----
  static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
  #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
  static void ins_compl_add_list __ARGS((list_T *list));
+ static void ins_compl_add_dict __ARGS((dict_T *dict));
  #endif
  static int  ins_compl_get_exp __ARGS((pos_T *ini));
  static void ins_compl_delete __ARGS((void));
***************
*** 3341,3347 ****
      /* Deleted more than what was used to find matches or didn't finish
       * finding all matches: need to look for matches all over again. */
      if (curwin->w_cursor.col <= compl_col + compl_length
! 						     || compl_was_interrupted)
  	ins_compl_restart();
  
      vim_free(compl_leader);
--- 3345,3351 ----
      /* Deleted more than what was used to find matches or didn't finish
       * finding all matches: need to look for matches all over again. */
      if (curwin->w_cursor.col <= compl_col + compl_length
! 						  || ins_compl_need_restart())
  	ins_compl_restart();
  
      vim_free(compl_leader);
***************
*** 3355,3360 ****
--- 3359,3378 ----
  }
  
  /*
+  * Return TRUE when we need to find matches again, ins_compl_restart() is to
+  * be called.
+  */
+     static int
+ ins_compl_need_restart()
+ {
+     /* Return TRUE if we didn't complete finding matches or when the
+      * 'completefunc' returned "always" in the "refresh" dictionary item. */
+     return compl_was_interrupted
+ 	|| ((ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI)
+ 						  && compl_opt_refresh_always);
+ }
+ 
+ /*
   * Called after changing "compl_leader".
   * Show the popup menu with a different set of matches.
   * May also search for matches again if the previous search was interrupted.
***************
*** 3443,3449 ****
  	ins_char(c);
  
      /* If we didn't complete finding matches we must search again. */
!     if (compl_was_interrupted)
  	ins_compl_restart();
  
      vim_free(compl_leader);
--- 3461,3467 ----
  	ins_char(c);
  
      /* If we didn't complete finding matches we must search again. */
!     if (ins_compl_need_restart())
  	ins_compl_restart();
  
      vim_free(compl_leader);
***************
*** 3871,3882 ****
      int		type;	    /* CTRL_X_OMNI or CTRL_X_FUNCTION */
      char_u	*base;
  {
!     list_T      *matchlist;
      char_u	*args[2];
      char_u	*funcname;
      pos_T	pos;
      win_T	*curwin_save;
      buf_T	*curbuf_save;
  
      funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
      if (*funcname == NUL)
--- 3889,3902 ----
      int		type;	    /* CTRL_X_OMNI or CTRL_X_FUNCTION */
      char_u	*base;
  {
!     list_T      *matchlist = NULL;
!     dict_T	*matchdict = NULL;
      char_u	*args[2];
      char_u	*funcname;
      pos_T	pos;
      win_T	*curwin_save;
      buf_T	*curbuf_save;
+     typval_T	rettv;
  
      funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
      if (*funcname == NUL)
***************
*** 3889,3895 ****
      pos = curwin->w_cursor;
      curwin_save = curwin;
      curbuf_save = curbuf;
!     matchlist = call_func_retlist(funcname, 2, args, FALSE);
      if (curwin_save != curwin || curbuf_save != curbuf)
      {
  	EMSG(_(e_complwin));
--- 3909,3933 ----
      pos = curwin->w_cursor;
      curwin_save = curwin;
      curbuf_save = curbuf;
! 
!     /* Call a function, which returns a list or dict. */
!     if (call_vim_function(funcname, 2, args, FALSE, &rettv) == OK)
!     {
! 	switch (rettv.v_type)
! 	{
! 	    case VAR_LIST:
! 		matchlist = rettv.vval.v_list;
! 		break;
! 	    case VAR_DICT:
! 		matchdict = rettv.vval.v_dict;
! 		break;
! 	    default:
! 		/* TODO: Give error message? */
! 		clear_tv(&rettv);
! 		break;
! 	}
!     }
! 
      if (curwin_save != curwin || curbuf_save != curbuf)
      {
  	EMSG(_(e_complwin));
***************
*** 3902,3911 ****
--- 3940,3954 ----
  	EMSG(_(e_compldel));
  	goto theend;
      }
+ 
      if (matchlist != NULL)
  	ins_compl_add_list(matchlist);
+     else if (matchdict != NULL)
+ 	ins_compl_add_dict(matchdict);
  
  theend:
+     if (matchdict != NULL)
+ 	dict_unref(matchdict);
      if (matchlist != NULL)
  	list_unref(matchlist);
  }
***************
*** 3934,3939 ****
--- 3977,4009 ----
  }
  
  /*
+  * Add completions from a dict.
+  */
+     static void
+ ins_compl_add_dict(dict)
+     dict_T	*dict;
+ {
+     dictitem_T	*refresh;
+     dictitem_T	*words;
+ 
+     /* Check for optional "refresh" item. */
+     compl_opt_refresh_always = FALSE;
+     refresh = dict_find(dict, (char_u *)"refresh", 7);
+     if (refresh != NULL && refresh->di_tv.v_type == VAR_STRING)
+     {
+ 	char_u	*v = refresh->di_tv.vval.v_string;
+ 
+ 	if (v != NULL && STRCMP(v, (char_u *)"always") == 0)
+ 	    compl_opt_refresh_always = TRUE;
+     }
+ 
+     /* Add completions from a "words" list. */
+     words = dict_find(dict, (char_u *)"words", 5);
+     if (words != NULL && words->di_tv.v_type == VAR_LIST)
+ 	ins_compl_add_list(words->di_tv.vval.v_list);
+ }
+ 
+ /*
   * Add a match to the list of matches from a typeval_T.
   * If the given string is already in the list of completions, then return
   * NOTDONE, otherwise add it to the list and return OK.  If there is an error,
***************
*** 5088,5093 ****
--- 5158,5169 ----
  		return FAIL;
  	    }
  
+ 	    /*
+ 	     * Reset extended parameters of completion, when start new
+ 	     * completion.
+ 	     */
+ 	    compl_opt_refresh_always = FALSE;
+ 
  	    if (col < 0)
  		col = curs_col;
  	    compl_col = col;
*** ../vim-7.3.310/src/eval.c	2011-09-14 14:33:47.000000000 +0200
--- src/eval.c	2011-09-14 16:16:47.000000000 +0200
***************
*** 380,388 ****
  
  static void prepare_vimvar __ARGS((int idx, typval_T *save_tv));
  static void restore_vimvar __ARGS((int idx, typval_T *save_tv));
- #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
- static int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
- #endif
  static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars));
  static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon));
  static char_u *skip_var_one __ARGS((char_u *arg));
--- 380,385 ----
***************
*** 451,457 ****
  static void set_ref_in_list __ARGS((list_T *l, int copyID));
  static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
  static int rettv_dict_alloc __ARGS((typval_T *rettv));
- static void dict_unref __ARGS((dict_T *d));
  static void dict_free __ARGS((dict_T *d, int recurse));
  static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
  static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item));
--- 448,453 ----
***************
*** 1563,1569 ****
   * arguments are currently supported.
   * Returns OK or FAIL.
   */
!     static int
  call_vim_function(func, argc, argv, safe, rettv)
      char_u      *func;
      int		argc;
--- 1559,1565 ----
   * arguments are currently supported.
   * Returns OK or FAIL.
   */
!     int
  call_vim_function(func, argc, argv, safe, rettv)
      char_u      *func;
      int		argc;
***************
*** 6903,6909 ****
   * Unreference a Dictionary: decrement the reference count and free it when it
   * becomes zero.
   */
!     static void
  dict_unref(d)
      dict_T *d;
  {
--- 6899,6905 ----
   * Unreference a Dictionary: decrement the reference count and free it when it
   * becomes zero.
   */
!     void
  dict_unref(d)
      dict_T *d;
  {
*** ../vim-7.3.310/src/proto/eval.pro	2010-08-15 21:57:28.000000000 +0200
--- src/proto/eval.pro	2011-09-14 16:16:47.000000000 +0200
***************
*** 23,28 ****
--- 23,29 ----
  list_T *eval_spell_expr __ARGS((char_u *badword, char_u *expr));
  int get_spellword __ARGS((list_T *list, char_u **pp));
  typval_T *eval_expr __ARGS((char_u *arg, char_u **nextcmd));
+ int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
  void *call_func_retstr __ARGS((char_u *func, int argc, char_u **argv, int safe));
  long call_func_retnr __ARGS((char_u *func, int argc, char_u **argv, int safe));
  void *call_func_retlist __ARGS((char_u *func, int argc, char_u **argv, int safe));
***************
*** 52,57 ****
--- 53,59 ----
  int list_append_string __ARGS((list_T *l, char_u *str, int len));
  int garbage_collect __ARGS((void));
  dict_T *dict_alloc __ARGS((void));
+ void dict_unref __ARGS((dict_T *d));
  dictitem_T *dictitem_alloc __ARGS((char_u *key));
  void dictitem_free __ARGS((dictitem_T *item));
  int dict_add __ARGS((dict_T *d, dictitem_T *item));
*** ../vim-7.3.310/src/version.c	2011-09-14 16:04:52.000000000 +0200
--- src/version.c	2011-09-14 16:25:08.000000000 +0200
***************
*** 711,712 ****
--- 711,714 ----
  {   /* Add new patch number below this line */
+ /**/
+     311,
  /**/

-- 
Contrary to popular belief, it's often your clothing that gets promoted, not
you.
				(Scott Adams - The Dilbert principle)

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