vim-easymotion/autoload/vital/_easymotion/Palette/Keymapping.vim

133 lines
3.6 KiB
VimL
Raw Normal View History

2015-02-23 11:19:17 -05:00
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
2015-06-28 10:01:55 -04:00
let s:modep = "[nvoicsxl]"
2015-02-23 11:19:17 -05:00
function! s:_vital_loaded(V)
let s:V = a:V
2015-06-28 10:01:55 -04:00
let s:Capture = s:V.import("Palette.Capture")
2015-02-23 11:19:17 -05:00
endfunction
function! s:_vital_depends()
return [
2015-06-28 10:01:55 -04:00
\ "Palette.Capture",
2015-02-23 11:19:17 -05:00
\ ]
endfunction
2015-06-28 10:01:55 -04:00
function! s:_capture(mode)
let cmd = "map"
if a:mode ==# "!"
let cmd = cmd . "!"
elseif a:mode =~# "[nvoicsxl]"
let cmd = a:mode . cmd
endif
return s:Capture.command(cmd)
endfunction
2015-02-23 11:19:17 -05:00
function! s:capture(...)
let mode = get(a:, 1, "")
2015-06-28 10:01:55 -04:00
let modes = split(mode, '\zs')
return join(map(modes, "s:_capture(v:val)"), "\n")
2015-02-23 11:19:17 -05:00
endfunction
function! s:_keymapping(str)
2015-06-28 10:01:55 -04:00
return a:str =~ '^[!nvoicsxl]\s'
2015-02-23 11:19:17 -05:00
endfunction
function! s:capture_list(...)
let mode = get(a:, 1, "")
return filter(split(s:capture(mode), "\n"), "s:_keymapping(v:val)")
endfunction
function! s:escape_special_key(key)
2015-06-28 10:01:55 -04:00
" Workaround : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:key ==# "<^?>"
return "\<C-?>"
endif
2015-02-23 11:19:17 -05:00
execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"'
return result
endfunction
function! s:parse_lhs(text, ...)
2015-06-28 10:01:55 -04:00
let mode = get(a:, 1, '[!nvoicsxl]')
" NOTE: :map! Surpport : https://github.com/osyo-manga/vital-palette/issues/4
if get(a:, 1, "") =~# '[!ci]'
let mode = '[!ci]'
endif
return matchstr(a:text, mode . '\{1,3\}\s*\zs\S\{-}\ze\s\+')
2015-02-23 11:19:17 -05:00
endfunction
function! s:parse_lhs_list(...)
let mode = get(a:, 1, "")
return map(s:capture_list(mode), "s:parse_lhs(v:val, mode)")
endfunction
function! s:lhs_key_list(...)
let mode = get(a:, 1, "")
return map(s:parse_lhs_list(mode), "s:escape_special_key(v:val)")
endfunction
2015-06-28 10:01:55 -04:00
function! s:_maparg(name, mode, abbr, dict)
" Workaround : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:name ==# "<^?>"
return maparg("\<C-?>", a:mode, a:abbr, a:dict)
endif
return maparg(a:name, a:mode, a:abbr, a:dict)
endfunction
2015-02-23 11:19:17 -05:00
function! s:rhs_key_list(...)
let mode = get(a:, 1, "")
let abbr = get(a:, 2, 0)
let dict = get(a:, 3, 0)
2015-06-28 10:01:55 -04:00
let result = []
for m in split(mode, '\zs')
let result += map(s:parse_lhs_list(m), "s:_maparg(v:val, m, abbr, dict)")
endfor
return filter(result, "empty(v:val) == 0")
2015-02-23 11:19:17 -05:00
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
2016-03-22 08:55:42 -04:00
" ___Revitalizer___
" NOTE: below code is generated by :Revitalize.
" Do not mofidify the code nor append new lines
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:___revitalizer_function___(fstr) abort
return function(a:fstr)
endfunction
else
function! s:___revitalizer_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze____revitalizer_SID$')
endfunction
let s:___revitalizer_sid = '<SNR>' . s:___revitalizer_SID() . '_'
function! s:___revitalizer_function___(fstr) abort
return function(substitute(a:fstr, 's:', s:___revitalizer_sid, 'g'))
endfunction
endif
2016-03-22 10:04:08 -04:00
let s:___revitalizer_functions___ = {'_vital_depends': s:___revitalizer_function___('s:_vital_depends'),'_vital_loaded': s:___revitalizer_function___('s:_vital_loaded'),'capture': s:___revitalizer_function___('s:capture'),'capture_list': s:___revitalizer_function___('s:capture_list'),'escape_special_key': s:___revitalizer_function___('s:escape_special_key'),'lhs_key_list': s:___revitalizer_function___('s:lhs_key_list'),'parse_lhs': s:___revitalizer_function___('s:parse_lhs'),'parse_lhs_list': s:___revitalizer_function___('s:parse_lhs_list'),'rhs_key_list': s:___revitalizer_function___('s:rhs_key_list')}
2016-03-22 08:55:42 -04:00
unlet! s:___revitalizer_sid
delfunction s:___revitalizer_function___
function! vital#_easymotion#Palette#Keymapping#import() abort
return s:___revitalizer_functions___
endfunction
" ___Revitalizer___