Skip to content

Commit 3f169ce

Browse files
committed
patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Problem: Triggering CompleteDone earlier is not backwards compatible. (Daniel Hahler) Solution: Add CompleteDonePre instead.
1 parent 318e7a9 commit 3f169ce

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

runtime/doc/autocmd.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ Name triggered by ~
374374

375375
|MenuPopup| just before showing the popup menu
376376
|CompleteChanged| after Insert mode completion menu changed
377-
|CompleteDone| after Insert mode completion is done
377+
|CompleteDonePre| after Insert mode completion is done, before clearing
378+
info
379+
|CompleteDone| after Insert mode completion is done, after clearing
380+
info
378381

379382
|User| to be used in combination with ":doautocmd"
380383

@@ -589,8 +592,8 @@ ColorSchemePre Before loading a color scheme. |:colorscheme|
589592
CompleteChanged *CompleteChanged*
590593
After each time the Insert mode completion
591594
menu changed. Not fired on popup menu hide,
592-
use |CompleteDone| for that. Never triggered
593-
recursively.
595+
use |CompleteDonePre| or |CompleteDone| for
596+
that. Never triggered recursively.
594597

595598
Sets these |v:event| keys:
596599
completed_item See |complete-items|.
@@ -606,12 +609,22 @@ CompleteChanged *CompleteChanged*
606609
The size and position of the popup are also
607610
available by calling |pum_getpos()|.
608611

612+
*CompleteDonePre*
613+
CompleteDonePre After Insert mode completion is done. Either
614+
when something was completed or abandoning
615+
completion. |ins-completion|
616+
|complete_info()| can be used, the info is
617+
cleared after triggering CompleteDonePre.
618+
The |v:completed_item| variable contains
619+
information about the completed item.
620+
609621
*CompleteDone*
610622
CompleteDone After Insert mode completion is done. Either
611623
when something was completed or abandoning
612624
completion. |ins-completion|
613-
|complete_info()| can be used, the info is
614-
cleared after triggering CompleteDone.
625+
|complete_info()| cannot be used, the info is
626+
cleared before triggering CompleteDone. Use
627+
CompleteDonePre if you need it.
615628
The |v:completed_item| variable contains
616629
information about the completed item.
617630

src/autocmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static struct event_name
114114
{"ColorSchemePre", EVENT_COLORSCHEMEPRE},
115115
{"CompleteChanged", EVENT_COMPLETECHANGED},
116116
{"CompleteDone", EVENT_COMPLETEDONE},
117+
{"CompleteDonePre", EVENT_COMPLETEDONEPRE},
117118
{"CursorHold", EVENT_CURSORHOLD},
118119
{"CursorHoldI", EVENT_CURSORHOLDI},
119120
{"CursorMoved", EVENT_CURSORMOVED},

src/insexpand.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,12 +2061,11 @@ ins_compl_prep(int c)
20612061

20622062
auto_format(FALSE, TRUE);
20632063

2064-
// Trigger the CompleteDone event to give scripts a chance to
2065-
// act upon the completion. Do this before clearing the info,
2066-
// and restore ctrl_x_mode, so that complete_info() can be
2067-
// used.
2064+
// Trigger the CompleteDonePre event to give scripts a chance to
2065+
// act upon the completion before clearing the info, and restore
2066+
// ctrl_x_mode, so that complete_info() can be used.
20682067
ctrl_x_mode = prev_mode;
2069-
ins_apply_autocmds(EVENT_COMPLETEDONE);
2068+
ins_apply_autocmds(EVENT_COMPLETEDONEPRE);
20702069

20712070
ins_compl_free();
20722071
compl_started = FALSE;
@@ -2092,6 +2091,9 @@ ins_compl_prep(int c)
20922091
if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
20932092
do_c_expr_indent();
20942093
#endif
2094+
// Trigger the CompleteDone event to give scripts a chance to act
2095+
// upon the end of completion.
2096+
ins_apply_autocmds(EVENT_COMPLETEDONE);
20952097
}
20962098
}
20972099
else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)

src/testdir/test_ins_complete.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,17 @@ func s:CompleteDone_CheckCompletedItemNone()
175175
let s:called_completedone = 1
176176
endfunc
177177

178-
func s:CompleteDone_CheckCompletedItemDict()
178+
func s:CompleteDone_CheckCompletedItemDict(pre)
179179
call assert_equal( 'aword', v:completed_item[ 'word' ] )
180180
call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
181181
call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
182182
call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
183183
call assert_equal( 'W', v:completed_item[ 'kind' ] )
184184
call assert_equal( 'test', v:completed_item[ 'user_data' ] )
185185

186-
call assert_equal('function', complete_info().mode)
186+
if a:pre
187+
call assert_equal('function', complete_info().mode)
188+
endif
187189

188190
let s:called_completedone = 1
189191
endfunc
@@ -205,7 +207,8 @@ func Test_CompleteDoneNone()
205207
endfunc
206208

207209
func Test_CompleteDoneDict()
208-
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict()
210+
au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1)
211+
au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0)
209212

210213
set completefunc=<SID>CompleteDone_CompleteFuncDict
211214
execute "normal a\<C-X>\<C-U>\<C-Y>"

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ static char *(features[]) =
742742

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
158,
745747
/**/
746748
157,
747749
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ enum auto_event
13031303
EVENT_COLORSCHEMEPRE, // before loading a colorscheme
13041304
EVENT_COMPLETECHANGED, // after completion popup menu changed
13051305
EVENT_COMPLETEDONE, // after finishing insert complete
1306+
EVENT_COMPLETEDONEPRE, // idem, before clearing info
13061307
EVENT_CURSORHOLD, // cursor in same position for a while
13071308
EVENT_CURSORHOLDI, // idem, in Insert mode
13081309
EVENT_CURSORMOVED, // cursor was moved

0 commit comments

Comments
 (0)