From 53b2c91f5da6c103647c106cc35419514ba83511 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 26 Mar 2017 23:07:33 +0800 Subject: [PATCH] Add mapping api --- autoload/SpaceVim/api/vim/compatible.vim | 27 ++++++++++++++++++ autoload/SpaceVim/api/vim/mapping.vim | 35 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 autoload/SpaceVim/api/vim/compatible.vim create mode 100644 autoload/SpaceVim/api/vim/mapping.vim diff --git a/autoload/SpaceVim/api/vim/compatible.vim b/autoload/SpaceVim/api/vim/compatible.vim new file mode 100644 index 000000000..a39352fa5 --- /dev/null +++ b/autoload/SpaceVim/api/vim/compatible.vim @@ -0,0 +1,27 @@ +function! SpaceVim#api#vim#compatible#get() abort + return map({ + \ 'execute' : '', + \ }, + \ "function('s:' . v:key)" + \ ) +endfunction + +function! s:execute(cmd, ...) abort + if a:0 == 0 + let s = 'silent' + else + let s = a:1 + endif + redir => output + if s ==# 'silent' + silent execute a:cmd + elseif s ==# 'silent!' + silent! execute a:cmd + else + execute a:cmd + endif + redir END + return output +endfunction + +" vim:set et sw=2 cc=80: diff --git a/autoload/SpaceVim/api/vim/mapping.vim b/autoload/SpaceVim/api/vim/mapping.vim new file mode 100644 index 000000000..d387e51d2 --- /dev/null +++ b/autoload/SpaceVim/api/vim/mapping.vim @@ -0,0 +1,35 @@ +let s:VIM = SpaceVim#api#import('vim#compatible') + +function! SpaceVim#api#vim#mapping#get() abort + return map({ + \ 'map' : '', + \ }, + \ "function('s:' . v:key)" + \ ) +endfunction + +function! s:map(...) abort + if a:0 == 1 + return s:parser(s:VIM.execute(':map ' . a:1)) + endif + return [] +endfunction + +function! s:parser(rst) abort + let mappings = split(a:rst, "\n") + let mappings = map(mappings, 'split(v:val)') + let rst = [] + for mapping in mappings + if len(mapping) >= 3 + let mode = mapping[0] + let key = mapping[1] + let m = maparg(key, mode, 0, 1) + if !empty(m) + call add(rst, m) + endif + endif + endfor + return rst +endfunction + +" vim:set et sw=2 cc=80: