From eff4334368480c62ed4955a17c576a3ff1e272ab Mon Sep 17 00:00:00 2001 From: Camille Dejoye Date: Sat, 13 Jun 2020 11:28:30 +0200 Subject: [PATCH] fix: execution order of post hooks The hooks were executed in the same order regarding of if they were pre or post hooks. This is actually not a correct behavior, let's assume we want to create a hook responsible for keeping the position of the cursor between operations: The pre hook will have to extract the current position of the cursor and therefore should be the first one to be executed, let's say we gave it a priority 0. The post hook will have to reposition the cursor after the transformation and therefore should be the last one to be executed. That's why we need to reverse the order of the post hooks. --- autoload/argwrap/hooks.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/argwrap/hooks.vim b/autoload/argwrap/hooks.vim index 559fe76..0462ac2 100644 --- a/autoload/argwrap/hooks.vim +++ b/autoload/argwrap/hooks.vim @@ -37,7 +37,15 @@ function! s:load() abort " {{{ endfunction " }}} function! argwrap#hooks#execute(name, ...) abort " {{{ - for hook in s:load() + " Reverse the order of the hooks for post hooks so that a pre hook with a + " low priority is executed before and a post hook is executed after + " For instance for a hook responsible to preserve the cursor position it + " must be the first to be executed to save the position of the cursor but + " the last to be executed to restore it after all other hooks have been + " executed + let l:hooks = a:name =~? '\v^post' ? reverse(copy(s:load())) : s:load() + + for hook in l:hooks silent! call call(printf('%s#%s', hook, a:name), a:000) endfor endfunction " }}}