From 0dbedeab66b0397b7edd7fd2b0773db7b427a6ab Mon Sep 17 00:00:00 2001 From: lambdalisue Date: Fri, 12 Jun 2020 11:43:58 +0900 Subject: [PATCH 1/2] Add (fern-wait) to wait ready --- autoload/fern/mapping.vim | 1 + autoload/fern/mapping/wait.vim | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 autoload/fern/mapping/wait.vim diff --git a/autoload/fern/mapping.vim b/autoload/fern/mapping.vim index df7148ba..1eb226b6 100644 --- a/autoload/fern/mapping.vim +++ b/autoload/fern/mapping.vim @@ -29,5 +29,6 @@ call s:Config.config(expand(':p'), { \ 'node', \ 'open', \ 'tree', + \ 'wait', \ ], \}) diff --git a/autoload/fern/mapping/wait.vim b/autoload/fern/mapping/wait.vim new file mode 100644 index 00000000..d1d49fee --- /dev/null +++ b/autoload/fern/mapping/wait.vim @@ -0,0 +1,38 @@ +let s:Config = vital#fern#import('Config') +let s:Promise = vital#fern#import('Async.Promise') + +function! fern#mapping#wait#init(disable_default_mappings) abort + nnoremap + \ (fern-wait-viewer:ready) + \ :call call('hook', 'viewer:ready') + nmap (fern-wait) (fern-wait-viewer:ready) +endfunction + +function! s:call(name, ...) abort + return call( + \ 'fern#mapping#call', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + +function! s:map_hook(helper, hook) abort + let [_, err] = s:Promise.wait( + \ fern#hook#promise(a:hook), + \ { + \ 'interval': g:fern#mapping#wait#interval, + \ 'timeout': g:fern#mapping#wait#timeout, + \ }, + \) + if err isnot# v:null + throw printf( + \ '[fern] Failed to wait hook "%s": %s', + \ a:hook, + \ err, + \) + endif +endfunction + +call s:Config.config(expand(':p'), { + \ 'interval': 100, + \ 'timeout': 1000, + \}) From d62d87af96dd0e2c4c0a9f967cc0c741c390ad76 Mon Sep 17 00:00:00 2001 From: lambdalisue Date: Fri, 12 Jun 2020 11:49:22 +0900 Subject: [PATCH 2/2] Add document about (fern-wait) --- doc/fern.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/fern.txt b/doc/fern.txt index 834da263..5ad5279f 100644 --- a/doc/fern.txt +++ b/doc/fern.txt @@ -169,6 +169,25 @@ hit "e", add the following code: " Use 'open:split' instead of 'open:edit' for 'open' action nmap (fern-action-open) (fern-action-open:split) < + *fern-custom-wait* +Fern provide following mapping helper: + + *(fern-wait)* Wait until the fern buffer become ready which + would opened just before this mapping. This is + required while fern buffers are loaded + asynchronously but mappings are inovked + synchronously. + +For example, following execute "tcd:root" action every after "leave" action. +> + nmap (fern-my-leave-and-tcd) + \ (fern-action-leave) + \ (fern-wait) + \ (fern-action-tcd:root) +< +Without (fern-wait), the "tcd:root" action will be invoked before actual +"leave" while "leave" action is asynchronous. + *fern-custom-smart* Fern provide following mapping helper functions: