Skip to content

Commit a9e6558

Browse files
committed
feat: make mappings customizable
1 parent adcaa2e commit a9e6558

File tree

1 file changed

+83
-73
lines changed

1 file changed

+83
-73
lines changed

plugin/fall/mapping.vim

Lines changed: 83 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,99 +3,109 @@ if exists('g:loaded_fall_mapping')
33
endif
44
let g:loaded_fall_mapping = 1
55

6+
function! s:dispatch(event) abort
7+
call fall#internal#dispatch(a:event)
8+
endfunction
9+
610
" List
7-
cnoremap <silent> <Plug>(fall-list-first) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor-at', cursor: 0})<CR>
8-
cnoremap <silent> <Plug>(fall-list-last) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor-at', cursor: '$'})<CR>
9-
cnoremap <silent> <Plug>(fall-list-prev) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor', amount: -1})<CR>
10-
cnoremap <silent> <Plug>(fall-list-next) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor', amount: 1})<CR>
11-
cnoremap <silent> <Plug>(fall-list-prev:scroll) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor', amount: -1, scroll: v:true})<CR>
12-
cnoremap <silent> <Plug>(fall-list-next:scroll) <Cmd>call fall#internal#dispatch(#{type: 'move-cursor', amount: 1, scroll: v:true})<CR>
13-
cnoremap <silent> <Plug>(fall-list-left) <Cmd>call fall#internal#dispatch(#{type: 'list-component-execute', command: 'silent! normal! zh'})<CR>
14-
cnoremap <silent> <Plug>(fall-list-right) <Cmd>call fall#internal#dispatch(#{type: 'list-component-execute', command: 'silent! normal! zl'})<CR>
15-
cnoremap <silent> <Plug>(fall-list-left:scroll) <Cmd>call fall#internal#dispatch(#{type: 'list-component-execute', command: 'silent! normal! zH'})<CR>
16-
cnoremap <silent> <Plug>(fall-list-right:scroll) <Cmd>call fall#internal#dispatch(#{type: 'list-component-execute', command: 'silent! normal! zL'})<CR>
11+
cnoremap <silent> <Plug>(fall-list-first) <Cmd>call <SID>dispatch(#{type: 'move-cursor-at', cursor: 0})<CR>
12+
cnoremap <silent> <Plug>(fall-list-last) <Cmd>call <SID>dispatch(#{type: 'move-cursor-at', cursor: '$'})<CR>
13+
cnoremap <silent> <Plug>(fall-list-prev) <Cmd>call <SID>dispatch(#{type: 'move-cursor', amount: -1})<CR>
14+
cnoremap <silent> <Plug>(fall-list-next) <Cmd>call <SID>dispatch(#{type: 'move-cursor', amount: 1})<CR>
15+
cnoremap <silent> <Plug>(fall-list-prev:scroll) <Cmd>call <SID>dispatch(#{type: 'move-cursor', amount: -1, scroll: v:true})<CR>
16+
cnoremap <silent> <Plug>(fall-list-next:scroll) <Cmd>call <SID>dispatch(#{type: 'move-cursor', amount: 1, scroll: v:true})<CR>
17+
cnoremap <silent> <Plug>(fall-list-left) <Cmd>call <SID>dispatch(#{type: 'list-component-execute', command: 'silent! normal! zh'})<CR>
18+
cnoremap <silent> <Plug>(fall-list-right) <Cmd>call <SID>dispatch(#{type: 'list-component-execute', command: 'silent! normal! zl'})<CR>
19+
cnoremap <silent> <Plug>(fall-list-left:scroll) <Cmd>call <SID>dispatch(#{type: 'list-component-execute', command: 'silent! normal! zH'})<CR>
20+
cnoremap <silent> <Plug>(fall-list-right:scroll) <Cmd>call <SID>dispatch(#{type: 'list-component-execute', command: 'silent! normal! zL'})<CR>
1721
1822
" Select
19-
cnoremap <silent> <Plug>(fall-select) <Cmd>call fall#internal#dispatch(#{type: 'select-item'})<CR>
20-
cnoremap <silent> <Plug>(fall-select-all) <Cmd>call fall#internal#dispatch(#{type: 'select-all-items'})<CR>
23+
cnoremap <silent> <Plug>(fall-select) <Cmd>call <SID>dispatch(#{type: 'select-item'})<CR>
24+
cnoremap <silent> <Plug>(fall-select-all) <Cmd>call <SID>dispatch(#{type: 'select-all-items'})<CR>
2125
2226
" Switch
23-
cnoremap <silent> <Plug>(fall-switch-matcher-first) <Cmd>call fall#internal#dispatch(#{type: 'switch-matcher-at', index: 0})<CR>
24-
cnoremap <silent> <Plug>(fall-switch-matcher-last) <Cmd>call fall#internal#dispatch(#{type: 'switch-matcher-at', index: '$'})<CR>
25-
cnoremap <silent> <Plug>(fall-switch-matcher-prev) <Cmd>call fall#internal#dispatch(#{type: 'switch-matcher', amount: -1, cycle: v:true})<CR>
26-
cnoremap <silent> <Plug>(fall-switch-matcher-next) <Cmd>call fall#internal#dispatch(#{type: 'switch-matcher', amount: 1, cycle: v:true})<CR>
27-
cnoremap <silent> <Plug>(fall-switch-sorter-first) <Cmd>call fall#internal#dispatch(#{type: 'switch-sorter-at', index: 0})<CR>
28-
cnoremap <silent> <Plug>(fall-switch-sorter-last) <Cmd>call fall#internal#dispatch(#{type: 'switch-sorter-at', index: '$'})<CR>
29-
cnoremap <silent> <Plug>(fall-switch-sorter-prev) <Cmd>call fall#internal#dispatch(#{type: 'switch-sorter', amount: -1, cycle: v:true})<CR>
30-
cnoremap <silent> <Plug>(fall-switch-sorter-next) <Cmd>call fall#internal#dispatch(#{type: 'switch-sorter', amount: 1, cycle: v:true})<CR>
31-
cnoremap <silent> <Plug>(fall-switch-renderer-first) <Cmd>call fall#internal#dispatch(#{type: 'switch-renderer-at', index: 0})<CR>
32-
cnoremap <silent> <Plug>(fall-switch-renderer-last) <Cmd>call fall#internal#dispatch(#{type: 'switch-renderer-at', index: '$'})<CR>
33-
cnoremap <silent> <Plug>(fall-switch-renderer-prev) <Cmd>call fall#internal#dispatch(#{type: 'switch-renderer', amount: -1, cycle: v:true})<CR>
34-
cnoremap <silent> <Plug>(fall-switch-renderer-next) <Cmd>call fall#internal#dispatch(#{type: 'switch-renderer', amount: 1, cycle: v:true})<CR>
35-
cnoremap <silent> <Plug>(fall-switch-previewer-first) <Cmd>call fall#internal#dispatch(#{type: 'switch-previewer-at', index: 0})<CR>
36-
cnoremap <silent> <Plug>(fall-switch-previewer-last) <Cmd>call fall#internal#dispatch(#{type: 'switch-previewer-at', index: '$'})<CR>
37-
cnoremap <silent> <Plug>(fall-switch-previewer-prev) <Cmd>call fall#internal#dispatch(#{type: 'switch-previewer', amount: -1, cycle: v:true})<CR>
38-
cnoremap <silent> <Plug>(fall-switch-previewer-next) <Cmd>call fall#internal#dispatch(#{type: 'switch-previewer', amount: 1, cycle: v:true})<CR>
27+
cnoremap <silent> <Plug>(fall-switch-matcher-first) <Cmd>call <SID>dispatch(#{type: 'switch-matcher-at', index: 0})<CR>
28+
cnoremap <silent> <Plug>(fall-switch-matcher-last) <Cmd>call <SID>dispatch(#{type: 'switch-matcher-at', index: '$'})<CR>
29+
cnoremap <silent> <Plug>(fall-switch-matcher-prev) <Cmd>call <SID>dispatch(#{type: 'switch-matcher', amount: -1, cycle: v:true})<CR>
30+
cnoremap <silent> <Plug>(fall-switch-matcher-next) <Cmd>call <SID>dispatch(#{type: 'switch-matcher', amount: 1, cycle: v:true})<CR>
31+
cnoremap <silent> <Plug>(fall-switch-sorter-first) <Cmd>call <SID>dispatch(#{type: 'switch-sorter-at', index: 0})<CR>
32+
cnoremap <silent> <Plug>(fall-switch-sorter-last) <Cmd>call <SID>dispatch(#{type: 'switch-sorter-at', index: '$'})<CR>
33+
cnoremap <silent> <Plug>(fall-switch-sorter-prev) <Cmd>call <SID>dispatch(#{type: 'switch-sorter', amount: -1, cycle: v:true})<CR>
34+
cnoremap <silent> <Plug>(fall-switch-sorter-next) <Cmd>call <SID>dispatch(#{type: 'switch-sorter', amount: 1, cycle: v:true})<CR>
35+
cnoremap <silent> <Plug>(fall-switch-renderer-first) <Cmd>call <SID>dispatch(#{type: 'switch-renderer-at', index: 0})<CR>
36+
cnoremap <silent> <Plug>(fall-switch-renderer-last) <Cmd>call <SID>dispatch(#{type: 'switch-renderer-at', index: '$'})<CR>
37+
cnoremap <silent> <Plug>(fall-switch-renderer-prev) <Cmd>call <SID>dispatch(#{type: 'switch-renderer', amount: -1, cycle: v:true})<CR>
38+
cnoremap <silent> <Plug>(fall-switch-renderer-next) <Cmd>call <SID>dispatch(#{type: 'switch-renderer', amount: 1, cycle: v:true})<CR>
39+
cnoremap <silent> <Plug>(fall-switch-previewer-first) <Cmd>call <SID>dispatch(#{type: 'switch-previewer-at', index: 0})<CR>
40+
cnoremap <silent> <Plug>(fall-switch-previewer-last) <Cmd>call <SID>dispatch(#{type: 'switch-previewer-at', index: '$'})<CR>
41+
cnoremap <silent> <Plug>(fall-switch-previewer-prev) <Cmd>call <SID>dispatch(#{type: 'switch-previewer', amount: -1, cycle: v:true})<CR>
42+
cnoremap <silent> <Plug>(fall-switch-previewer-next) <Cmd>call <SID>dispatch(#{type: 'switch-previewer', amount: 1, cycle: v:true})<CR>
3943
4044
" Preview
41-
cnoremap <silent> <Plug>(fall-preview-first) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! gg'})<CR>
42-
cnoremap <silent> <Plug>(fall-preview-last) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! G'})<CR>
43-
cnoremap <silent> <Plug>(fall-preview-prev) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! k'})<CR>
44-
cnoremap <silent> <Plug>(fall-preview-next) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! j'})<CR>
45-
cnoremap <silent> <Plug>(fall-preview-prev:scroll) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! <C-u>'})<CR>
46-
cnoremap <silent> <Plug>(fall-preview-next:scroll) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! <C-d>'})<CR>
47-
cnoremap <silent> <Plug>(fall-preview-left) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zh'})<CR>
48-
cnoremap <silent> <Plug>(fall-preview-right) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zl'})<CR>
49-
cnoremap <silent> <Plug>(fall-preview-left:scroll) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zH'})<CR>
50-
cnoremap <silent> <Plug>(fall-preview-right:scroll) <Cmd>call fall#internal#dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zL'})<CR>
45+
cnoremap <silent> <Plug>(fall-preview-first) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! gg'})<CR>
46+
cnoremap <silent> <Plug>(fall-preview-last) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! G'})<CR>
47+
cnoremap <silent> <Plug>(fall-preview-prev) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! k'})<CR>
48+
cnoremap <silent> <Plug>(fall-preview-next) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! j'})<CR>
49+
cnoremap <silent> <Plug>(fall-preview-prev:scroll) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! <C-u>'})<CR>
50+
cnoremap <silent> <Plug>(fall-preview-next:scroll) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! <C-d>'})<CR>
51+
cnoremap <silent> <Plug>(fall-preview-left) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zh'})<CR>
52+
cnoremap <silent> <Plug>(fall-preview-right) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zl'})<CR>
53+
cnoremap <silent> <Plug>(fall-preview-left:scroll) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zH'})<CR>
54+
cnoremap <silent> <Plug>(fall-preview-right:scroll) <Cmd>call <SID>dispatch(#{type: 'preview-component-execute', command: 'silent! normal! zL'})<CR>
5155
5256
" Help
53-
cnoremap <silent> <Plug>(fall-help) <Cmd>call fall#internal#dispatch(#{type: 'help-component-toggle'})<CR>
54-
cnoremap <silent> <Plug>(fall-help-prev) <Cmd>call fall#internal#dispatch(#{type: 'help-component-page', amount: -1})<CR>
55-
cnoremap <silent> <Plug>(fall-help-next) <Cmd>call fall#internal#dispatch(#{type: 'help-component-page', amount: 1})<CR>
57+
cnoremap <silent> <Plug>(fall-help) <Cmd>call <SID>dispatch(#{type: 'help-component-toggle'})<CR>
58+
cnoremap <silent> <Plug>(fall-help-prev) <Cmd>call <SID>dispatch(#{type: 'help-component-page', amount: -1})<CR>
59+
cnoremap <silent> <Plug>(fall-help-next) <Cmd>call <SID>dispatch(#{type: 'help-component-page', amount: 1})<CR>
5660
5761
" Action
5862
cnoremap <silent> <Plug>(fall-action-select) <Cmd>call fall#action('@select')<CR>
5963
6064
if !get(g:, 'fall_disable_default_mapping')
65+
function! s:define(lhs, rhs) abort
66+
if !hasmapto(a:rhs, 'c')
67+
execute 'cnoremap <silent> <nowait> ' . a:lhs . ' ' . a:rhs
68+
endif
69+
endfunction
70+
6171
function! s:map_picker() abort
6272
" List
63-
cnoremap <nowait> <C-t> <Plug>(fall-list-first)
64-
cnoremap <nowait> <C-g> <Plug>(fall-list-last)
65-
cnoremap <nowait> <C-p> <Plug>(fall-list-prev)
66-
cnoremap <nowait> <C-n> <Plug>(fall-list-next)
67-
cnoremap <nowait> <C-u> <Plug>(fall-list-prev:scroll)
68-
cnoremap <nowait> <C-d> <Plug>(fall-list-next:scroll)
69-
cnoremap <nowait> <PageUp> <Plug>(fall-list-left)
70-
cnoremap <nowait> <PageDown> <Plug>(fall-list-right)
71-
cnoremap <nowait> <S-PageUp> <Plug>(fall-list-left:scroll)
72-
cnoremap <nowait> <S-PageDown> <Plug>(fall-list-right:scroll)
73-
cnoremap <nowait> <C-,> <Plug>(fall-select)
74-
cnoremap <nowait> <C-.> <Plug>(fall-select-all)
75-
cnoremap <nowait> <C-j> <Plug>(fall-select)<Plug>(fall-list-next)
76-
cnoremap <nowait> <C-k> <Plug>(fall-list-prev)<Plug>(fall-select)
73+
call s:define('<C-t>', '<Plug>(fall-list-first)')
74+
call s:define('<C-g>', '<Plug>(fall-list-last)')
75+
call s:define('<C-p>', '<Plug>(fall-list-prev)')
76+
call s:define('<C-n>', '<Plug>(fall-list-next)')
77+
call s:define('<C-u>', '<Plug>(fall-list-prev:scroll)')
78+
call s:define('<C-d>', '<Plug>(fall-list-next:scroll)')
79+
call s:define('<PageUp>', '<Plug>(fall-list-left)')
80+
call s:define('<PageDown>', '<Plug>(fall-list-right)')
81+
call s:define('<S-PageUp>', '<Plug>(fall-list-left:scroll)')
82+
call s:define('<S-PageDown>', '<Plug>(fall-list-right:scroll)')
83+
call s:define('<C-,>', '<Plug>(fall-select)')
84+
call s:define('<C-.>', '<Plug>(fall-select-all)')
85+
call s:define('<C-j>', '<Plug>(fall-select)<Plug>(fall-list-next)')
86+
call s:define('<C-k>', '<Plug>(fall-list-prev)<Plug>(fall-select)')
7787
" Preview
78-
cnoremap <nowait> <M-Home> <Plug>(fall-preview-first)
79-
cnoremap <nowait> <M-End> <Plug>(fall-preview-last)
80-
cnoremap <nowait> <M-Up> <Plug>(fall-preview-prev)
81-
cnoremap <nowait> <M-Down> <Plug>(fall-preview-next)
82-
cnoremap <nowait> <S-Up> <Plug>(fall-preview-prev:scroll)
83-
cnoremap <nowait> <S-Down> <Plug>(fall-preview-next:scroll)
84-
cnoremap <nowait> <M-Left> <Plug>(fall-preview-left)
85-
cnoremap <nowait> <M-Right> <Plug>(fall-preview-right)
86-
cnoremap <nowait> <S-Left> <Plug>(fall-preview-left:scroll)
87-
cnoremap <nowait> <S-Right> <Plug>(fall-preview-right:scroll)
88+
call s:define('<M-Home>', '<Plug>(fall-preview-first)')
89+
call s:define('<M-End>', '<Plug>(fall-preview-last)')
90+
call s:define('<M-Up>', '<Plug>(fall-preview-prev)')
91+
call s:define('<M-Down>', '<Plug>(fall-preview-next)')
92+
call s:define('<S-Up>', '<Plug>(fall-preview-prev:scroll)')
93+
call s:define('<S-Down>', '<Plug>(fall-preview-next:scroll)')
94+
call s:define('<M-Left>', '<Plug>(fall-preview-left)')
95+
call s:define('<M-Right>', '<Plug>(fall-preview-right)')
96+
call s:define('<S-Left>', '<Plug>(fall-preview-left:scroll)')
97+
call s:define('<S-Right>', '<Plug>(fall-preview-right:scroll)')
8898
" Action
89-
cnoremap <nowait> <Tab> <Plug>(fall-action-select)
99+
call s:define('<Tab>', '<Plug>(fall-action-select)')
90100
" Help
91-
cnoremap <nowait> <F1> <Plug>(fall-help)
92-
cnoremap <nowait> <S-Home> <Plug>(fall-help-prev)
93-
cnoremap <nowait> <S-End> <Plug>(fall-help-next)
101+
call s:define('<F1>', '<Plug>(fall-help)')
102+
call s:define('<S-Home>', '<Plug>(fall-help-prev)')
103+
call s:define('<S-End>', '<Plug>(fall-help-next)')
94104
" Switch
95-
cnoremap <nowait> <F2> <Plug>(fall-switch-matcher-next)
96-
cnoremap <nowait> <F3> <Plug>(fall-switch-sorter-next)
97-
cnoremap <nowait> <F4> <Plug>(fall-switch-renderer-next)
98-
cnoremap <nowait> <F5> <Plug>(fall-switch-previewer-next)
105+
call s:define('<F2>', '<Plug>(fall-switch-matcher-next)')
106+
call s:define('<F3>', '<Plug>(fall-switch-sorter-next)')
107+
call s:define('<F4>', '<Plug>(fall-switch-renderer-next)')
108+
call s:define('<F5>', '<Plug>(fall-switch-previewer-next)')
99109
endfunction
100110

101111
augroup fall_mapping_plugin

0 commit comments

Comments
 (0)