Skip to content

Commit 40b8fc9

Browse files
authored
Merge pull request #132 from lambdalisue/scheme-mapping
Support 3rd party scheme mappings and document mappings on developer docs
2 parents 318a195 + 3bcfc6e commit 40b8fc9

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

autoload/fern/internal/scheme.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ function! fern#internal#scheme#provider_new(scheme) abort
1111
endfunction
1212

1313
function! fern#internal#scheme#mapping_init(scheme, disable_default_mappings) abort
14-
return call('s:call', [a:scheme, 'mapping#init', a:disable_default_mappings])
14+
let mappings = get(g:, printf('fern#scheme#%s#mapping#mappings', a:scheme), [])
15+
for name in mappings
16+
call s:call(a:scheme, printf('mapping#%s#init', name), a:disable_default_mappings)
17+
endfor
18+
return s:call(a:scheme, 'mapping#init', a:disable_default_mappings)
1519
endfunction
1620

1721
function! fern#internal#scheme#complete_url(scheme, arglead, cmdline, cursorpos) abort
18-
return call('s:call', [a:scheme, 'complete#url', a:arglead, a:cmdline, a:cursorpos])
22+
return s:call(a:scheme, 'complete#url', a:arglead, a:cmdline, a:cursorpos)
1923
endfunction
2024

2125
function! fern#internal#scheme#complete_reveal(scheme, arglead, cmdline, cursorpos) abort
22-
return call('s:call', [a:scheme, 'complete#reveal', a:arglead, a:cmdline, a:cursorpos])
26+
return s:call(a:scheme, 'complete#reveal', a:arglead, a:cmdline, a:cursorpos)
2327
endfunction

autoload/fern/scheme/dict/mapping.vim

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

44
function! fern#scheme#dict#mapping#init(disable_default_mappings) abort
5-
call fern#scheme#dict#mapping#clipboard#init(a:disable_default_mappings)
6-
call fern#scheme#dict#mapping#rename#init(a:disable_default_mappings)
7-
85
nnoremap <buffer><silent> <Plug>(fern-action-new-leaf) :<C-u>call <SID>call('new_leaf')<CR>
96
nnoremap <buffer><silent> <Plug>(fern-action-new-branch) :<C-u>call <SID>call('new_branch')<CR>
107
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
@@ -204,3 +201,8 @@ function! s:map_edit_leaf(helper) abort
204201
\.then({ -> a:helper.async.reload_node(root.__key) })
205202
\.then({ -> a:helper.async.redraw() })
206203
endfunction
204+
205+
let g:fern#scheme#dict#mapping#mappings = get(g:, 'fern#scheme#dict#mapping#mappings', [
206+
\ 'clipboard',
207+
\ 'rename',
208+
\])

autoload/fern/scheme/file/mapping.vim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ 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-
call fern#scheme#file#mapping#cd#init(a:disable_default_mappings)
6-
call fern#scheme#file#mapping#system#init(a:disable_default_mappings)
7-
call fern#scheme#file#mapping#clipboard#init(a:disable_default_mappings)
8-
call fern#scheme#file#mapping#rename#init(a:disable_default_mappings)
9-
call fern#scheme#file#mapping#terminal#init(a:disable_default_mappings)
10-
call fern#scheme#file#mapping#grep#init(a:disable_default_mappings)
11-
125
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
136
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
147
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
@@ -198,3 +191,12 @@ function! s:map_remove(helper) abort
198191
\.then({ -> a:helper.async.redraw() })
199192
\.then({ -> a:helper.sync.echo(printf('%d items are removed', len(ps))) })
200193
endfunction
194+
195+
let g:fern#scheme#file#mapping#mappings = get(g:, 'fern#scheme#file#mapping#mappings', [
196+
\ 'cd',
197+
\ 'clipboard',
198+
\ 'grep',
199+
\ 'rename',
200+
\ 'system',
201+
\ 'terminal',
202+
\])

doc/fern-develop.txt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,21 @@ See https://github.com/lambdalisue/fern-comparator-lexical.vim as example.
185185
=============================================================================
186186
MAPPING *fern-develop-mapping*
187187

188-
TBW
188+
Fern provides global mappings under "autoload/fern/mapping" directory.
189+
Mapping MUST provide an init function as "fern#mapping#{name}#init()" with
190+
a boolean argument to disable default mappings.
191+
192+
Mappings under that directory are registered automatically when a filename has
193+
listed in |g:fern#mapping#mappings| variable.
194+
195+
So 3rd party plugin MUST register mappings by add followings to plugin.vim
196+
like:
197+
>
198+
call add(g:fern#mapping#mappings, ['your_plugin'])
199+
>
200+
*g:fern#mapping#mappings*
201+
A |List| of globally available mapping names.
202+
A target mapping MUST exist under "fern#mapping#" namespace.
189203

190204

191205
=============================================================================
@@ -292,7 +306,23 @@ the following methods.
292306
-----------------------------------------------------------------------------
293307
MAPPING *fern-develop-scheme-mapping*
294308

295-
TBW
309+
Fern provides scheme mappings under "autoload/fern/scheme/{scheme}/mapping"
310+
directory. Mapping MUST provide an init function as
311+
"fern#scheme#{scheme}#mapping#{name}#init()" with a boolean argument to disable
312+
default mappings.
313+
314+
Mappings under that directory are registered automatically when a filename has
315+
listed in |g:fern#scheme#{scheme}#mapping#mappings| variable.
316+
317+
So 3rd party plugin MUST register mappings by add followings to plugin.vim
318+
like:
319+
>
320+
call add(g:fern#scheme#file#mapping#mappings, ['your_plugin'])
321+
>
322+
*g:fern#scheme#{scheme}#mapping#mappings*
323+
A |List| of scheme available mapping names for {scheme}.
324+
A target mapping MUST exist under "fern#scheme#{scheme}#mapping#"
325+
namespace.
296326

297327

298328
=============================================================================

0 commit comments

Comments
 (0)