Skip to content

Commit 1b234d8

Browse files
authored
Merge pull request #352 from lambdalisue/input-without-guard
Add `=` action variants to several actions for providing default value
2 parents 40f0987 + 0c3b831 commit 1b234d8

File tree

7 files changed

+135
-19
lines changed

7 files changed

+135
-19
lines changed

autoload/fern/mapping.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ function! fern#mapping#call(fn, ...) abort
1313
endtry
1414
endfunction
1515

16+
function! fern#mapping#call_without_guard(fn, ...) abort
17+
try
18+
call s:Promise.resolve(call('fern#helper#call', [a:fn] + a:000))
19+
\.catch({ e -> fern#logger#error(e) })
20+
catch
21+
call fern#logger#error(v:exception)
22+
endtry
23+
endfunction
24+
1625
function! fern#mapping#init(scheme) abort
1726
let disable_default_mappings = g:fern#disable_default_mappings
1827
for name in g:fern#mapping#mappings

autoload/fern/mapping/filter.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ function! fern#mapping#filter#init(disable_default_mappings) abort
22
nnoremap <buffer><silent> <Plug>(fern-action-hidden:set) :<C-u>call <SID>call('hidden_set')<CR>
33
nnoremap <buffer><silent> <Plug>(fern-action-hidden:unset) :<C-u>call <SID>call('hidden_unset')<CR>
44
nnoremap <buffer><silent> <Plug>(fern-action-hidden:toggle) :<C-u>call <SID>call('hidden_toggle')<CR>
5-
nnoremap <buffer><silent> <Plug>(fern-action-include) :<C-u>call <SID>call('include')<CR>
6-
nnoremap <buffer><silent> <Plug>(fern-action-exclude) :<C-u>call <SID>call('exclude')<CR>
5+
nnoremap <buffer><silent> <Plug>(fern-action-include) :<C-u>call <SID>call('include')<CR>
6+
nnoremap <buffer><silent> <Plug>(fern-action-exclude) :<C-u>call <SID>call('exclude')<CR>
7+
nnoremap <buffer><silent> <Plug>(fern-action-include=) :<C-u>call <SID>call_without_guard('include')<CR>
8+
nnoremap <buffer><silent> <Plug>(fern-action-exclude=) :<C-u>call <SID>call_without_guard('exclude')<CR>
79
810
" Alias
911
nmap <buffer> <Plug>(fern-action-hidden) <Plug>(fern-action-hidden:toggle)
@@ -30,6 +32,13 @@ function! s:call(name, ...) abort
3032
\)
3133
endfunction
3234

35+
function! s:call_without_guard(name, ...) abort
36+
return call(
37+
\ 'fern#mapping#call_without_guard',
38+
\ [funcref(printf('s:map_%s', a:name))] + a:000,
39+
\)
40+
endfunction
41+
3342
function! s:map_hidden_set(helper) abort
3443
return a:helper.async.set_hidden(1)
3544
\.then({ -> a:helper.async.redraw() })

autoload/fern/mapping/node.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function! fern#mapping#node#init(disable_default_mappings) abort
99
nnoremap <buffer><silent> <Plug>(fern-action-expand:in) :<C-u>call <SID>call('expand_in')<CR>
1010
nnoremap <buffer><silent> <Plug>(fern-action-collapse) :<C-u>call <SID>call('collapse')<CR>
1111
nnoremap <buffer><silent> <Plug>(fern-action-reveal) :<C-u>call <SID>call('reveal')<CR>
12+
nnoremap <buffer><silent> <Plug>(fern-action-reveal=) :<C-u>call <SID>call_without_guard('reveal')<CR>
1213
nnoremap <buffer><silent> <Plug>(fern-action-focus:parent) :<C-u>call <SID>call('focus_parent')<CR>
1314
1415
nnoremap <buffer><silent> <Plug>(fern-action-enter) :<C-u>call <SID>call('enter')<CR>
@@ -36,6 +37,13 @@ function! s:call(name, ...) abort
3637
\)
3738
endfunction
3839

40+
function! s:call_without_guard(name, ...) abort
41+
return call(
42+
\ 'fern#mapping#call_without_guard',
43+
\ [funcref(printf('s:map_%s', a:name))] + a:000,
44+
\)
45+
endfunction
46+
3947
function! s:map_debug(helper) abort
4048
let node = a:helper.sync.get_cursor_node()
4149
redraw | echo fern#internal#node#debug(node)

autoload/fern/scheme/file/mapping.vim

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ let s:Promise = vital#fern#import('Async.Promise')
22
let s:Prompt = vital#fern#import('Prompt')
33

