1
Fork 0

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.
This commit is contained in:
Camille Dejoye 2020-06-13 11:28:30 +02:00
parent 12ea40a812
commit eff4334368
1 changed files with 9 additions and 1 deletions

View File

@ -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 " }}}