Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions autoload/dpp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ function dpp#util#_execute_hook(plugin, hook_name, plugin_name, hook) abort
endif
endif

let g:dpp#hook_result = v:null

try
" NOTE: hook may contain \r in Windows
const cmds = a:hook->split('\r\?\n')
Expand Down
32 changes: 32 additions & 0 deletions doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Interface |dpp-interface|
Functions |dpp-functions|
Plugin options |dpp-plugin-options|
Lua functions. |dpp-lua-functions|
Variables |dpp-variables|
Dpp Sources |dpp-ddu-sources|
Examples |dpp-examples|
Plugins merged feature |dpp-merge|
Expand Down Expand Up @@ -553,6 +554,14 @@ HOOKS *dpp-hooks*
NOTE: |Vim9| script syntax is very strict and it is hard to
debug. It is experimental feature.

To return a value from a hook, assign it to |g:dpp#hook_result|.
The variable is reset to |v:null| before each hook execution.
>vim
hook_source = '''
let g:dpp#hook_result = s:configure()
'''
<

*dpp-plugin-option-hooks_file*
hooks_file (String) or (List)
Hooks file path. It must be valid path.
Expand Down Expand Up @@ -739,6 +748,29 @@ dpp.source([{name}])
dpp.sync_ext_action({ext-name}, {action-name}[, {action-params}])
Same as |dpp#sync_ext_action()|.

==============================================================================
VARIABLES *dpp-variables*

*g:dpp#hook_result*
g:dpp#hook_result
The variable is set to |v:null| before each hook is executed.
Inside a hook string you can assign any value to it in order to
communicate a result back to the caller.
>vim
hook_source = '''
" Compute something and store the result
let g:dpp#hook_result = s:my_function()
'''
<
After |dpp#util#_execute_hook()| returns, the variable holds
whatever the hook last assigned, or |v:null| if the hook did
not assign anything.

NOTE: Because hooks may be executed sequentially in a loop
(e.g. by |dpp#call_hook()|), read the value immediately after
the hook you are interested in, before the next hook overwrites
it.

==============================================================================
DDU SOURCES *dpp-ddu-sources*

Expand Down
Loading