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
1 change: 1 addition & 0 deletions autoload/fern/mapping.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ call s:Config.config(expand('<sfile>:p'), {
\ 'node',
\ 'open',
\ 'tree',
\ 'wait',
\ ],
\})
38 changes: 38 additions & 0 deletions autoload/fern/mapping/wait.vim
Original file line number Diff line number Diff line change
@@ -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 <buffer><silent>
\ <Plug>(fern-wait-viewer:ready)
\ :<C-u>call <SID>call('hook', 'viewer:ready')<CR>
nmap <buffer> <Plug>(fern-wait) <Plug>(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('<sfile>:p'), {
\ 'interval': 100,
\ 'timeout': 1000,
\})
19 changes: 19 additions & 0 deletions doc/fern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ hit "e", add the following code:
" Use 'open:split' instead of 'open:edit' for 'open' action
nmap <buffer> <Plug>(fern-action-open) <Plug>(fern-action-open:split)
<
*fern-custom-wait*
Fern provide following mapping helper:

*<Plug>(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 <buffer> <Plug>(fern-my-leave-and-tcd)
\ <Plug>(fern-action-leave)
\ <Plug>(fern-wait)
\ <Plug>(fern-action-tcd:root)
<
Without <Plug>(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:

Expand Down