From f7e39155de6e5e27262d4222b33ebb8af2e13056 Mon Sep 17 00:00:00 2001 From: Camille Dejoye Date: Sat, 6 Jun 2020 19:49:50 +0200 Subject: [PATCH] improvement: trigger post hooks after wrap/unwrap A first step to make the plugin extendable. This allow to add logic on a per filetype basis. This solution allow a user to extend the behavior if the plugin does not provide a hook for the given filetype. But if there is already a hook then the user can not create it's own. One solution could be to find every functions defined in the namespace `argwrap#hooks#user##post_wrap`, I think airline provide a feature like this. Those hooks would need to be sorted in order to have a predictible behavior, also it might be interesting to provide a way for each hook to update the range, container and arguments. There might be nothing to do because I think Vim's lists and dictionaries are passed by reference. --- autoload/argwrap.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/autoload/argwrap.vim b/autoload/argwrap.vim index 3693b85..c7b5049 100644 --- a/autoload/argwrap.vim +++ b/autoload/argwrap.vim @@ -259,9 +259,19 @@ function! argwrap#toggle() if l:range.lineStart == l:range.lineEnd call argwrap#wrapContainer(l:range, l:container, l:arguments, l:wrapBrace, l:tailComma, l:tailCommaBraces, l:tailIndentBraces, l:linePrefix, l:commaFirst, l:commaFirstIndent) let l:cursor[1] = l:range.lineStart + 1 + + let l:filetypeHook = printf('argwrap#hooks#%s#post_wrap', &filetype) + if exists('*'.l:filetypeHook) + call call(l:filetypeHook, [l:range, l:container, l:arguments]) + endif else call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded) let l:cursor[1] = l:range.lineStart + + let l:filetypeHook = printf('argwrap#hooks#%s#post_unwrap', &filetype) + if exists('*'.l:filetypeHook) + call call(l:filetypeHook, [l:range, l:container, l:arguments]) + endif endif call setpos('.', l:cursor)