From b9cf1b0758f26874d17aaea5eeff21c79db3fcec Mon Sep 17 00:00:00 2001 From: kuuote Date: Fri, 1 Sep 2023 10:22:16 +0900 Subject: [PATCH] :bug: Fix always use last callback at `wait_async()` --- autoload/denops/plugin.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/autoload/denops/plugin.vim b/autoload/denops/plugin.vim index dab4dd53..3ddd6f69 100644 --- a/autoload/denops/plugin.vim +++ b/autoload/denops/plugin.vim @@ -164,6 +164,13 @@ function! s:DenopsSystemPluginPre() abort execute printf('doautocmd User DenopsPluginPre:%s', l:plugin) endfunction +" Split function to create new callstack independent for loop, +" because overwrited callback references when +" before timer processing timings. +function! s:delay_callback(callback) abort + call timer_start(0, { -> a:callback() }) +endfunction + function! s:DenopsSystemPluginPost() abort let l:plugin = matchstr(expand(''), 'DenopsSystemPluginPost:\zs.*') let s:loaded_plugins[l:plugin] = 0 @@ -174,7 +181,7 @@ function! s:DenopsSystemPluginPost() abort " behavior. let l:callbacks = has('nvim') ? l:callbacks : reverse(l:callbacks) for l:Callback in l:callbacks - call timer_start(0, { -> l:Callback() }) + call s:delay_callback(l:Callback) endfor endif execute printf('doautocmd User DenopsPluginPost:%s', l:plugin)