diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/insexpand.c | 17 | ||||
-rw-r--r-- | src/nvim/vvars.lua | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index a1cebb407e..93d081153c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -561,11 +561,19 @@ static bool is_first_match(const compl_T *const match) return match == compl_first_match; } -static void do_autocmd_completedone(int c) +static void do_autocmd_completedone(int c, int mode, char *word) { save_v_event_T save_v_event; dict_T *v_event = get_v_event(&save_v_event); + mode = mode & ~CTRL_X_WANT_IDENT; + char *mode_str = NULL; + if (ctrl_x_mode_names[mode]) { + mode_str = ctrl_x_mode_names[mode]; + } + tv_dict_add_str(v_event, S_LEN("complete_word"), word != NULL ? word : ""); + tv_dict_add_str(v_event, S_LEN("complete_type"), mode_str != NULL ? mode_str : ""); + tv_dict_add_str(v_event, S_LEN("reason"), (c == Ctrl_Y ? "accept" : "cancel")); tv_dict_set_keys_readonly(v_event); @@ -2115,12 +2123,14 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) } } + char *word = NULL; // If the popup menu is displayed pressing CTRL-Y means accepting // the selection without inserting anything. When // compl_enter_selects is set the Enter key does the same. if ((c == Ctrl_Y || (compl_enter_selects && (c == CAR || c == K_KENTER || c == NL))) && pum_visible()) { + word = xstrdup(compl_shown_match->cp_str); retval = true; } @@ -2178,7 +2188,8 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) } // Trigger the CompleteDone event to give scripts a chance to act // upon the end of completion. - do_autocmd_completedone(c); + do_autocmd_completedone(c, prev_mode, word); + xfree(word); return retval; } @@ -2267,7 +2278,7 @@ bool ins_compl_prep(int c) } else if (ctrl_x_mode == CTRL_X_LOCAL_MSG) { // Trigger the CompleteDone event to give scripts a chance to act // upon the (possibly failed) completion. - do_autocmd_completedone(c); + do_autocmd_completedone(c, ctrl_x_mode, NULL); } may_trigger_modechanged(); diff --git a/src/nvim/vvars.lua b/src/nvim/vvars.lua index 5fc014a50c..f1b8c22bdd 100644 --- a/src/nvim/vvars.lua +++ b/src/nvim/vvars.lua @@ -208,6 +208,8 @@ M.vars = { changing window (or tab) on |DirChanged|. status Job status or exit code, -1 means "unknown". |TermClose| reason Reason for completion being done. |CompleteDone| + complete_word The word that was selected, empty if abandoned complete. + complete_type See |complete_info_mode| ]=], }, exception = { |