Skip to content

Commit 3f5d5c1

Browse files
authored
Merge pull request #113 from lambdalisue/ferndo
Add :FernDo command and deprecate :FernFocus command
2 parents a4465a3 + 578b127 commit 3f5d5c1

File tree

5 files changed

+71
-42
lines changed

5 files changed

+71
-42
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function! fern#internal#command#do#command(mods, fargs) abort
2+
let winid_saved = win_getid()
3+
try
4+
let stay = fern#internal#args#pop(a:fargs, 'stay', v:false)
5+
let drawer = fern#internal#args#pop(a:fargs, 'drawer', v:false)
6+
7+
if len(a:fargs) is# 0
8+
\ || type(stay) isnot# v:t_bool
9+
\ || type(drawer) isnot# v:t_bool
10+
throw 'Usage: FernDo {expr...} [-drawer] [-stay]'
11+
endif
12+
13+
" Does all options are handled?
14+
call fern#internal#args#throw_if_dirty(a:fargs)
15+
16+
let found = fern#internal#window#find(
17+
\ funcref('s:predicator', [drawer]),
18+
\ winnr() + 1,
19+
\)
20+
if !found
21+
return
22+
endif
23+
call win_gotoid(win_getid(found))
24+
execute join([a:mods] + a:fargs, ' ')
25+
catch
26+
echohl ErrorMsg
27+
echo v:exception
28+
echohl None
29+
call fern#logger#debug(v:exception)
30+
call fern#logger#debug(v:throwpoint)
31+
finally
32+
if stay
33+
call win_gotoid(winid_saved)
34+
endif
35+
endtry
36+
endfunction
37+
38+
function! fern#internal#command#do#complete(arglead, cmdline, cursorpos) abort
39+
return fern#internal#complete#options(a:arglead, a:cmdline, a:cursorpos)
40+
endfunction
41+
42+
function! s:predicator(drawer, winnr) abort
43+
let bufname = bufname(winbufnr(a:winnr))
44+
let fri = fern#fri#parse(bufname)
45+
return fri.scheme ==# 'fern'
46+
\ && (!a:drawer || fri.authority =~# '\<drawer\>')
47+
endfunction

autoload/fern/internal/command/fern.vim

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
let s:Promise = vital#fern#import('Async.Promise')
22
let s:drawer_opener = 'topleft vsplit'
3-
let s:options = [
4-
\ '-drawer',
5-
\ '-width=',
6-
\ '-keep',
7-
\ '-stay',
8-
\ '-wait',
9-
\ '-reveal=',
10-
\ '-toggle',
11-
\ '-opener=',
12-
\]
133

144
function! fern#internal#command#fern#command(mods, fargs) abort
155
try
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
11
function! fern#internal#command#focus#command(mods, fargs) abort
2-
try
3-
let drawer = fern#internal#args#pop(a:fargs, 'drawer', v:false)
4-
5-
if len(a:fargs) isnot# 0
6-
\ || type(drawer) isnot# v:t_bool
7-
throw 'Usage: FernFocus [-drawer]'
8-
endif
9-
10-
" Does all options are handled?
11-
call fern#internal#args#throw_if_dirty(a:fargs)
12-
13-
let found = fern#internal#window#find(
14-
\ funcref('s:predicator', [drawer]),
15-
\ winnr() + 1,
16-
\)
17-
if found
18-
call win_gotoid(win_getid(found))
19-
endif
20-
catch
21-
echohl ErrorMsg
22-
echo v:exception
23-
echohl None
24-
call fern#logger#debug(v:exception)
25-
call fern#logger#debug(v:throwpoint)
26-
endtry
2+
call fern#util#deprecated(
3+
\ '":FernFocus"',
4+
\ '":FernDo :"'
5+
\)
6+
if fern#internal#args#pop(a:fargs, 'drawer', v:false)
7+
FernDo : -drawer
8+
else
9+
FernDo :
10+
endif
2711
endfunction
2812

2913
function! fern#internal#command#focus#complete(arglead, cmdline, cursorpos) abort
3014
return fern#internal#complete#options(a:arglead, a:cmdline, a:cursorpos)
3115
endfunction
32-
33-
function! s:predicator(drawer, winnr) abort
34-
let bufname = bufname(winbufnr(a:winnr))
35-
let fri = fern#fri#parse(bufname)
36-
return fri.scheme ==# 'fern'
37-
\ && (!a:drawer || fri.authority =~# '\<drawer\>')
38-
endfunction

doc/fern.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,18 @@ COMMAND *fern-command*
382382
See |:Fern| for other arguments and options. Note that -opener options
383383
is ignored for project drawer style.
384384

385+
*:FernDo*
386+
:FernDo {expr...} [-drawer] [-stay]
387+
Focus a next fern viewer and execute {expr...}. It does nothing if no
388+
next fern viewer is found.
389+
If "-drawer" option is specified, it focus and execute only a project
390+
drawer style fern.
391+
If "-stay" option is specified, it stay focus after execution.
392+
Note that the command can be followed by a '|' and another command.
393+
385394
*:FernFocus*
386395
:FernFocus [-drawer]
396+
DEPRECATED: Use |:FernDo| with ":" like ":FernDo :" instead.
387397
Focus a next fern viewer. If "-drawer" option is specified, it focus
388398
only a project drawer style fern.
389399
Note that the command can be followed by a '|' and another command.

plugin/fern.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ command! -bar -nargs=*
1313
\ FernFocus
1414
\ call fern#internal#command#focus#command(<q-mods>, [<f-args>])
1515

16+
command! -bar -nargs=*
17+
\ -complete=customlist,fern#internal#command#do#complete
18+
\ FernDo
19+
\ call fern#internal#command#do#command(<q-mods>, [<f-args>])
20+
1621
function! s:BufReadCmd() abort
1722
if exists('b:fern') && !get(g:, 'fern_debug')
1823
return

0 commit comments

Comments
 (0)