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
|