Skip to content

Commit

Permalink
Merge pull request #113 from lambdalisue/ferndo
Browse files Browse the repository at this point in the history
Add :FernDo command and deprecate :FernFocus command
  • Loading branch information
lambdalisue authored Jun 13, 2020
2 parents a4465a3 + 578b127 commit 3f5d5c1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 42 deletions.
47 changes: 47 additions & 0 deletions autoload/fern/internal/command/do.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function! fern#internal#command#do#command(mods, fargs) abort
let winid_saved = win_getid()
try
let stay = fern#internal#args#pop(a:fargs, 'stay', v:false)
let drawer = fern#internal#args#pop(a:fargs, 'drawer', v:false)

if len(a:fargs) is# 0
\ || type(stay) isnot# v:t_bool
\ || type(drawer) isnot# v:t_bool
throw 'Usage: FernDo {expr...} [-drawer] [-stay]'
endif

" Does all options are handled?
call fern#internal#args#throw_if_dirty(a:fargs)

let found = fern#internal#window#find(
\ funcref('s:predicator', [drawer]),
\ winnr() + 1,
\)
if !found
return
endif
call win_gotoid(win_getid(found))
execute join([a:mods] + a:fargs, ' ')
catch
echohl ErrorMsg
echo v:exception
echohl None
call fern#logger#debug(v:exception)
call fern#logger#debug(v:throwpoint)
finally
if stay
call win_gotoid(winid_saved)
endif
endtry
endfunction

function! fern#internal#command#do#complete(arglead, cmdline, cursorpos) abort
return fern#internal#complete#options(a:arglead, a:cmdline, a:cursorpos)
endfunction

function! s:predicator(drawer, winnr) abort
let bufname = bufname(winbufnr(a:winnr))
let fri = fern#fri#parse(bufname)
return fri.scheme ==# 'fern'
\ && (!a:drawer || fri.authority =~# '\<drawer\>')
endfunction
10 changes: 0 additions & 10 deletions autoload/fern/internal/command/fern.vim
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
let s:Promise = vital#fern#import('Async.Promise')
let s:drawer_opener = 'topleft vsplit'
let s:options = [
\ '-drawer',
\ '-width=',
\ '-keep',
\ '-stay',
\ '-wait',
\ '-reveal=',
\ '-toggle',
\ '-opener=',
\]

function! fern#internal#command#fern#command(mods, fargs) abort
try
Expand Down
41 changes: 9 additions & 32 deletions autoload/fern/internal/command/focus.vim
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
function! fern#internal#command#focus#command(mods, fargs) abort
try
let drawer = fern#internal#args#pop(a:fargs, 'drawer', v:false)

if len(a:fargs) isnot# 0
\ || type(drawer) isnot# v:t_bool
throw 'Usage: FernFocus [-drawer]'
endif

" Does all options are handled?
call fern#internal#args#throw_if_dirty(a:fargs)

let found = fern#internal#window#find(
\ funcref('s:predicator', [drawer]),
\ winnr() + 1,
\)
if found
call win_gotoid(win_getid(found))
endif
catch
echohl ErrorMsg
echo v:exception
echohl None
call fern#logger#debug(v:exception)
call fern#logger#debug(v:throwpoint)
endtry
call fern#util#deprecated(
\ '":FernFocus"',
\ '":FernDo :"'
\)
if fern#internal#args#pop(a:fargs, 'drawer', v:false)
FernDo : -drawer
else
FernDo :
endif
endfunction

function! fern#internal#command#focus#complete(arglead, cmdline, cursorpos) abort
return fern#internal#complete#options(a:arglead, a:cmdline, a:cursorpos)
endfunction

function! s:predicator(drawer, winnr) abort
let bufname = bufname(winbufnr(a:winnr))
let fri = fern#fri#parse(bufname)
return fri.scheme ==# 'fern'
\ && (!a:drawer || fri.authority =~# '\<drawer\>')
endfunction
10 changes: 10 additions & 0 deletions doc/fern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,18 @@ COMMAND *fern-command*
See |:Fern| for other arguments and options. Note that -opener options
is ignored for project drawer style.

*:FernDo*
:FernDo {expr...} [-drawer] [-stay]
Focus a next fern viewer and execute {expr...}. It does nothing if no
next fern viewer is found.
If "-drawer" option is specified, it focus and execute only a project
drawer style fern.
If "-stay" option is specified, it stay focus after execution.
Note that the command can be followed by a '|' and another command.

*:FernFocus*
:FernFocus [-drawer]
DEPRECATED: Use |:FernDo| with ":" like ":FernDo :" instead.
Focus a next fern viewer. If "-drawer" option is specified, it focus
only a project drawer style fern.
Note that the command can be followed by a '|' and another command.
Expand Down
5 changes: 5 additions & 0 deletions plugin/fern.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ command! -bar -nargs=*
\ FernFocus
\ call fern#internal#command#focus#command(<q-mods>, [<f-args>])

command! -bar -nargs=*
\ -complete=customlist,fern#internal#command#do#complete
\ FernDo
\ call fern#internal#command#do#command(<q-mods>, [<f-args>])

function! s:BufReadCmd() abort
if exists('b:fern') && !get(g:, 'fern_debug')
return
Expand Down

0 comments on commit 3f5d5c1

Please sign in to comment.