44
function! fern#scheme#file#mapping#init(disable_default_mappings) abort
5-
nnoremap <buffer><silent> <Plug>(fern-action-new-path) :<C-u>call <SID>call('new_path')<CR>
6-
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
7-
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
8-
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
9-
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
10-
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
11-
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
5+
nnoremap <buffer><silent> <Plug>(fern-action-new-path) :<C-u>call <SID>call('new_path')<CR>
6+
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
7+
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
8+
nnoremap <buffer><silent> <Plug>(fern-action-new-path=) :<C-u>call <SID>call_without_guard('new_path')<CR>
9+
nnoremap <buffer><silent> <Plug>(fern-action-new-file=) :<C-u>call <SID>call_without_guard('new_file')<CR>
10+
nnoremap <buffer><silent> <Plug>(fern-action-new-dir=) :<C-u>call <SID>call_without_guard('new_dir')<CR>
11+
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
12+
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
13+
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
14+
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
1215
1316
if !a:disable_default_mappings
1417
nmap <buffer><nowait> N <Plug>(fern-action-new-file)
@@ -26,6 +29,13 @@ function! s:call(name, ...) abort
2629
\)
2730
endfunction
2831

32+
function! s:call_without_guard(name, ...) abort
33+
return call(
34+
\ 'fern#mapping#call_without_guard',
35+
\ [funcref(printf('s:map_%s', a:name))] + a:000,
36+
\)
37+
endfunction
38+
2939
function! s:map_cd(helper, command) abort
3040
let path = a:helper.sync.get_cursor_node()._path
3141
if a:command ==# 'tcd' && !exists(':tcd')

autoload/fern/scheme/file/mapping/ex.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
let s:Promise = vital#fern#import('Async.Promise')
22

33
function! fern#scheme#file#mapping#ex#init(disable_default_mappings) abort
4-
nnoremap <buffer><silent> <Plug>(fern-action-ex) :<C-u>call <SID>call('ex')<CR>
4+
nnoremap <buffer><silent> <Plug>(fern-action-ex) :<C-u>call <SID>call('ex')<CR>
5+
nnoremap <buffer><silent> <Plug>(fern-action-ex=) :<C-u>call <SID>call_without_guard('ex')<CR>
56
endfunction
67

78
function! s:call(name, ...) abort
@@ -11,6 +12,13 @@ function! s:call(name, ...) abort
1112
\)
1213
endfunction
1314

