comparison src/insexpand.c @ 16268:0f65f2808470 v8.1.1138

patch 8.1.1138: plugins don't get notified when the popup menu changes commit https://github.com/vim/vim/commit/d7f246c68cfb97406bcd4b098a2df2d870b3ef92 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 8 18:15:41 2019 +0200 patch 8.1.1138: plugins don't get notified when the popup menu changes Problem: Plugins don't get notified when the popup menu changes. Solution: Add the CompleteChanged event. (Andy Massimino. closes https://github.com/vim/vim/issues/4176)
author Bram Moolenaar <Bram@vim.org>
date Mon, 08 Apr 2019 18:30:06 +0200
parents 5df26b29e809
children 54ffc82f38a8
comparison
equal deleted inserted replaced
16267:b471858040bc 16268:0f65f2808470
201 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); 201 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
202 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) 202 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
203 static void ins_compl_add_list(list_T *list); 203 static void ins_compl_add_list(list_T *list);
204 static void ins_compl_add_dict(dict_T *dict); 204 static void ins_compl_add_dict(dict_T *dict);
205 # endif 205 # endif
206 static dict_T *ins_compl_dict_alloc(compl_T *match);
206 static int ins_compl_key2dir(int c); 207 static int ins_compl_key2dir(int c);
207 static int ins_compl_pum_key(int c); 208 static int ins_compl_pum_key(int c);
208 static int ins_compl_key2count(int c); 209 static int ins_compl_key2count(int c);
209 static void show_pum(int prev_w_wrow, int prev_w_leftcol); 210 static void show_pum(int prev_w_wrow, int prev_w_leftcol);
210 static unsigned quote_meta(char_u *dest, char_u *str, int len); 211 static unsigned quote_meta(char_u *dest, char_u *str, int len);
992 if (strstr((char *)p_cot, "menuone") != NULL) 993 if (strstr((char *)p_cot, "menuone") != NULL)
993 return (i >= 1); 994 return (i >= 1);
994 return (i >= 2); 995 return (i >= 2);
995 } 996 }
996 997
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
997 /* 1029 /*
998 * Show the popup menu for the list of matches. 1030 * Show the popup menu for the list of matches.
999 * Also adjusts "compl_shown_match" to an entry that is actually displayed. 1031 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
1000 */ 1032 */
1001 void 1033 void
1134 // Use the cursor to get all wrapping and other settings right. 1166 // Use the cursor to get all wrapping and other settings right.
1135 col = curwin->w_cursor.col; 1167 col = curwin->w_cursor.col;
1136 curwin->w_cursor.col = compl_col; 1168 curwin->w_cursor.col = compl_col;
1137 pum_display(compl_match_array, compl_match_arraysize, cur); 1169 pum_display(compl_match_array, compl_match_arraysize, cur);
1138 curwin->w_cursor.col = col; 1170 curwin->w_cursor.col = col;
1171
1172 if (has_completechanged())
1173 trigger_complete_changed_event(cur);
1139 } 1174 }
1140 } 1175 }
1141 1176
1142 #define DICT_FIRST (1) // use just first element in "dict" 1177 #define DICT_FIRST (1) // use just first element in "dict"
1143 #define DICT_EXACT (2) // "dict" is the exact name of a file 1178 #define DICT_EXACT (2) // "dict" is the exact name of a file
2897 ins_bytes(compl_shown_match->cp_str + ins_compl_len()); 2932 ins_bytes(compl_shown_match->cp_str + ins_compl_len());
2898 if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) 2933 if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT)
2899 compl_used_match = FALSE; 2934 compl_used_match = FALSE;
2900 else 2935 else
2901 compl_used_match = TRUE; 2936 compl_used_match = TRUE;
2902 2937 dict = ins_compl_dict_alloc(compl_shown_match);
2903 // Set completed item.
2904 // { word, abbr, menu, kind, info }
2905 dict = dict_alloc_lock(VAR_FIXED);
2906 if (dict != NULL)
2907 {
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]);
2915 }
2916 set_vim_var_dict(VV_COMPLETED_ITEM, dict); 2938 set_vim_var_dict(VV_COMPLETED_ITEM, dict);
2917 if (!in_compl_func) 2939 if (!in_compl_func)
2918 compl_curr_match = compl_shown_match; 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);
2951
2952 if (dict != NULL)
2953 {
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]);
2960 }
2961 return dict;
2919 } 2962 }
2920 2963
2921 /* 2964 /*
2922 * Fill in the next completion in the current direction. 2965 * Fill in the next completion in the current direction.
2923 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to 2966 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to