@@ -179,8 +179,8 @@ static void ins_compl_add_dict(dict_T *dict);
179179#endif
180180static int ins_compl_get_exp (pos_T * ini );
181181static void ins_compl_delete (void );
182- static void ins_compl_insert (void );
183- static int ins_compl_next (int allow_get_expansion , int count , int insert_match );
182+ static void ins_compl_insert (int in_compl_func );
183+ static int ins_compl_next (int allow_get_expansion , int count , int insert_match , int in_compl_func );
184184static int ins_compl_key2dir (int c );
185185static int ins_compl_pum_key (int c );
186186static int ins_compl_key2count (int c );
@@ -861,7 +861,7 @@ edit(
861861 && (c == CAR || c == K_KENTER || c == NL )))
862862 {
863863 ins_compl_delete ();
864- ins_compl_insert ();
864+ ins_compl_insert (FALSE );
865865 }
866866 }
867867 }
@@ -3297,7 +3297,7 @@ ins_compl_files(
32973297 break ;
32983298 }
32993299 line_breakcheck ();
3300- ins_compl_check_keys (50 );
3300+ ins_compl_check_keys (50 , FALSE );
33013301 }
33023302 fclose (fp );
33033303 }
@@ -4036,8 +4036,6 @@ ins_compl_next_buf(buf_T *buf, int flag)
40364036}
40374037
40384038#ifdef FEAT_COMPL_FUNC
4039- static void expand_by_function (int type , char_u * base );
4040-
40414039/*
40424040 * Execute user defined complete function 'completefunc' or 'omnifunc', and
40434041 * get matches in "matches".
@@ -4596,7 +4594,7 @@ ins_compl_get_exp(pos_T *ini)
45964594 break ;
45974595 /* Fill the popup menu as soon as possible. */
45984596 if (type != -1 )
4599- ins_compl_check_keys (0 );
4597+ ins_compl_check_keys (0 , FALSE );
46004598
46014599 if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL (ctrl_x_mode ))
46024600 || compl_interrupted )
@@ -4653,9 +4651,12 @@ ins_compl_delete(void)
46534651 set_vim_var_dict (VV_COMPLETED_ITEM , dict_alloc ());
46544652}
46554653
4656- /* Insert the new text being completed. */
4654+ /*
4655+ * Insert the new text being completed.
4656+ * "in_compl_func" is TRUE when called from complete_check().
4657+ */
46574658 static void
4658- ins_compl_insert (void )
4659+ ins_compl_insert (int in_compl_func )
46594660{
46604661 dict_T * dict ;
46614662
@@ -4682,7 +4683,8 @@ ins_compl_insert(void)
46824683 EMPTY_IF_NULL (compl_shown_match -> cp_text [CPT_INFO ]));
46834684 }
46844685 set_vim_var_dict (VV_COMPLETED_ITEM , dict );
4685- compl_curr_match = compl_shown_match ;
4686+ if (!in_compl_func )
4687+ compl_curr_match = compl_shown_match ;
46864688}
46874689
46884690/*
@@ -4706,7 +4708,8 @@ ins_compl_next(
47064708 int allow_get_expansion ,
47074709 int count , /* repeat completion this many times; should
47084710 be at least 1 */
4709- int insert_match ) /* Insert the newly selected match */
4711+ int insert_match , /* Insert the newly selected match */
4712+ int in_compl_func ) /* called from complete_check() */
47104713{
47114714 int num_matches = -1 ;
47124715 int i ;
@@ -4856,7 +4859,7 @@ ins_compl_next(
48564859 else if (insert_match )
48574860 {
48584861 if (!compl_get_longest || compl_used_match )
4859- ins_compl_insert ();
4862+ ins_compl_insert (in_compl_func );
48604863 else
48614864 ins_bytes (compl_leader + ins_compl_len ());
48624865 }
@@ -4921,9 +4924,11 @@ ins_compl_next(
49214924 * mode. Also, when compl_pending is not zero, show a completion as soon as
49224925 * possible. -- webb
49234926 * "frequency" specifies out of how many calls we actually check.
4927+ * "in_compl_func" is TRUE when called from complete_check(), don't set
4928+ * compl_curr_match.
49244929 */
49254930 void
4926- ins_compl_check_keys (int frequency )
4931+ ins_compl_check_keys (int frequency , int in_compl_func )
49274932{
49284933 static int count = 0 ;
49294934
@@ -4949,7 +4954,7 @@ ins_compl_check_keys(int frequency)
49494954 c = safe_vgetc (); /* Eat the character */
49504955 compl_shows_dir = ins_compl_key2dir (c );
49514956 (void )ins_compl_next (FALSE, ins_compl_key2count (c ),
4952- c != K_UP && c != K_DOWN );
4957+ c != K_UP && c != K_DOWN , in_compl_func );
49534958 }
49544959 else
49554960 {
@@ -4972,7 +4977,7 @@ ins_compl_check_keys(int frequency)
49724977 int todo = compl_pending > 0 ? compl_pending : - compl_pending ;
49734978
49744979 compl_pending = 0 ;
4975- (void )ins_compl_next (FALSE, todo , TRUE);
4980+ (void )ins_compl_next (FALSE, todo , TRUE, in_compl_func );
49764981 }
49774982}
49784983
@@ -5490,7 +5495,8 @@ ins_complete(int c, int enable_pum)
54905495 * Find next match (and following matches).
54915496 */
54925497 save_w_wrow = curwin -> w_wrow ;
5493- n = ins_compl_next (TRUE, ins_compl_key2count (c ), ins_compl_use_match (c ));
5498+ n = ins_compl_next (TRUE, ins_compl_key2count (c ),
5499+ ins_compl_use_match (c ), FALSE);
54945500
54955501 /* may undisplay the popup menu */
54965502 ins_compl_upd_pum ();
0 commit comments