15+
function! s:call_without_guard(name, ...) abort
16+
return call(
17+
\ 'fern#mapping#call_without_guard',
18+
\ [funcref(printf('s:map_%s', a:name))] + a:000,
19+
\)
20+
endfunction
21+
1422
function! s:map_ex(helper) abort
1523
let nodes = a:helper.sync.get_selected_nodes()
1624
let nodes = filter(copy(nodes), { -> v:val._path isnot# v:null })

autoload/fern/scheme/file/mapping/grep.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ let s:Promise = vital#fern#import('Async.Promise')
33
let s:Process = vital#fern#import('Async.Promise.Process')
44

55
function! fern#scheme#file#mapping#grep#init(disable_default_mappings) abort
6-
nnoremap <buffer><silent> <Plug>(fern-action-grep) :<C-u>call <SID>call('grep')<CR>
6+
nnoremap <buffer><silent> <Plug>(fern-action-grep) :<C-u>call <SID>call('grep')<CR>
7+
nnoremap <buffer><silent> <Plug>(fern-action-grep=) :<C-u>call <SID>call_without_guard('grep')<CR>
78
endfunction
89

910
function! s:call(name, ...) abort
@@ -13,6 +14,13 @@ function! s:call(name, ...) abort
1314
\)
1415
endfunction
1516

17+
function! s:call_without_guard(name, ...) abort
18+
return call(
19+
\ 'fern#mapping#call_without_guard',
20+
\ [funcref(printf('s:map_%s', a:name))] + a:000,
21+
\)
22+
endfunction
23+
1624
function! s:map_grep(helper) abort
1725
let pattern = input('Grep: ', '')
1826
if empty(pattern)

doc/fern.txt

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,29 @@ GLOBAL *fern-mapping-global*
823823
DEPRECATED: Use |<Plug>(fern-action-hidden:toggle)| instead.
824824

825825
*<Plug>(fern-action-include)*
826+
*<Plug>(fern-action-include=)*
826827
Open a prompt to enter include filter. Users can type a |pattern| to
827828
filter nodes recursively.
828-
829+
You can use a "=" variant to apply values to the prompt and/or submit
830+
a value like:
831+
>
832+
" Automatically apply "foo" to the prompt and submit.
833+
nmap <buffer>
834+
\ <Plug>(my-include)
835+
\ <Plug>(fern-action-include=)foo<CR>
836+
<
829837
*<Plug>(fern-action-exclude)*
838+
*<Plug>(fern-action-exclude=)*
830839
Open a prompt to enter exclude filter. Users can type a |pattern| to
831840
filter nodes recursively.
832-
841+
You can use a "=" variant to apply values to the prompt and/or submit
842+
a value like:
843+
>
844+
" Automatically apply "foo" to the prompt and submit.
845+
nmap <buffer>
846+
\ <Plug>(my-exclude)
847+
\ <Plug>(fern-action-exclude=)foo<CR>
848+
<
833849
*<Plug>(fern-action-mark:clear)*
834850
Clear existing marks.
835851

@@ -895,8 +911,16 @@ GLOBAL *fern-mapping-global*
895911
Collapse on a cursor node.
896912

897913
*<Plug>(fern-action-reveal)*
914+
*<Plug>(fern-action-reveal=)*
898915
Open a prompt to reveal a node in a tree.
899-
916+
You can use a "=" variant to apply values to the prompt and/or submit
917+
a value like:
918+
>
919+
" Automatically apply "foo" to the prompt and submit.
920+
nmap <buffer>
921+
\ <Plug>(my-reveal)
922+
\ <Plug>(fern-action-reveal=)foo<CR>
923+
<
900924
*<Plug>(fern-action-focus:parent)*
901925
Focus the parent of the cursor node.
902926

@@ -1103,26 +1127,58 @@ FILE *fern-mapping-file*
11031127
The following mappings/actions are only available on file:// scheme.
11041128

11051129
*<Plug>(fern-action-ex)*
1130+
*<Plug>(fern-action-ex=)*
11061131
Open a prompt to execute an Ex command with a path of cursor node or
11071132
paths of marked nodes.
1108-
1133+
You can use a "=" variant to apply values to the prompt and/or submit
1134+
a value like:
1135+
>
1136+
" Automatically apply "foo" to the prompt and submit.
1137+
nmap <buffer>
1138+
\ <Plug>(my-ex)
1139+
\ <Plug>(fern-action-ex=)foo<CR>
1140+
<
11091141
*<Plug>(fern-action-new-path)*
1142+
*<Plug>(fern-action-new-path=)*
11101143
Open a prompt to ask a path and create a file/directory of the input
11111144
path from the path of a cursor node.
11121145
Any intermediate directories of the destination will be created.
11131146
If the path ends with "/", it creates a directory. Otherwise it
11141147
creates a file.
1115-
1148+
You can use a "=" variant to apply values to the prompt and/or submit
1149+
a value like:
1150+
>
1151+
" Automatically apply "foo" to the prompt and submit.
1152+
nmap <buffer>
1153+
\ <Plug>(my-new-path)
1154+
\ <Plug>(fern-action-new-path=)foo<CR>
1155+
<
11161156
*<Plug>(fern-action-new-file)*
1157+
*<Plug>(fern-action-new-file=)*
11171158
Open a prompt to ask a path and create a file of the input path from
11181159
the path of a cursor node.
11191160
Any intermediate directories of the destination will be created.
1120-
1161+
You can use a "=" variant to apply values to the prompt and/or submit
1162+
a value like:
1163+
>
1164+
" Automatically apply "foo" to the prompt and submit.
1165+
nmap <buffer>
1166+
\ <Plug>(my-new-file)
1167+
\ <Plug>(fern-action-new-file=)foo<CR>
1168+
<
11211169
*<Plug>(fern-action-new-dir)*
1170+
*<Plug>(fern-action-new-dir=)*
11221171
Open a prompt to ask a path and create a directory of the input path
11231172
from the path of a cursor node.
11241173
Any intermediate directories of the destination will be created.
1125-
1174+
You can use a "=" variant to apply values to the prompt and/or submit
1175+
a value like:
1176+
>
1177+
" Automatically apply "foo" to the prompt and submit.
1178+
nmap <buffer>
1179+
\ <Plug>(my-new-dir)
1180+
\ <Plug>(fern-action-new-dir=)foo<CR>
1181+
<
11261182
*<Plug>(fern-action-copy)*
11271183
Open a prompt to ask a path and copy a file/directory of the cursor
11281184
node or marked node path(s) to the input path(s).
@@ -1195,9 +1251,17 @@ The following mappings/actions are only available on file:// scheme.
11951251
Note that this action has NO-relation with the system clipboard.
11961252

11971253
*<Plug>(fern-action-grep)*
1254+
*<Plug>(fern-action-grep=)*
11981255
Open a prompt to ask a grep pattern and execute grep command under the
11991256
cursor node. It respects the value of 'grepprg' and 'grepformat'.
1200-
1257+
You can use a "=" variant to apply values to the prompt and/or submit
1258+
a value like:
1259+
>
1260+
" Automatically apply "foo" to the prompt and submit.
1261+
nmap <buffer>
1262+
\ <Plug>(my-grep)
1263+
\ <Plug>(fern-action-grep=)foo<CR>
1264+
<
12011265
*<Plug>(fern-action-rename:select)*
12021266
*<Plug>(fern-action-rename:split)*
12031267
*<Plug>(fern-action-rename:vsplit)*

0 commit comments

Comments
 (0)