@@ -203,6 +203,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
203203static void ins_compl_add_list (list_T * list );
204204static void ins_compl_add_dict (dict_T * dict );
205205# endif
206+ static dict_T * ins_compl_dict_alloc (compl_T * match );
206207static int ins_compl_key2dir (int c );
207208static int ins_compl_pum_key (int c );
208209static int ins_compl_key2count (int c );
@@ -994,6 +995,37 @@ pum_enough_matches(void)
994995 return (i >= 2 );
995996}
996997
998+ static void
999+ trigger_complete_changed_event (int cur )
1000+ {
1001+ dict_T * v_event ;
1002+ dict_T * item ;
1003+ static int recursive = FALSE;
1004+
1005+ if (recursive )
1006+ return ;
1007+
1008+ v_event = get_vim_var_dict (VV_EVENT );
1009+ if (cur < 0 )
1010+ item = dict_alloc ();
1011+ else
1012+ item = ins_compl_dict_alloc (compl_curr_match );
1013+ if (item == NULL )
1014+ return ;
1015+ dict_add_dict (v_event , "completed_item" , item );
1016+ pum_set_event_info (v_event );
1017+ dict_set_items_ro (v_event );
1018+
1019+ recursive = TRUE;
1020+ textlock ++ ;
1021+ apply_autocmds (EVENT_COMPLETECHANGED , NULL , NULL , FALSE, curbuf );
1022+ textlock -- ;
1023+ recursive = FALSE;
1024+
1025+ dict_free_contents (v_event );
1026+ hash_init (& v_event -> dv_hashtab );
1027+ }
1028+
9971029/*
9981030 * Show the popup menu for the list of matches.
9991031 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
@@ -1136,6 +1168,9 @@ ins_compl_show_pum(void)
11361168 curwin -> w_cursor .col = compl_col ;
11371169 pum_display (compl_match_array , compl_match_arraysize , cur );
11381170 curwin -> w_cursor .col = col ;
1171+
1172+ if (has_completechanged ())
1173+ trigger_complete_changed_event (cur );
11391174 }
11401175}
11411176
@@ -2899,23 +2934,31 @@ ins_compl_insert(int in_compl_func)
28992934 compl_used_match = FALSE;
29002935 else
29012936 compl_used_match = TRUE;
2937+ dict = ins_compl_dict_alloc (compl_shown_match );
2938+ set_vim_var_dict (VV_COMPLETED_ITEM , dict );
2939+ if (!in_compl_func )
2940+ compl_curr_match = compl_shown_match ;
2941+ }
2942+
2943+ /*
2944+ * Allocate Dict for the completed item.
2945+ * { word, abbr, menu, kind, info }
2946+ */
2947+ static dict_T *
2948+ ins_compl_dict_alloc (compl_T * match )
2949+ {
2950+ dict_T * dict = dict_alloc_lock (VAR_FIXED );
29022951
2903- // Set completed item.
2904- // { word, abbr, menu, kind, info }
2905- dict = dict_alloc_lock (VAR_FIXED );
29062952 if (dict != NULL )
29072953 {
2908- dict_add_string (dict , "word" , compl_shown_match -> cp_str );
2909- dict_add_string (dict , "abbr" , compl_shown_match -> cp_text [CPT_ABBR ]);
2910- dict_add_string (dict , "menu" , compl_shown_match -> cp_text [CPT_MENU ]);
2911- dict_add_string (dict , "kind" , compl_shown_match -> cp_text [CPT_KIND ]);
2912- dict_add_string (dict , "info" , compl_shown_match -> cp_text [CPT_INFO ]);
2913- dict_add_string (dict , "user_data" ,
2914- compl_shown_match -> cp_text [CPT_USER_DATA ]);
2954+ dict_add_string (dict , "word" , match -> cp_str );
2955+ dict_add_string (dict , "abbr" , match -> cp_text [CPT_ABBR ]);
2956+ dict_add_string (dict , "menu" , match -> cp_text [CPT_MENU ]);
2957+ dict_add_string (dict , "kind" , match -> cp_text [CPT_KIND ]);
2958+ dict_add_string (dict , "info" , match -> cp_text [CPT_INFO ]);
2959+ dict_add_string (dict , "user_data" , match -> cp_text [CPT_USER_DATA ]);
29152960 }
2916- set_vim_var_dict (VV_COMPLETED_ITEM , dict );
2917- if (!in_compl_func )
2918- compl_curr_match = compl_shown_match ;
2961+ return dict ;
29192962}
29202963
29212964/*
0 commit comments