-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let s:vault = {} | ||
|
||
function skkeleton#internal#map#save(mode) abort | ||
let bufnr = bufnr() | ||
let s:vault[bufnr] = get(s:vault, bufnr, {}) | ||
let buf = s:vault[bufnr] | ||
if has_key(buf, a:mode) | ||
return | ||
endif | ||
if exists('*nvim_buf_get_keymap') | ||
let buf[a:mode] = nvim_buf_get_keymap(bufnr, a:mode) | ||
elseif exists('*maplist') | ||
let buf[a:mode] = maplist()->filter('v:val.buffer && v:val.mode == a:mode') | ||
endif | ||
endfunction | ||
|
||
function skkeleton#internal#map#restore() abort | ||
let bufnr = bufnr() | ||
let buf = get(s:vault, bufnr, {}) | ||
for [mode, maps] in items(buf) | ||
execute mode .. 'mapclear <buffer>' | ||
for m in maps | ||
call mapset(m) | ||
endfor | ||
endfor | ||
silent! unlet s:vault[bufnr] | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
" so % | ||
" TODO: rewrite with test framework | ||
|
||
function s:assert_equal(expected, actual) | ||
let v:errors = [] | ||
if assert_equal(a:expected, a:actual) | ||
throw v:errors[0] | ||
endif | ||
endfunction | ||
|
||
source <script>:h/map.vim | ||
nmapclear <buffer> | ||
nnoremap <buffer> a b | ||
call skkeleton#internal#map#save('n') | ||
nnoremap <buffer> b a | ||
call s:assert_equal(2, execute('nnoremap <buffer>')->split('\n')->len()) | ||
call skkeleton#internal#map#restore() | ||
call s:assert_equal(1, execute('nnoremap <buffer>')->split('\n')->len()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters