49 changed files with 9392 additions and 731 deletions
@ -0,0 +1,4 @@ |
|||||||
|
doc/tags |
||||||
|
tmp* |
||||||
|
*.lock |
||||||
|
.vim-flavor |
@ -0,0 +1,10 @@ |
|||||||
|
language: ruby |
||||||
|
rvm: |
||||||
|
- 2.0.0 |
||||||
|
before_script: |
||||||
|
- bundle install |
||||||
|
- bundle show |
||||||
|
script: |
||||||
|
- rake ci |
||||||
|
install: |
||||||
|
- git clone https://github.com/kana/vim-vspec.git |
@ -0,0 +1,4 @@ |
|||||||
|
source 'https://rubygems.org' |
||||||
|
|
||||||
|
gem 'vim-flavor', '~> 1.1' |
||||||
|
gem 'rake' |
@ -0,0 +1,11 @@ |
|||||||
|
#!/usr/bin/env rake |
||||||
|
|
||||||
|
task :ci => [:dump, :test] |
||||||
|
|
||||||
|
task :dump do |
||||||
|
sh 'vim --version' |
||||||
|
end |
||||||
|
|
||||||
|
task :test do |
||||||
|
sh 'bundle exec vim-flavor test' |
||||||
|
end |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,109 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: autoload/EasyMotion/cmigemo.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
scriptencoding utf-8 |
||||||
|
" Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
|
||||||
|
function! s:has_vimproc() "{{{ |
||||||
|
if !exists('s:exists_vimproc') |
||||||
|
try |
||||||
|
silent call vimproc#version() |
||||||
|
let s:exists_vimproc = 1 |
||||||
|
catch |
||||||
|
let s:exists_vimproc = 0 |
||||||
|
endtry |
||||||
|
endif |
||||||
|
|
||||||
|
return s:exists_vimproc |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#cmigemo#system(...) "{{{ |
||||||
|
return call(s:has_vimproc() ? 'vimproc#system' : 'system', a:000) |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! s:SearchDict2(name) "{{{ |
||||||
|
let path = $VIM . ',' . &runtimepath |
||||||
|
let dict = globpath(path, "dict/".a:name) |
||||||
|
if dict == '' |
||||||
|
let dict = globpath(path, a:name) |
||||||
|
endif |
||||||
|
if dict == '' |
||||||
|
for path in [ |
||||||
|
\ '/usr/local/share/migemo/', |
||||||
|
\ '/usr/local/share/cmigemo/', |
||||||
|
\ '/usr/local/share/', |
||||||
|
\ '/usr/share/cmigemo/', |
||||||
|
\ '/usr/share/', |
||||||
|
\ ] |
||||||
|
let path = path . a:name |
||||||
|
if filereadable(path) |
||||||
|
let dict = path |
||||||
|
break |
||||||
|
endif |
||||||
|
endfor |
||||||
|
endif |
||||||
|
let dict = matchstr(dict, "^[^\<NL>]*") |
||||||
|
return dict |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! s:SearchDict() "{{{ |
||||||
|
for path in [ |
||||||
|
\ 'migemo/'.&encoding.'/migemo-dict', |
||||||
|
\ &encoding.'/migemo-dict', |
||||||
|
\ 'migemo-dict', |
||||||
|
\ ] |
||||||
|
let dict = s:SearchDict2(path) |
||||||
|
if dict != '' |
||||||
|
return dict |
||||||
|
endif |
||||||
|
endfor |
||||||
|
echoerr 'a dictionary for migemo is not found' |
||||||
|
echoerr 'your encoding is '.&encoding |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#cmigemo#getMigemoPattern(input) "{{{ |
||||||
|
if !exists('s:migemodict') |
||||||
|
let s:migemodict = s:SearchDict() |
||||||
|
endif |
||||||
|
|
||||||
|
if has('migemo') |
||||||
|
" Use migemo(). |
||||||
|
return migemo(a:input) |
||||||
|
elseif executable('cmigemo') |
||||||
|
" Use cmigemo. |
||||||
|
return EasyMotion#cmigemo#system('cmigemo -v -w "'.a:input.'" -d "'.s:migemodict.'"') |
||||||
|
else |
||||||
|
" Not supported |
||||||
|
return a:input |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4 |
@ -0,0 +1,288 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: autoload/EasyMotion/command_line.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" Reference: https://github.com/osyo-manga/vim-over |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
scriptencoding utf-8 |
||||||
|
" Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
|
||||||
|
" CommandLine: |
||||||
|
let s:V = vital#of('easymotion') |
||||||
|
let s:cmdline = s:V.import('Over.Commandline.Base') |
||||||
|
let s:modules = s:V.import("Over.Commandline.Modules") |
||||||
|
let s:search = s:cmdline.make() |
||||||
|
let s:search.highlights.prompt = 'Question' |
||||||
|
|
||||||
|
" Add Module: {{{ |
||||||
|
call s:search.connect('Exit') |
||||||
|
call s:search.connect('Cancel') |
||||||
|
call s:search.connect('Redraw') |
||||||
|
call s:search.connect('DrawCommandline') |
||||||
|
call s:search.connect('Delete') |
||||||
|
call s:search.connect('CursorMove') |
||||||
|
call s:search.connect('Paste') |
||||||
|
call s:search.connect('BufferComplete') |
||||||
|
call s:search.connect('InsertRegister') |
||||||
|
call s:search.connect('ExceptionExit') |
||||||
|
call s:search.connect(s:modules.get('ExceptionMessage').make('EasyMotion: ', 'echom')) |
||||||
|
call s:search.connect(s:modules.get('History').make('/')) |
||||||
|
call s:search.connect(s:modules.get('NoInsert').make_special_chars()) |
||||||
|
call s:search.connect(s:modules.get('KeyMapping').make_emacs()) |
||||||
|
call s:search.connect(s:modules.get('Doautocmd').make('EMCommandLine')) |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "EasyMotion", |
||||||
|
\} |
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("<Over>(em-scroll-f)") |
||||||
|
call s:scroll(0) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("<Over>(em-scroll-b)") |
||||||
|
call s:scroll(1) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("<Over>(em-jumpback)") |
||||||
|
keepjumps call setpos('.', s:save_orig_pos) |
||||||
|
let s:orig_pos = s:save_orig_pos |
||||||
|
let s:orig_line_start = getpos('w0') |
||||||
|
let s:orig_line_end = getpos('w$') |
||||||
|
let s:direction = s:save_direction |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("<Over>(em-openallfold)") |
||||||
|
" TODO: better solution |
||||||
|
normal! zR |
||||||
|
call a:cmdline.setchar('') |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
call s:search.connect(s:module) |
||||||
|
"}}} |
||||||
|
|
||||||
|
" CommandLine Keymap: {{{ |
||||||
|
function! s:search.keymapping() "{{{ |
||||||
|
return { |
||||||
|
\ "\<C-l>" : { |
||||||
|
\ "key" : "<Over>(buffer-complete)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<Tab>" : { |
||||||
|
\ "key" : "<Over>(em-scroll-f)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<S-Tab>" : { |
||||||
|
\ "key" : "<Over>(em-scroll-b)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-o>" : { |
||||||
|
\ "key" : "<Over>(em-jumpback)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-z>" : { |
||||||
|
\ "key" : "<Over>(em-openallfold)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<CR>" : { |
||||||
|
\ "key" : "<Over>(exit)", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ } |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Fins Motion CommandLine Mapping Command: {{{ |
||||||
|
function! EasyMotion#command_line#cmap(args) |
||||||
|
let lhs = s:as_keymapping(a:args[0]) |
||||||
|
let rhs = s:as_keymapping(a:args[1]) |
||||||
|
call s:search.cmap(lhs, rhs) |
||||||
|
endfunction |
||||||
|
function! EasyMotion#command_line#cnoremap(args) |
||||||
|
let lhs = s:as_keymapping(a:args[0]) |
||||||
|
let rhs = s:as_keymapping(a:args[1]) |
||||||
|
call s:search.cnoremap(lhs, rhs) |
||||||
|
endfunction |
||||||
|
function! EasyMotion#command_line#cunmap(lhs) |
||||||
|
let lhs = s:as_keymapping(a:lhs) |
||||||
|
call s:search.cunmap(lhs) |
||||||
|
endfunction |
||||||
|
function! s:as_keymapping(key) |
||||||
|
execute 'let result = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"' |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
"}}} |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Event: {{{ |
||||||
|
function! s:search.on_enter(cmdline) "{{{ |
||||||
|
if s:num_strokes == -1 |
||||||
|
call EasyMotion#highlight#delete_highlight() |
||||||
|
call EasyMotion#helper#VarReset('&scrolloff', 0) |
||||||
|
if g:EasyMotion_do_shade |
||||||
|
call EasyMotion#highlight#add_highlight('\_.*', |
||||||
|
\ g:EasyMotion_hl_group_shade) |
||||||
|
endif |
||||||
|
endif |
||||||
|
if g:EasyMotion_cursor_highlight |
||||||
|
call EasyMotion#highlight#add_highlight('\%#', |
||||||
|
\ g:EasyMotion_hl_inc_cursor) |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
function! s:search.on_leave(cmdline) "{{{ |
||||||
|
if s:num_strokes == -1 |
||||||
|
call EasyMotion#highlight#delete_highlight(g:EasyMotion_hl_inc_search) |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
function! s:search.on_char(cmdline) "{{{ |
||||||
|
if s:num_strokes == -1 |
||||||
|
let re = s:search.getline() |
||||||
|
if EasyMotion#helper#should_case_sensitive(re, 1) |
||||||
|
let case_flag = '\c' |
||||||
|
else |
||||||
|
let case_flag = '\C' |
||||||
|
endif |
||||||
|
let re .= case_flag |
||||||
|
if g:EasyMotion_inc_highlight |
||||||
|
call s:inc_highlight(re) |
||||||
|
endif |
||||||
|
if g:EasyMotion_off_screen_search |
||||||
|
call s:off_screen_search(re) |
||||||
|
endif |
||||||
|
elseif s:search.line.length() >= s:num_strokes |
||||||
|
call s:search.exit() |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Main: |
||||||
|
function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{ |
||||||
|
let s:num_strokes = a:num_strokes |
||||||
|
|
||||||
|
let s:prompt_base = s:getPromptMessage(a:num_strokes) |
||||||
|
call s:search.set_prompt(s:prompt_base) |
||||||
|
|
||||||
|
" Screen: cursor position, first and last line |
||||||
|
let s:orig_pos = getpos('.') |
||||||
|
let s:orig_line_start = getpos('w0') |
||||||
|
let s:orig_line_end = getpos('w$') |
||||||
|
let s:save_orig_pos = deepcopy(s:orig_pos) |
||||||
|
|
||||||
|
" Direction: |
||||||
|
let s:direction = a:direction == 1 ? 'b' : '' |
||||||
|
let s:save_direction = deepcopy(s:direction) |
||||||
|
|
||||||
|
let input = s:search.get() |
||||||
|
if input == '' && ! s:search.exit_code() |
||||||
|
return a:prev |
||||||
|
elseif s:search.exit_code() == 1 || s:search.exit_code() == -1 |
||||||
|
call s:Cancell() |
||||||
|
return '' |
||||||
|
else |
||||||
|
return input |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Helper: |
||||||
|
function! s:Cancell() " {{{ |
||||||
|
call EasyMotion#highlight#delete_highlight() |
||||||
|
call EasyMotion#helper#VarReset('&scrolloff') |
||||||
|
keepjumps call setpos('.', s:save_orig_pos) |
||||||
|
echo 'EasyMotion: Cancelled' |
||||||
|
return '' |
||||||
|
endfunction " }}} |
||||||
|
function! s:getPromptMessage(num_strokes) "{{{ |
||||||
|
if a:num_strokes == 1 |
||||||
|
let prompt = substitute( |
||||||
|
\ substitute(g:EasyMotion_prompt,'{n}', a:num_strokes, 'g'), |
||||||
|
\ '(s)', '', 'g') |
||||||
|
elseif a:num_strokes == -1 |
||||||
|
let prompt = substitute( |
||||||
|
\ substitute(g:EasyMotion_prompt, '{n}\s\{0,1}', '', 'g'), |
||||||
|
\ '(s)', 's', 'g') |
||||||
|
else |
||||||
|
let prompt = substitute( |
||||||
|
\ substitute(g:EasyMotion_prompt,'{n}', a:num_strokes, 'g'), |
||||||
|
\ '(s)', 's', 'g') |
||||||
|
endif |
||||||
|
return prompt |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! s:off_screen_search(re) "{{{ |
||||||
|
" First: search within visible screen range |
||||||
|
call s:adjust_screen() |
||||||
|
" Error occur when '\zs' without '!' |
||||||
|
silent! let pos = searchpos(a:re, s:direction . 'n', s:orig_line_end[1]) |
||||||
|
if pos != [0, 0] |
||||||
|
" Restore cursor posision |
||||||
|
keepjumps call setpos('.', s:orig_pos) |
||||||
|
else |
||||||
|
" Second: if there were no much, search off screen |
||||||
|
silent! let pos = searchpos(a:re, s:direction) |
||||||
|
if pos != [0, 0] |
||||||
|
" Match |
||||||
|
keepjumps call setpos('.', pos) |
||||||
|
" Move cursor |
||||||
|
if s:save_direction != 'b' |
||||||
|
normal! zzH0 |
||||||
|
else |
||||||
|
normal! zzL0 |
||||||
|
endif |
||||||
|
else |
||||||
|
" No much |
||||||
|
call s:adjust_screen() |
||||||
|
keepjumps call setpos('.', s:orig_pos) |
||||||
|
endif |
||||||
|
endif |
||||||
|
" redraw |
||||||
|
endfunction "}}} |
||||||
|
function! s:adjust_screen() "{{{ |
||||||
|
if s:save_direction != 'b' |
||||||
|
" Forward |
||||||
|
keepjumps call setpos('.', s:orig_line_start) |
||||||
|
normal! zt |
||||||
|
else |
||||||
|
" Backward |
||||||
|
keepjumps call setpos('.', s:orig_line_end) |
||||||
|
normal! zb |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
function! s:scroll(direction) "{{{ |
||||||
|
" direction: 0 -> forward, 1 -> backward |
||||||
|
exec a:direction == 0 ? "normal! \<C-f>" : "normal! \<C-b>" |
||||||
|
let s:orig_pos = getpos('.') |
||||||
|
let s:orig_line_start = getpos('w0') |
||||||
|
let s:orig_line_end = getpos('w$') |
||||||
|
let s:direction = a:direction == 0 ? '' : 'b' |
||||||
|
endfunction "}}} |
||||||
|
function! s:inc_highlight(re) "{{{ |
||||||
|
call EasyMotion#highlight#delete_highlight(g:EasyMotion_hl_inc_search) |
||||||
|
if s:search.line.length() > 0 |
||||||
|
" Error occur when '\zs' without '!' |
||||||
|
silent! call EasyMotion#highlight#add_highlight(a:re, g:EasyMotion_hl_inc_search) |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4 |
@ -0,0 +1,167 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: autoload/EasyMotion/helper.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
scriptencoding utf-8 |
||||||
|
" Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
|
||||||
|
function! EasyMotion#helper#mode(flag) "{{{ |
||||||
|
return mode(a:flag) == "\<C-v>" ? "C-v" : mode(a:flag) |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#helper#get_char_by_coord(coord) "{{{ |
||||||
|
" @param coord: [lnum, col] or [bufnum, lnum, col, off] |
||||||
|
if len(a:coord) == 4 |
||||||
|
let [line_num, col_num] = [a:coord[1], a:coord[2]] |
||||||
|
else |
||||||
|
let [line_num, col_num] = a:coord |
||||||
|
endif |
||||||
|
let target_col_regexp = '\%' . (col_num) . 'c.' |
||||||
|
return matchstr(getline(line_num), target_col_regexp) |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#helper#is_greater_coords(coords1, coords2) "{{{ |
||||||
|
" [line_num, col_num] < [line_num, col_num] |
||||||
|
" |
||||||
|
" coords1 < coords2 : return 1 |
||||||
|
" coords1 > coords2 : return -1 |
||||||
|
" coords1 == coords2 : return 0 |
||||||
|
if a:coords1 == a:coords2 | return 0 | endif |
||||||
|
|
||||||
|
if a:coords1[0] < a:coords2[0] |
||||||
|
return 1 |
||||||
|
elseif a:coords1[0] > a:coords2[0] |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
|
||||||
|
" Same line |
||||||
|
if a:coords1[1] < a:coords2[1] |
||||||
|
return 1 |
||||||
|
elseif a:coords1[1] > a:coords2[1] |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#helper#is_folded(line) "{{{ |
||||||
|
" Return false if g:EasyMotion_skipfoldedline == 1 |
||||||
|
" and line is start of folded lines |
||||||
|
let _foldclosed = foldclosed(a:line) |
||||||
|
return _foldclosed != -1 && |
||||||
|
\ (g:EasyMotion_skipfoldedline == 1 || a:line != _foldclosed) |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#helper#should_case_sensitive(input, is_search) "{{{ |
||||||
|
if !a:is_search |
||||||
|
if g:EasyMotion_smartcase == 0 |
||||||
|
return 0 |
||||||
|
else |
||||||
|
" return 1 if input didn't match uppercase letter |
||||||
|
return match(a:input, '\u') == -1 |
||||||
|
endif |
||||||
|
endif |
||||||
|
|
||||||
|
if (g:EasyMotion_smartcase == 1 && match(a:input, '\u') == -1) || |
||||||
|
\ (&ignorecase && &smartcase && match(a:input, '\u') == -1) || |
||||||
|
\ (&ignorecase && !&smartcase) |
||||||
|
return 1 |
||||||
|
endif |
||||||
|
return 0 |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#helper#silent_feedkeys(expr, name, ...) "{{{ |
||||||
|
" Ref: |
||||||
|
" https://github.com/osyo-manga/vim-over/blob/d51b028c29661d4a5f5b79438ad6d69266753711/autoload/over.vim#L6 |
||||||
|
let mode = get(a:, 1, "m") |
||||||
|
let name = "easymotion-" . a:name |
||||||
|
let map = printf("<Plug>(%s)", name) |
||||||
|
if mode == "n" |
||||||
|
let command = "nnoremap" |
||||||
|
else |
||||||
|
let command = "nmap" |
||||||
|
endif |
||||||
|
execute command "<silent>" map printf("%s:nunmap %s<CR>", a:expr, map) |
||||||
|
if mode(1) !=# 'ce' |
||||||
|
" FIXME: mode(1) !=# 'ce' exists only for the test |
||||||
|
" :h feedkeys() doesn't work while runnning a test script |
||||||
|
" https://github.com/kana/vim-vspec/issues/27 |
||||||
|
call feedkeys(printf("\<Plug>(%s)", name)) |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#helper#VarReset(var, ...) "{{{ |
||||||
|
if ! exists('s:var_reset') |
||||||
|
let s:var_reset = {} |
||||||
|
endif |
||||||
|
|
||||||
|
if a:0 == 0 && has_key(s:var_reset, a:var) |
||||||
|
" Reset var to original value |
||||||
|
" setbufvar( or bufname): '' or '%' can be used for the current buffer |
||||||
|
call setbufvar('%', a:var, s:var_reset[a:var]) |
||||||
|
elseif a:0 == 1 |
||||||
|
" Save original value and set new var value |
||||||
|
|
||||||
|
let new_value = a:0 == 1 ? a:1 : '' |
||||||
|
|
||||||
|
" Store original value |
||||||
|
let s:var_reset[a:var] = getbufvar("", a:var) |
||||||
|
|
||||||
|
" Set new var value |
||||||
|
call setbufvar('%', a:var, new_value) |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Migemo {{{ |
||||||
|
function! EasyMotion#helper#load_migemo_dict() "{{{ |
||||||
|
let enc = &l:encoding |
||||||
|
if enc ==# 'utf-8' |
||||||
|
return EasyMotion#migemo#utf8#load_dict() |
||||||
|
elseif enc ==# 'cp932' |
||||||
|
return EasyMotion#migemo#cp932#load_dict() |
||||||
|
elseif enc ==# 'euc-jp' |
||||||
|
return EasyMotion#migemo#eucjp#load_dict() |
||||||
|
else |
||||||
|
let g:EasyMotion_use_migemo = 0 |
||||||
|
throw "Error: ".enc." is not supported. Migemo is made disabled." |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" EasyMotion#helper#strchars() {{{ |
||||||
|
if exists('*strchars') |
||||||
|
function! EasyMotion#helper#strchars(str) |
||||||
|
return strchars(a:str) |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! EasyMotion#helper#strchars(str) |
||||||
|
return strlen(substitute(a:str, ".", "x", "g")) |
||||||
|
endfunction |
||||||
|
endif "}}} |
||||||
|
function! EasyMotion#helper#include_multibyte_char(str) "{{{ |
||||||
|
return strlen(a:str) != EasyMotion#helper#strchars(a:str) |
||||||
|
endfunction "}}} |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4 |
@ -0,0 +1,251 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: highlight.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" Reference: https://github.com/t9md/vim-smalls |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
scriptencoding utf-8 |
||||||
|
" Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
|
||||||
|
function! EasyMotion#highlight#load() |
||||||
|
"load |
||||||
|
endfunction |
||||||
|
|
||||||
|
" -- Default highlighting ---------------- {{{ |
||||||
|
let g:EasyMotion_hl_group_target = get(g:, |
||||||
|
\ 'EasyMotion_hl_group_target', 'EasyMotionTarget') |
||||||
|
let g:EasyMotion_hl2_first_group_target = get(g:, |
||||||
|
\ 'EasyMotion_hl2_first_group_target', 'EasyMotionTarget2First') |
||||||
|
let g:EasyMotion_hl2_second_group_target = get(g:, |
||||||
|
\ 'EasyMotion_hl2_second_group_target', 'EasyMotionTarget2Second') |
||||||
|
let g:EasyMotion_hl_group_shade = get(g:, |
||||||
|
\ 'EasyMotion_hl_group_shade', 'EasyMotionShade') |
||||||
|
|
||||||
|
let g:EasyMotion_hl_inc_search = get(g:, |
||||||
|
\ 'EasyMotion_hl_inc_search', 'EasyMotionIncSearch') |
||||||
|
let g:EasyMotion_hl_inc_cursor = get(g:, |
||||||
|
\ 'EasyMotion_hl_inc_cursor', 'EasyMotionIncCursor') |
||||||
|
let g:EasyMotion_hl_move = get(g:, |
||||||
|
\ 'EasyMotion_hl_move', 'EasyMotionMoveHL') |
||||||
|
|
||||||
|
let s:target_hl_defaults = { |
||||||
|
\ 'gui' : ['NONE', '#ff0000' , 'bold'] |
||||||
|
\ , 'cterm256': ['NONE', '196' , 'bold'] |
||||||
|
\ , 'cterm' : ['NONE', 'red' , 'bold'] |
||||||
|
\ } |
||||||
|
|
||||||
|
let s:target_hl2_first_defaults = { |
||||||
|
\ 'gui' : ['NONE', '#ffb400' , 'bold'] |
||||||
|
\ , 'cterm256': ['NONE', '11' , 'bold'] |
||||||
|
\ , 'cterm' : ['NONE', 'yellow' , 'bold'] |
||||||
|
\ } |
||||||
|
|
||||||
|
let s:target_hl2_second_defaults = { |
||||||
|
\ 'gui' : ['NONE', '#b98300' , 'bold'] |
||||||
|
\ , 'cterm256': ['NONE', '3' , 'bold'] |
||||||
|
\ , 'cterm' : ['NONE', 'yellow' , 'bold'] |
||||||
|
\ } |
||||||
|
|
||||||
|
let s:shade_hl_defaults = { |
||||||
|
\ 'gui' : ['NONE', '#777777' , 'NONE'] |
||||||
|
\ , 'cterm256': ['NONE', '242' , 'NONE'] |
||||||
|
\ , 'cterm' : ['NONE', 'grey' , 'NONE'] |
||||||
|
\ } |
||||||
|
|
||||||
|
let s:shade_hl_line_defaults = { |
||||||
|
\ 'gui' : ['red' , '#FFFFFF' , 'NONE'] |
||||||
|
\ , 'cterm256': ['red' , '242' , 'NONE'] |
||||||
|
\ , 'cterm' : ['red' , 'grey' , 'NONE'] |
||||||
|
\ } |
||||||
|
|
||||||
|
let s:target_hl_inc = { |
||||||
|
\ 'gui' : ['NONE', '#7fbf00' , 'bold'] |
||||||
|
\ , 'cterm256': ['NONE', '40' , 'bold'] |
||||||
|
\ , 'cterm' : ['NONE', 'green' , 'bold'] |
||||||
|
\ } |
||||||
|
let s:target_hl_inc_cursor = { |
||||||
|
\ 'gui' : ['#ACDBDA', '#121813' , 'bold'] |
||||||
|
\ , 'cterm256': ['cyan' , '232' , 'bold'] |
||||||
|
\ , 'cterm' : ['cyan' , 'black' , 'bold'] |
||||||
|
\ } |
||||||
|
let s:target_hl_move = { |
||||||
|
\ 'gui' : ['#7fbf00', '#121813' , 'bold'] |
||||||
|
\ , 'cterm256': ['green' , '15' , 'bold'] |
||||||
|
\ , 'cterm' : ['green' , 'white' , 'bold'] |
||||||
|
\ } |
||||||
|
" }}} |
||||||
|
function! EasyMotion#highlight#InitHL(group, colors) " {{{ |
||||||
|
let group_default = a:group . 'Default' |
||||||
|
|
||||||
|
" Prepare highlighting variables |
||||||
|
let guihl = printf('guibg=%s guifg=%s gui=%s', a:colors.gui[0], a:colors.gui[1], a:colors.gui[2]) |
||||||
|
let ctermhl = &t_Co == 256 |
||||||
|
\ ? printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm256[0], a:colors.cterm256[1], a:colors.cterm256[2]) |
||||||
|
\ : printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm[0], a:colors.cterm[1], a:colors.cterm[2]) |
||||||
|
|
||||||
|
" Create default highlighting group |
||||||
|
execute printf('hi default %s %s %s', group_default, guihl, ctermhl) |
||||||
|
|
||||||
|
" Check if the hl group exists |
||||||
|
if hlexists(a:group) |
||||||
|
redir => hlstatus | exec 'silent hi ' . a:group | redir END |
||||||
|
|
||||||
|
" Return if the group isn't cleared |
||||||
|
if hlstatus !~ 'cleared' |
||||||
|
return |
||||||
|
endif |
||||||
|
endif |
||||||
|
|
||||||
|
" No colors are defined for this group, link to defaults |
||||||
|
execute printf('hi default link %s %s', a:group, group_default) |
||||||
|
endfunction " }}} |
||||||
|
function! EasyMotion#highlight#init() "{{{ |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl2_first_group_target, s:target_hl2_first_defaults) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl2_second_group_target, s:target_hl2_second_defaults) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl_inc_search, s:target_hl_inc) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl_inc_cursor, s:target_hl_inc_cursor) |
||||||
|
call EasyMotion#highlight#InitHL(g:EasyMotion_hl_move, s:target_hl_move) |
||||||
|
if exists(':CSApprox') == 2 && g:EasyMotion_force_csapprox |
||||||
|
"TODO: better solution or remove completly |
||||||
|
CSApprox! |
||||||
|
endif |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Reset highlighting after loading a new color scheme {{{ |
||||||
|
augroup EasyMotionInitHL |
||||||
|
autocmd! |
||||||
|
autocmd ColorScheme * call EasyMotion#highlight#init() |
||||||
|
augroup end |
||||||
|
" }}} |
||||||
|
|
||||||
|
call EasyMotion#highlight#init() |
||||||
|
" Init: {{{ |
||||||
|
let s:h = {} |
||||||
|
let s:h.ids = {} |
||||||
|
let s:priorities = { |
||||||
|
\ g:EasyMotion_hl_group_target : 100, |
||||||
|
\ g:EasyMotion_hl2_first_group_target : 100, |
||||||
|
\ g:EasyMotion_hl2_second_group_target : 100, |
||||||
|
\ g:EasyMotion_hl_group_shade : 0, |
||||||
|
\ g:EasyMotion_hl_inc_search : 1, |
||||||
|
\ g:EasyMotion_hl_inc_cursor : 2, |
||||||
|
\ g:EasyMotion_hl_move : 0, |
||||||
|
\ } |
||||||
|
for s:group in keys(s:priorities) |
||||||
|
let s:h.ids[s:group] = [] |
||||||
|
endfor |
||||||
|
unlet s:group |
||||||
|
"}}} |
||||||
|
|
||||||
|
function! EasyMotion#highlight#delete_highlight(...) "{{{ |
||||||
|
let groups = !empty(a:000) ? a:000 : keys(s:priorities) |
||||||
|
for group in groups |
||||||
|
for id in s:h.ids[group] |
||||||
|
silent! call matchdelete(id) |
||||||
|
endfor |
||||||
|
let s:h.ids[group] = [] |
||||||
|
endfor |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#add_highlight(re, group) "{{{ |
||||||
|
call add(s:h.ids[a:group], matchadd(a:group, a:re, s:priorities[a:group])) |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#add_pos_highlight(line_num, col_num, group) "{{{ |
||||||
|
call add(s:h.ids[a:group], matchaddpos(a:group, [[a:line_num, a:col_num]], s:priorities[a:group])) |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#attach_autocmd() "{{{ |
||||||
|
" Reference: https://github.com/justinmk/vim-sneak |
||||||
|
augroup plugin-easymotion |
||||||
|
autocmd! |
||||||
|
autocmd InsertEnter,WinLeave,BufLeave <buffer> |
||||||
|
\ silent! call EasyMotion#highlight#delete_highlight() |
||||||
|
\ | autocmd! plugin-easymotion * <buffer> |
||||||
|
autocmd CursorMoved <buffer> |
||||||
|
\ autocmd plugin-easymotion CursorMoved <buffer> |
||||||
|
\ silent! call EasyMotion#highlight#delete_highlight() |
||||||
|
\ | autocmd! plugin-easymotion * <buffer> |
||||||
|
augroup END |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#add_color_group(new_groups) "{{{ |
||||||
|
let s:priorities = extend(deepcopy(s:priorities), a:new_groups) |
||||||
|
for group in keys(a:new_groups) |
||||||
|
let s:h.ids[group] = [] |
||||||
|
endfor |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
function! EasyMotion#highlight#capture(hlname) "{{{ |
||||||
|
" Based On: https://github.com/t9md/vim-ezbar |
||||||
|
" https://github.com/osyo-manga/vital-over |
||||||
|
let hlname = a:hlname |
||||||
|
if !hlexists(hlname) |
||||||
|
return |
||||||
|
endif |
||||||
|
while 1 |
||||||
|
let save_verbose = &verbose |
||||||
|
let &verbose = 0 |
||||||
|
try |
||||||
|
redir => HL_SAVE |
||||||
|
execute 'silent! highlight ' . hlname |
||||||
|
redir END |
||||||
|
finally |
||||||
|
let &verbose = save_verbose |
||||||
|
endtry |
||||||
|
if !empty(matchstr(HL_SAVE, 'xxx cleared$')) |
||||||
|
return '' |
||||||
|
endif |
||||||
|
" follow highlight link |
||||||
|
let ml = matchlist(HL_SAVE, 'links to \zs.*') |
||||||
|
if !empty(ml) |
||||||
|
let hlname = ml[0] |
||||||
|
continue |
||||||
|
endif |
||||||
|
break |
||||||
|
endwhile |
||||||
|
let HL_SAVE = substitute(matchstr(HL_SAVE, 'xxx \zs.*'), |
||||||
|
\ '[ \t\n]\+', ' ', 'g') |
||||||
|
return [hlname, HL_SAVE] |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#turn_off(hl) "{{{ |
||||||
|
if type(a:hl) != type([]) |
||||||
|
return |
||||||
|
endif |
||||||
|
execute 'highlight ' . a:hl[0] . ' NONE' |
||||||
|
endfunction "}}} |
||||||
|
function! EasyMotion#highlight#turn_on(hl) "{{{ |
||||||
|
if type(a:hl) != type([]) |
||||||
|
return |
||||||
|
endif |
||||||
|
execute 'highlight ' . a:hl[0] . ' ' . a:hl[1] |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" __END__ {{{ |
||||||
|
" vim: expandtab softtabstop=4 shiftwidth=4 |
||||||
|
" vim: foldmethod=marker |
||||||
|
" }}} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,24 @@ |
|||||||
|
" Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
" |
||||||
|
let EasyMotion#sticky_table#us = { |
||||||
|
\',' : '<', '.' : '>', '/' : '?', |
||||||
|
\'1' : '!', '2' : '@', '3' : '#', '4' : '$', '5' : '%', |
||||||
|
\'6' : '^', '7' : '&', '8' : '*', '9' : '(', '0' : ')', '-' : '_', '=' : '+', |
||||||
|
\';' : ':', '[' : '{', ']' : '}', '`' : '~', "'" : "\"", '\' : '|', |
||||||
|
\} |
||||||
|
|
||||||
|
let EasyMotion#sticky_table#jp = { |
||||||
|
\',' : '<', '.' : '>', '/' : '?', |
||||||
|
\'1' : '!', '2' : '"', '3' : '#', '4' : '$', '5' : '%', |
||||||
|
\'6' : '&', '7' : "'", '8' : '(', '9' : ')', '0' : '_', '-' : '=', '^' : '~', |
||||||
|
\';' : '+', ':' : '*', '[' : '{', ']' : '}', '@' : '`', '\' : '|', |
||||||
|
\} |
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4 |
@ -0,0 +1,12 @@ |
|||||||
|
function! vital#of(name) abort |
||||||
|
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital') |
||||||
|
let file = split(files, "\n") |
||||||
|
if empty(file) |
||||||
|
throw 'vital: version file not found: ' . a:name |
||||||
|
endif |
||||||
|
let ver = readfile(file[0], 'b') |
||||||
|
if empty(ver) |
||||||
|
throw 'vital: invalid version file: ' . a:name |
||||||
|
endif |
||||||
|
return vital#_{substitute(ver[0], '\W', '', 'g')}#new() |
||||||
|
endfunction |
@ -0,0 +1,319 @@ |
|||||||
|
let s:self_version = expand('<sfile>:t:r') |
||||||
|
let s:self_file = expand('<sfile>') |
||||||
|
|
||||||
|
" Note: The extra argument to globpath() was added in Patch 7.2.051. |
||||||
|
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51') |
||||||
|
|
||||||
|
let s:loaded = {} |
||||||
|
let s:cache_module_path = {} |
||||||
|
let s:cache_sid = {} |
||||||
|
|
||||||
|
let s:_vital_files_cache_runtimepath = '' |
||||||
|
let s:_vital_files_cache = [] |
||||||
|
let s:_unify_path_cache = {} |
||||||
|
|
||||||
|
function! s:import(name, ...) abort |
||||||
|
let target = {} |
||||||
|
let functions = [] |
||||||
|
for a in a:000 |
||||||
|
if type(a) == type({}) |
||||||
|
let target = a |
||||||
|
elseif type(a) == type([]) |
||||||
|
let functions = a |
||||||
|
endif |
||||||
|
unlet a |
||||||
|
endfor |
||||||
|
let module = s:_import(a:name) |
||||||
|
if empty(functions) |
||||||
|
call extend(target, module, 'keep') |
||||||
|
else |
||||||
|
for f in functions |
||||||
|
if has_key(module, f) && !has_key(target, f) |
||||||
|
let target[f] = module[f] |
||||||
|
endif |
||||||
|
endfor |
||||||
|
endif |
||||||
|
return target |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:load(...) dict abort |
||||||
|
for arg in a:000 |
||||||
|
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg] |
||||||
|
let target = split(join(as, ''), '\W\+') |
||||||
|
let dict = self |
||||||
|
let dict_type = type({}) |
||||||
|
while !empty(target) |
||||||
|
let ns = remove(target, 0) |
||||||
|
if !has_key(dict, ns) |
||||||
|
let dict[ns] = {} |
||||||
|
endif |
||||||
|
if type(dict[ns]) == dict_type |
||||||
|
let dict = dict[ns] |
||||||
|
else |
||||||
|
unlet dict |
||||||
|
break |
||||||
|
endif |
||||||
|
endwhile |
||||||
|
|
||||||
|
if exists('dict') |
||||||
|
call extend(dict, s:_import(name)) |
||||||
|
endif |
||||||
|
unlet arg |
||||||
|
endfor |
||||||
|
return self |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:unload() abort |
||||||
|
let s:loaded = {} |
||||||
|
let s:cache_sid = {} |
||||||
|
let s:cache_module_path = {} |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:exists(name) abort |
||||||
|
return s:_get_module_path(a:name) !=# '' |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:search(pattern) abort |
||||||
|
let paths = s:_vital_files(a:pattern) |
||||||
|
let modules = sort(map(paths, 's:_file2module(v:val)')) |
||||||
|
return s:_uniq(modules) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:expand_modules(entry, all) abort |
||||||
|
if type(a:entry) == type([]) |
||||||
|
let candidates = s:_concat(map(copy(a:entry), 's:search(v:val)')) |
||||||
|
if empty(candidates) |
||||||
|
throw printf('vital: Any of module %s is not found', string(a:entry)) |
||||||
|
endif |
||||||
|
if eval(join(map(copy(candidates), 'has_key(a:all, v:val)'), '+')) |
||||||
|
let modules = [] |
||||||
|
else |
||||||
|
let modules = [candidates[0]] |
||||||
|
endif |
||||||
|
else |
||||||
|
let modules = s:search(a:entry) |
||||||
|
if empty(modules) |
||||||
|
throw printf('vital: Module %s is not found', a:entry) |
||||||
|
endif |
||||||
|
endif |
||||||
|
call filter(modules, '!has_key(a:all, v:val)') |
||||||
|
for module in modules |
||||||
|
let a:all[module] = 1 |
||||||
|
endfor |
||||||
|
return modules |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_import(name) abort |
||||||
|
if type(a:name) == type(0) |
||||||
|
return s:_build_module(a:name) |
||||||
|
endif |
||||||
|
let path = s:_get_module_path(a:name) |
||||||
|
if path ==# '' |
||||||
|
throw 'vital: module not found: ' . a:name |
||||||
|
endif |
||||||
|
let sid = s:_get_sid_by_script(path) |
||||||
|
if !sid |
||||||
|
try |
||||||
|
execute 'source' fnameescape(path) |
||||||
|
catch /^Vim\%((\a\+)\)\?:E484/ |
||||||
|
throw 'vital: module not found: ' . a:name |
||||||
|
catch /^Vim\%((\a\+)\)\?:E127/ |
||||||
|
" Ignore. |
||||||
|
endtry |
||||||
|
|
||||||
|
let sid = s:_get_sid_by_script(path) |
||||||
|
endif |
||||||
|
return s:_build_module(sid) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_get_module_path(name) abort |
||||||
|
let key = a:name . '_' |
||||||
|
if has_key(s:cache_module_path, key) |
||||||
|
return s:cache_module_path[key] |
||||||
|
endif |
||||||
|
if s:_is_absolute_path(a:name) && filereadable(a:name) |
||||||
|
return a:name |
||||||
|
endif |
||||||
|
if a:name ==# '' |
||||||
|
let paths = [s:self_file] |
||||||
|
elseif a:name =~# '\v^\u\w*%(\.\u\w*)*$' |
||||||
|
let paths = s:_vital_files(a:name) |
||||||
|
else |
||||||
|
throw 'vital: Invalid module name: ' . a:name |
||||||
|
endif |
||||||
|
|
||||||
|
call filter(paths, 'filereadable(expand(v:val, 1))') |
||||||
|
let path = get(paths, 0, '') |
||||||
|
let s:cache_module_path[key] = path |
||||||
|
return path |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_get_sid_by_script(path) abort |
||||||
|
if has_key(s:cache_sid, a:path) |
||||||
|
return s:cache_sid[a:path] |
||||||
|
endif |
||||||
|
|
||||||
|
let path = s:_unify_path(a:path) |
||||||
|
for line in filter(split(s:_redir('scriptnames'), "\n"), |
||||||
|
\ 'stridx(v:val, s:self_version) > 0') |
||||||
|
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$') |
||||||
|
if !empty(list) && s:_unify_path(list[2]) ==# path |
||||||
|
let s:cache_sid[a:path] = list[1] - 0 |
||||||
|
return s:cache_sid[a:path] |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_file2module(file) abort |
||||||
|
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?') |
||||||
|
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$') |
||||||
|
return join(split(tail, '[\\/]\+'), '.') |
||||||
|
endfunction |
||||||
|
|
||||||
|
if filereadable(expand('<sfile>:r') . '.VIM') |
||||||
|
" resolve() is slow, so we cache results. |
||||||
|
" Note: On windows, vim can't expand path names from 8.3 formats. |
||||||
|
" So if getting full path via <sfile> and $HOME was set as 8.3 format, |
||||||
|
" vital load duplicated scripts. Below's :~ avoid this issue. |
||||||
|
function! s:_unify_path(path) abort |
||||||
|
if has_key(s:_unify_path_cache, a:path) |
||||||
|
return s:_unify_path_cache[a:path] |
||||||
|
endif |
||||||
|
let value = tolower(fnamemodify(resolve(fnamemodify( |
||||||
|
\ a:path, ':p')), ':~:gs?[\\/]?/?')) |
||||||
|
let s:_unify_path_cache[a:path] = value |
||||||
|
return value |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! s:_unify_path(path) abort |
||||||
|
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?')) |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
if s:globpath_third_arg |
||||||
|
function! s:_runtime_files(path) abort |
||||||
|
return split(globpath(&runtimepath, a:path, 1), "\n") |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! s:_runtime_files(path) abort |
||||||
|
return split(globpath(&runtimepath, a:path), "\n") |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
function! s:_vital_files(pattern) abort |
||||||
|
if s:_vital_files_cache_runtimepath !=# &runtimepath |
||||||
|
let path = printf('autoload/vital/%s/**/*.vim', s:self_version) |
||||||
|
let s:_vital_files_cache = s:_runtime_files(path) |
||||||
|
let mod = ':p:gs?[\\/]\+?/?' |
||||||
|
call map(s:_vital_files_cache, 'fnamemodify(v:val, mod)') |
||||||
|
let s:_vital_files_cache_runtimepath = &runtimepath |
||||||
|
endif |
||||||
|
let target = substitute(a:pattern, '\.', '/', 'g') |
||||||
|
let target = substitute(target, '\*', '[^/]*', 'g') |
||||||
|
let regexp = printf('autoload/vital/%s/%s.vim', s:self_version, target) |
||||||
|
return filter(copy(s:_vital_files_cache), 'v:val =~# regexp') |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Copy from System.Filepath |
||||||
|
if has('win16') || has('win32') || has('win64') |
||||||
|
function! s:_is_absolute_path(path) abort |
||||||
|
return a:path =~? '^[a-z]:[/\\]' |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! s:_is_absolute_path(path) abort |
||||||
|
return a:path[0] ==# '/' |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
function! s:_build_module(sid) abort |
||||||
|
if has_key(s:loaded, a:sid) |
||||||
|
return copy(s:loaded[a:sid]) |
||||||
|
endif |
||||||
|
let functions = s:_get_functions(a:sid) |
||||||
|
|
||||||
|
let prefix = '<SNR>' . a:sid . '_' |
||||||
|
let module = {} |
||||||
|
for func in functions |
||||||
|
let module[func] = function(prefix . func) |
||||||
|
endfor |
||||||
|
if has_key(module, '_vital_loaded') |
||||||
|
let V = vital#{s:self_version}#new() |
||||||
|
if has_key(module, '_vital_depends') |
||||||
|
let all = {} |
||||||
|
let modules = |
||||||
|
\ s:_concat(map(module._vital_depends(), |
||||||
|
\ 's:expand_modules(v:val, all)')) |
||||||
|
call call(V.load, modules, V) |
||||||
|
endif |
||||||
|
try |
||||||
|
call module._vital_loaded(V) |
||||||
|
catch |
||||||
|
" FIXME: Show an error message for debug. |
||||||
|
endtry |
||||||
|
endif |
||||||
|
if !get(g:, 'vital_debug', 0) |
||||||
|
call filter(module, 'v:key =~# "^\\a"') |
||||||
|
endif |
||||||
|
let s:loaded[a:sid] = module |
||||||
|
return copy(module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
if exists('+regexpengine') |
||||||
|
function! s:_get_functions(sid) abort |
||||||
|
let funcs = s:_redir(printf("function /\\%%#=2^\<SNR>%d_", a:sid)) |
||||||
|
let map_pat = '<SNR>' . a:sid . '_\zs\w\+' |
||||||
|
return map(split(funcs, "\n"), 'matchstr(v:val, map_pat)') |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! s:_get_functions(sid) abort |
||||||
|
let prefix = '<SNR>' . a:sid . '_' |
||||||
|
let funcs = s:_redir('function') |
||||||
|
let filter_pat = '^\s*function ' . prefix |
||||||
|
let map_pat = prefix . '\zs\w\+' |
||||||
|
return map(filter(split(funcs, "\n"), |
||||||
|
\ 'stridx(v:val, prefix) > 0 && v:val =~# filter_pat'), |
||||||
|
\ 'matchstr(v:val, map_pat)') |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
if exists('*uniq') |
||||||
|
function! s:_uniq(list) abort |
||||||
|
return uniq(a:list) |
||||||
|
endfunction |
||||||
|
else |
||||||
|
function! s:_uniq(list) abort |
||||||
|
let i = len(a:list) - 1 |
||||||
|
while 0 < i |
||||||
|
if a:list[i] ==# a:list[i - 1] |
||||||
|
call remove(a:list, i) |
||||||
|
let i -= 2 |
||||||
|
else |
||||||
|
let i -= 1 |
||||||
|
endif |
||||||
|
endwhile |
||||||
|
return a:list |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
function! s:_concat(lists) abort |
||||||
|
let result_list = [] |
||||||
|
for list in a:lists |
||||||
|
let result_list += list |
||||||
|
endfor |
||||||
|
return result_list |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_redir(cmd) abort |
||||||
|
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile] |
||||||
|
set verbose=0 verbosefile= |
||||||
|
redir => res |
||||||
|
silent! execute a:cmd |
||||||
|
redir END |
||||||
|
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile] |
||||||
|
return res |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! vital#{s:self_version}#new() abort |
||||||
|
return s:_import('') |
||||||
|
endfunction |
@ -0,0 +1,442 @@ |
|||||||
|
" Utilities for list. |
||||||
|
|
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
function! s:pop(list) abort |
||||||
|
return remove(a:list, -1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:push(list, val) abort |
||||||
|
call add(a:list, a:val) |
||||||
|
return a:list |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:shift(list) abort |
||||||
|
return remove(a:list, 0) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:unshift(list, val) abort |
||||||
|
return insert(a:list, a:val) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:cons(x, xs) abort |
||||||
|
return [a:x] + a:xs |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:conj(xs, x) abort |
||||||
|
return a:xs + [a:x] |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Removes duplicates from a list. |
||||||
|
function! s:uniq(list) abort |
||||||
|
return s:uniq_by(a:list, 'v:val') |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Removes duplicates from a list. |
||||||
|
function! s:uniq_by(list, f) abort |
||||||
|
let list = map(copy(a:list), printf('[v:val, %s]', a:f)) |
||||||
|
let i = 0 |
||||||
|
let seen = {} |
||||||
|
while i < len(list) |
||||||
|
let key = string(list[i][1]) |
||||||
|
if has_key(seen, key) |
||||||
|
call remove(list, i) |
||||||
|
else |
||||||
|
let seen[key] = 1 |
||||||
|
let i += 1 |
||||||
|
endif |
||||||
|
endwhile |
||||||
|
return map(list, 'v:val[0]') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:clear(list) abort |
||||||
|
if !empty(a:list) |
||||||
|
unlet! a:list[0 : len(a:list) - 1] |
||||||
|
endif |
||||||
|
return a:list |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Concatenates a list of lists. |
||||||
|
" XXX: Should we verify the input? |
||||||
|
function! s:concat(list) abort |
||||||
|
let memo = [] |
||||||
|
for Value in a:list |
||||||
|
let memo += Value |
||||||
|
endfor |
||||||
|
return memo |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Take each elements from lists to a new list. |
||||||
|
function! s:flatten(list, ...) abort |
||||||
|
let limit = a:0 > 0 ? a:1 : -1 |
||||||
|
let memo = [] |
||||||
|
if limit == 0 |
||||||
|
return a:list |
||||||
|
endif |
||||||
|
let limit -= 1 |
||||||
|
for Value in a:list |
||||||
|
let memo += |
||||||
|
\ type(Value) == type([]) ? |
||||||
|
\ s:flatten(Value, limit) : |
||||||
|
\ [Value] |
||||||
|
unlet! Value |
||||||
|
endfor |
||||||
|
return memo |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Sorts a list with expression to compare each two values. |
||||||
|
" a:a and a:b can be used in {expr}. |
||||||
|
function! s:sort(list, expr) abort |
||||||
|
if type(a:expr) == type(function('function')) |
||||||
|
return sort(a:list, a:expr) |
||||||
|
endif |
||||||
|
let s:expr = a:expr |
||||||
|
return sort(a:list, 's:_compare') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_compare(a, b) abort |
||||||
|
return eval(s:expr) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Sorts a list using a set of keys generated by mapping the values in the list |
||||||
|
" through the given expr. |
||||||
|
" v:val is used in {expr} |
||||||
|
function! s:sort_by(list, expr) abort |
||||||
|
let pairs = map(a:list, printf('[v:val, %s]', a:expr)) |
||||||
|
return map(s:sort(pairs, |
||||||
|
\ 'a:a[1] ==# a:b[1] ? 0 : a:a[1] ># a:b[1] ? 1 : -1'), 'v:val[0]') |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns a maximum value in {list} through given {expr}. |
||||||
|
" Returns 0 if {list} is empty. |
||||||
|
" v:val is used in {expr} |
||||||
|
function! s:max_by(list, expr) abort |
||||||
|
if empty(a:list) |
||||||
|
return 0 |
||||||
|
endif |
||||||
|
let list = map(copy(a:list), a:expr) |
||||||
|
return a:list[index(list, max(list))] |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns a minimum value in {list} through given {expr}. |
||||||
|
" Returns 0 if {list} is empty. |
||||||
|
" v:val is used in {expr} |
||||||
|
" FIXME: -0x80000000 == 0x80000000 |
||||||
|
function! s:min_by(list, expr) abort |
||||||
|
return s:max_by(a:list, '-(' . a:expr . ')') |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns List of character sequence between [a:from, a:to] |
||||||
|
" e.g.: s:char_range('a', 'c') returns ['a', 'b', 'c'] |
||||||
|
function! s:char_range(from, to) abort |
||||||
|
return map( |
||||||
|
\ range(char2nr(a:from), char2nr(a:to)), |
||||||
|
\ 'nr2char(v:val)' |
||||||
|
\) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns true if a:list has a:value. |
||||||
|
" Returns false otherwise. |
||||||
|
function! s:has(list, value) abort |
||||||
|
return index(a:list, a:value) isnot -1 |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns true if a:list[a:index] exists. |
||||||
|
" Returns false otherwise. |
||||||
|
" NOTE: Returns false when a:index is negative number. |
||||||
|
function! s:has_index(list, index) abort |
||||||
|
" Return true when negative index? |
||||||
|
" let index = a:index >= 0 ? a:index : len(a:list) + a:index |
||||||
|
return 0 <= a:index && a:index < len(a:list) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Data.List.span |
||||||
|
function! s:span(f, xs) abort |
||||||
|
let border = len(a:xs) |
||||||
|
for i in range(len(a:xs)) |
||||||
|
if !eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) |
||||||
|
let border = i |
||||||
|
break |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return border == 0 ? [[], copy(a:xs)] : [a:xs[: border - 1], a:xs[border :]] |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Data.List.break |
||||||
|
function! s:break(f, xs) abort |
||||||
|
return s:span(printf('!(%s)', a:f), a:xs) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Data.List.takeWhile |
||||||
|
function! s:take_while(f, xs) abort |
||||||
|
return s:span(a:f, a:xs)[0] |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Data.List.partition |
||||||
|
function! s:partition(f, xs) abort |
||||||
|
return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')] |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.all |
||||||
|
function! s:all(f, xs) abort |
||||||
|
return !s:any(printf('!(%s)', a:f), a:xs) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.any |
||||||
|
function! s:any(f, xs) abort |
||||||
|
return !empty(filter(map(copy(a:xs), a:f), 'v:val')) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.and |
||||||
|
function! s:and(xs) abort |
||||||
|
return s:all('v:val', a:xs) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.or |
||||||
|
function! s:or(xs) abort |
||||||
|
return s:any('v:val', a:xs) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:map_accum(expr, xs, init) abort |
||||||
|
let memo = [] |
||||||
|
let init = a:init |
||||||
|
for x in a:xs |
||||||
|
let expr = substitute(a:expr, 'v:memo', init, 'g') |
||||||
|
let expr = substitute(expr, 'v:val', x, 'g') |
||||||
|
let [tmp, init] = eval(expr) |
||||||
|
call add(memo, tmp) |
||||||
|
endfor |
||||||
|
return memo |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.foldl |
||||||
|
function! s:foldl(f, init, xs) abort |
||||||
|
let memo = a:init |
||||||
|
for x in a:xs |
||||||
|
let expr = substitute(a:f, 'v:val', string(x), 'g') |
||||||
|
let expr = substitute(expr, 'v:memo', string(memo), 'g') |
||||||
|
unlet memo |
||||||
|
let memo = eval(expr) |
||||||
|
endfor |
||||||
|
return memo |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.foldl1 |
||||||
|
function! s:foldl1(f, xs) abort |
||||||
|
if len(a:xs) == 0 |
||||||
|
throw 'foldl1' |
||||||
|
endif |
||||||
|
return s:foldl(a:f, a:xs[0], a:xs[1:]) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.foldr |
||||||
|
function! s:foldr(f, init, xs) abort |
||||||
|
return s:foldl(a:f, a:init, reverse(copy(a:xs))) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Haskell's Prelude.fold11 |
||||||
|
function! s:foldr1(f, xs) abort |
||||||
|
if len(a:xs) == 0 |
||||||
|
throw 'foldr1' |
||||||
|
endif |
||||||
|
return s:foldr(a:f, a:xs[-1], a:xs[0:-2]) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to python's zip() |
||||||
|
function! s:zip(...) abort |
||||||
|
return map(range(min(map(copy(a:000), 'len(v:val)'))), "map(copy(a:000), 'v:val['.v:val.']')") |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to zip(), but goes until the longer one. |
||||||
|
function! s:zip_fill(xs, ys, filler) abort |
||||||
|
if empty(a:xs) && empty(a:ys) |
||||||
|
return [] |
||||||
|
elseif empty(a:ys) |
||||||
|
return s:cons([a:xs[0], a:filler], s:zip_fill(a:xs[1 :], [], a:filler)) |
||||||
|
elseif empty(a:xs) |
||||||
|
return s:cons([a:filler, a:ys[0]], s:zip_fill([], a:ys[1 :], a:filler)) |
||||||
|
else |
||||||
|
return s:cons([a:xs[0], a:ys[0]], s:zip_fill(a:xs[1 :], a:ys[1: ], a:filler)) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Inspired by Ruby's with_index method. |
||||||
|
function! s:with_index(list, ...) abort |
||||||
|
let base = a:0 > 0 ? a:1 : 0 |
||||||
|
return s:zip(a:list, range(base, len(a:list)+base-1)) |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Ruby's detect or Haskell's find. |
||||||
|
function! s:find(list, default, f) abort |
||||||
|
for x in a:list |
||||||
|
if eval(substitute(a:f, 'v:val', string(x), 'g')) |
||||||
|
return x |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return a:default |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns the index of the first element which satisfies the given expr. |
||||||
|
function! s:find_index(xs, f, ...) abort |
||||||
|
let len = len(a:xs) |
||||||
|
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0 |
||||||
|
let default = a:0 > 1 ? a:2 : -1 |
||||||
|
if start >=# len || start < 0 |
||||||
|
return default |
||||||
|
endif |
||||||
|
for i in range(start, len - 1) |
||||||
|
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) |
||||||
|
return i |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return default |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Returns the index of the last element which satisfies the given expr. |
||||||
|
function! s:find_last_index(xs, f, ...) abort |
||||||
|
let len = len(a:xs) |
||||||
|
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : len - 1 |
||||||
|
let default = a:0 > 1 ? a:2 : -1 |
||||||
|
if start >=# len || start < 0 |
||||||
|
return default |
||||||
|
endif |
||||||
|
for i in range(start, 0, -1) |
||||||
|
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) |
||||||
|
return i |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return default |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Similar to find_index but returns the list of indices satisfying the given expr. |
||||||
|
function! s:find_indices(xs, f, ...) abort |
||||||
|
let len = len(a:xs) |
||||||
|
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0 |
||||||
|
let result = [] |
||||||
|
if start >=# len || start < 0 |
||||||
|
return result |
||||||
|
endif |
||||||
|
for i in range(start, len - 1) |
||||||
|
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) |
||||||
|
call add(result, i) |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
" Return non-zero if a:list1 and a:list2 have any common item(s). |
||||||
|
" Return zero otherwise. |
||||||
|
function! s:has_common_items(list1, list2) abort |
||||||
|
return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1')) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:intersect(list1, list2) abort |
||||||
|
let items = [] |
||||||
|
" for funcref |
||||||
|
for X in a:list1 |
||||||
|
if index(a:list2, X) != -1 && index(items, X) == -1 |
||||||
|
let items += [X] |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return items |
||||||
|
endfunction |
||||||
|
|
||||||
|
" similar to Ruby's group_by. |
||||||
|
function! s:group_by(xs, f) abort |
||||||
|
let result = {} |
||||||
|
let list = map(copy(a:xs), printf('[v:val, %s]', a:f)) |
||||||
|
for x in list |
||||||
|
let Val = x[0] |
||||||
|
let key = type(x[1]) !=# type('') ? string(x[1]) : x[1] |
||||||
|
if has_key(result, key) |
||||||
|
call add(result[key], Val) |
||||||
|
else |
||||||
|
let result[key] = [Val] |
||||||
|
endif |
||||||
|
unlet Val |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_default_compare(a, b) abort |
||||||
|
return a:a <# a:b ? -1 : a:a ># a:b ? 1 : 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:binary_search(list, value, ...) abort |
||||||
|
let Predicate = a:0 >= 1 ? a:1 : 's:_default_compare' |
||||||
|
let dic = a:0 >= 2 ? a:2 : {} |
||||||
|
let start = 0 |
||||||
|
let end = len(a:list) - 1 |
||||||
|
|
||||||
|
while 1 |
||||||
|
if start > end |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
|
||||||
|
let middle = (start + end) / 2 |
||||||
|
|
||||||
|
let compared = call(Predicate, [a:value, a:list[middle]], dic) |
||||||
|
|
||||||
|
if compared < 0 |
||||||
|
let end = middle - 1 |
||||||
|
elseif compared > 0 |
||||||
|
let start = middle + 1 |
||||||
|
else |
||||||
|
return middle |
||||||
|
endif |
||||||
|
endwhile |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:product(lists) abort |
||||||
|
let result = [[]] |
||||||
|
for pool in a:lists |
||||||
|
let tmp = [] |
||||||
|
for x in result |
||||||
|
let tmp += map(copy(pool), 'x + [v:val]') |
||||||
|
endfor |
||||||
|
let result = tmp |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:permutations(list, ...) abort |
||||||
|
if a:0 > 1 |
||||||
|
throw 'vital: Data.List: too many arguments' |
||||||
|
endif |
||||||
|
let r = a:0 == 1 ? a:1 : len(a:list) |
||||||
|
if r > len(a:list) |
||||||
|
return [] |
||||||
|
elseif r < 0 |
||||||
|
throw 'vital: Data.List: {r} must be non-negative integer' |
||||||
|
endif |
||||||
|
let n = len(a:list) |
||||||
|
let result = [] |
||||||
|
for indices in s:product(map(range(r), 'range(n)')) |
||||||
|
if len(s:uniq(indices)) == r |
||||||
|
call add(result, map(indices, 'a:list[v:val]')) |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:combinations(list, r) abort |
||||||
|
if a:r > len(a:list) |
||||||
|
return [] |
||||||
|
elseif a:r < 0 |
||||||
|
throw 'vital: Data:List: {r} must be non-negative integer' |
||||||
|
endif |
||||||
|
let n = len(a:list) |
||||||
|
let result = [] |
||||||
|
for indices in s:permutations(range(n), a:r) |
||||||
|
if s:sort(copy(indices), 'a:a - a:b') == indices |
||||||
|
call add(result, map(indices, 'a:list[v:val]')) |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
|
||||||
|
" vim:set et ts=2 sts=2 sw=2 tw=0: |
@ -0,0 +1,591 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:String = s:V.import("Over.String") |
||||||
|
let s:Signals = s:V.import("Over.Signals") |
||||||
|
let s:Input = s:V.import("Over.Input") |
||||||
|
let s:Keymapping = s:V.import("Over.Keymapping") |
||||||
|
let s:Module = s:V.import("Over.Commandline.Modules") |
||||||
|
let s:base.variables.modules = s:Signals.make() |
||||||
|
function! s:base.variables.modules.get_slot(val) |
||||||
|
return a:val.slot.module |
||||||
|
endfunction |
||||||
|
|
||||||
|
let s:Highlight = s:V.import("Palette.Highlight") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Over.String", |
||||||
|
\ "Over.Signals", |
||||||
|
\ "Over.Input", |
||||||
|
\ "Over.Keymapping", |
||||||
|
\ "Over.Commandline.Modules", |
||||||
|
\ "Palette.Highlight", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(...) |
||||||
|
let result = deepcopy(s:base) |
||||||
|
call result.set_prompt(get(a:, 1, ":")) |
||||||
|
call result.connect(result, "_") |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make_plain() |
||||||
|
return deepcopy(s:base) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:base = { |
||||||
|
\ "line" : {}, |
||||||
|
\ "variables" : { |
||||||
|
\ "prompt" : "", |
||||||
|
\ "char" : "", |
||||||
|
\ "input" : "", |
||||||
|
\ "tap_key" : "", |
||||||
|
\ "exit" : 0, |
||||||
|
\ "keymapping" : {}, |
||||||
|
\ "suffix" : "", |
||||||
|
\ "is_setted" : 0, |
||||||
|
\ }, |
||||||
|
\ "highlights" : { |
||||||
|
\ "prompt" : "NONE", |
||||||
|
\ "cursor" : "VitalOverCommandLineCursor", |
||||||
|
\ "cursor_on" : "VitalOverCommandLineCursorOn", |
||||||
|
\ "cursor_insert" : "VitalOverCommandLineOnCursor", |
||||||
|
\ }, |
||||||
|
\} |
||||||
|
|
||||||
|
if exists("s:Signals") |
||||||
|
let s:base.variables.modules = s:Signals.make() |
||||||
|
function! s:base.variables.modules.get_slot(val) |
||||||
|
return a:val.slot.module |
||||||
|
endfunction |
||||||
|
endif |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.getline() |
||||||
|
return self.line.str() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.setline(line) |
||||||
|
return self.line.set(a:line) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.char() |
||||||
|
return self.variables.char |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.setchar(char, ...) |
||||||
|
" 1 の場合は既に設定されていても上書きする |
||||||
|
" 0 の場合は既に設定されていれば上書きしない |
||||||
|
let overwrite = get(a:, 1, 1) |
||||||
|
if overwrite || self.variables.is_setted == 0 |
||||||
|
let self.variables.input = a:char |
||||||
|
let self.variables.is_setted = 1 |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.getpos() |
||||||
|
return self.line.pos() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.setpos(pos) |
||||||
|
return self.line.set_pos(a:pos) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.tap_keyinput(key) |
||||||
|
let self.variables.tap_key = a:key |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.untap_keyinput(key) |
||||||
|
if self.variables.tap_key == a:key |
||||||
|
let self.variables.tap_key = "" |
||||||
|
return 1 |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get_tap_key() |
||||||
|
return self.variables.tap_key |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.is_input(key, ...) |
||||||
|
let prekey = get(a:, 1, "") |
||||||
|
return self.get_tap_key() ==# prekey |
||||||
|
\ && self.char() ==# a:key |
||||||
|
" \ && self.char() == (prekey . a:key) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.input_key() |
||||||
|
return self.variables.input_key |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.set_prompt(prompt) |
||||||
|
let self.variables.prompt = a:prompt |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get_prompt() |
||||||
|
return self.variables.prompt |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.set_suffix(str) |
||||||
|
let self.variables.suffix = a:str |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get_suffix() |
||||||
|
return self.variables.suffix |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.insert(word, ...) |
||||||
|
if a:0 |
||||||
|
call self.line.set(a:1) |
||||||
|
endif |
||||||
|
call self.line.input(a:word) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.forward() |
||||||
|
return self.line.forward() |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.backward() |
||||||
|
return self.line.backward() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.backward_word(...) |
||||||
|
let pat = get(a:, 1, '\k\+\s*\|.') |
||||||
|
return matchstr(self.backward(), '\%(' . pat . '\)$') |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.connect(module, ...) |
||||||
|
if type(a:module) == type("") |
||||||
|
return call(self.connect, [s:Module.make(a:module)] + a:000, self) |
||||||
|
endif |
||||||
|
if empty(a:module) |
||||||
|
return |
||||||
|
endif |
||||||
|
let name = a:0 > 0 ? a:1 : a:module.name |
||||||
|
let slot = self.variables.modules.find_first_by("get(v:val.slot, 'name', '') == " . string(name)) |
||||||
|
if empty(slot) |
||||||
|
call self.variables.modules.connect({ "name" : name, "module" : a:module }) |
||||||
|
else |
||||||
|
let slot.slot.module = a:module |
||||||
|
endif |
||||||
|
" let self.variables.modules[name] = a:module |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.disconnect(name) |
||||||
|
return self.variables.modules.disconnect_by( |
||||||
|
\ "get(v:val.slot, 'name', '') == " . string(a:name) |
||||||
|
\ ) |
||||||
|
" unlet self.variables.modules[a:name] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get_module(name) |
||||||
|
let slot = self.variables.modules.find_first_by("get(v:val.slot, 'name', '') == " . string(a:name)) |
||||||
|
return empty(slot) ? {} : slot.slot.module |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.callevent(event) |
||||||
|
call self.variables.modules.sort_by("has_key(v:val.slot.module, 'priority') ? v:val.slot.module.priority('" . a:event . "') : 0") |
||||||
|
return self.variables.modules.call(a:event, [self]) |
||||||
|
" call map(filter(copy(self.variables.modules), "has_key(v:val, a:event)"), "v:val." . a:event . "(self)") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.cmap(lhs, rhs) |
||||||
|
let self.variables.keymapping[a:lhs] = a:rhs |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.cnoremap(lhs, rhs) |
||||||
|
let key = s:Keymapping.as_key_config(a:rhs) |
||||||
|
let key.noremap = 1 |
||||||
|
let self.variables.keymapping[a:lhs] = key |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.cunmap(lhs) |
||||||
|
unlet self.variables.keymapping[a:lhs] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.keymapping() |
||||||
|
return self.__keymapping__() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__keymapping__() |
||||||
|
return {} |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.execute(...) |
||||||
|
let command = get(a:, 1, self.getline()) |
||||||
|
call self.__execute(command) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.draw() |
||||||
|
call self.callevent("on_draw_pre") |
||||||
|
call self.callevent("on_draw") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.exit(...) |
||||||
|
let self.variables.exit = 1 |
||||||
|
let self.variables.exit_code = get(a:, 1, 0) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.enable_keymapping() |
||||||
|
let self.variables.enable_keymapping = 1 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.disable_keymapping() |
||||||
|
let self.variables.enable_keymapping = 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.is_enable_keymapping() |
||||||
|
return self.variables.enable_keymapping |
||||||
|
endfunction |
||||||
|
|
||||||
|
" function! s:base.cancel() |
||||||
|
" call self.exit(1) |
||||||
|
" call self.__on_cancel() |
||||||
|
" endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.exit_code() |
||||||
|
return self.variables.exit_code |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.hl_cursor_on() |
||||||
|
if exists("self.variables.old_guicursor") |
||||||
|
set guicursor& |
||||||
|
let &guicursor = self.variables.old_guicursor |
||||||
|
unlet self.variables.old_guicursor |
||||||
|
endif |
||||||
|
|
||||||
|
if exists("self.variables.old_t_ve") |
||||||
|
let &t_ve = self.variables.old_t_ve |
||||||
|
unlet self.variables.old_t_ve |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.hl_cursor_off() |
||||||
|
if exists("self.variables.old_t_ve") |
||||||
|
return |
||||||
|
endif |
||||||
|
|
||||||
|
let self.variables.old_guicursor = &guicursor |
||||||
|
set guicursor=n:block-NONE |
||||||
|
let self.variables.old_t_ve = &t_ve |
||||||
|
set t_ve= |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.start(...) |
||||||
|
let exit_code = call(self.__main, a:000, self) |
||||||
|
return exit_code |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__empty(...) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get(...) |
||||||
|
let Old_execute = self.execute |
||||||
|
let self.execute = self.__empty |
||||||
|
try |
||||||
|
let exit_code = call(self.start, a:000, self) |
||||||
|
if exit_code == 0 |
||||||
|
return self.getline() |
||||||
|
endif |
||||||
|
finally |
||||||
|
let self.execute = Old_execute |
||||||
|
endtry |
||||||
|
return "" |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.input_key_stack() |
||||||
|
return self.variables.input_key_stack |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.input_key_stack_string() |
||||||
|
return join(self.variables.input_key_stack, "") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.set_input_key_stack(stack) |
||||||
|
let self.variables.input_key_stack = a:stack |
||||||
|
return self.variables.input_key_stack |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.input_key_stack_pop() |
||||||
|
return remove(self.input_key_stack(), 0) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.getchar(...) |
||||||
|
if empty(self.input_key_stack()) |
||||||
|
return call(s:Input.getchar, a:000, s:Input) |
||||||
|
endif |
||||||
|
return self.input_key_stack_pop() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__init_variables() |
||||||
|
let self.variables.tap_key = "" |
||||||
|
let self.variables.char = "" |
||||||
|
let self.variables.input = "" |
||||||
|
let self.variables.exit = 0 |
||||||
|
let self.variables.exit_code = 1 |
||||||
|
let self.variables.enable_keymapping = 1 |
||||||
|
let self.variables.input_key_stack = [] |
||||||
|
let self.line = deepcopy(s:String.make()) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_is_valid_highlight(name) |
||||||
|
let highlight = s:Highlight.get(a:name) |
||||||
|
if empty(highlight) |
||||||
|
return 0 |
||||||
|
endif |
||||||
|
|
||||||
|
if has("gui_running") |
||||||
|
\ && (has_key(highlight, "guifg") || has_key(highlight, "guibg")) |
||||||
|
return 1 |
||||||
|
elseif (has_key(highlight, "ctermfg") || has_key(highlight, "ctermbg")) |
||||||
|
return 1 |
||||||
|
endif |
||||||
|
return 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__init() |
||||||
|
call self.__init_variables() |
||||||
|
call self.hl_cursor_off() |
||||||
|
if !hlexists(self.highlights.cursor) |
||||||
|
if s:_is_valid_highlight("Cursor") |
||||||
|
execute "highlight link " . self.highlights.cursor . " Cursor" |
||||||
|
else |
||||||
|
" Workaround by CUI Vim Cursor Highlight |
||||||
|
" issues #92 |
||||||
|
" https://github.com/osyo-manga/vital-over/issues/92 |
||||||
|
execute "highlight " . self.highlights.cursor . " term=reverse cterm=reverse gui=reverse" |
||||||
|
endif |
||||||
|
endif |
||||||
|
if !hlexists(self.highlights.cursor_on) |
||||||
|
execute "highlight link " . self.highlights.cursor_on . " " . self.highlights.cursor |
||||||
|
endif |
||||||
|
if !hlexists(self.highlights.cursor_insert) |
||||||
|
execute "highlight " . self.highlights.cursor_insert . " cterm=underline term=underline gui=underline" |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__execute(command) |
||||||
|
call self.callevent("on_execute_pre") |
||||||
|
try |
||||||
|
call self.__execute__(a:command) |
||||||
|
catch |
||||||
|
echohl ErrorMsg |
||||||
|
echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze') |
||||||
|
echohl None |
||||||
|
call self.callevent("on_execute_failed") |
||||||
|
finally |
||||||
|
call self.callevent("on_execute") |
||||||
|
endtry |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__execute__(cmd) |
||||||
|
execute a:cmd |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__input_char(char) |
||||||
|
let char = a:char |
||||||
|
let self.variables.input_key = char |
||||||
|
let self.variables.char = char |
||||||
|
call self.setchar(self.variables.char) |
||||||
|
let self.variables.is_setted = 0 |
||||||
|
call self.callevent("on_char_pre") |
||||||
|
call self.insert(self.variables.input) |
||||||
|
call self.callevent("on_char") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__input(input, ...) |
||||||
|
if a:input == "" |
||||||
|
return |
||||||
|
endif |
||||||
|
|
||||||
|
let self.variables.input_key = a:input |
||||||
|
if a:0 == 0 |
||||||
|
let keymapping = self.__get_keymapping() |
||||||
|
else |
||||||
|
let keymapping = a:1 |
||||||
|
endif |
||||||
|
if self.is_enable_keymapping() |
||||||
|
let key = s:Keymapping.unmapping(keymapping, a:input) |
||||||
|
else |
||||||
|
let key = a:input |
||||||
|
endif |
||||||
|
if key == "" |
||||||
|
return |
||||||
|
endif |
||||||
|
|
||||||
|
call self.set_input_key_stack(s:String.split_by_keys(key)) |
||||||
|
while !(empty(self.input_key_stack()) || self.is_exit()) |
||||||
|
call self.__input_char(self.input_key_stack_pop()) |
||||||
|
endwhile |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:is_input_waiting(keymapping, input) |
||||||
|
let num = len(filter(copy(a:keymapping), 'stridx(v:key, a:input) == 0')) |
||||||
|
return num > 1 || (num == 1 && !has_key(a:keymapping, a:input)) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__inputting() |
||||||
|
if !self.is_enable_keymapping() |
||||||
|
return self.__input(s:Input.getchar()) |
||||||
|
endif |
||||||
|
|
||||||
|
let input = s:Input.getchar() |
||||||
|
let old_line = self.getline() |
||||||
|
let old_pos = self.getpos() |
||||||
|
let keymapping = self.__get_keymapping() |
||||||
|
try |
||||||
|
let t = reltime() |
||||||
|
while s:is_input_waiting(keymapping, input) |
||||||
|
\ && str2nr(reltimestr(reltime(t))) * 1000 < &timeoutlen |
||||||
|
call self.setline(old_line) |
||||||
|
call self.insert(input) |
||||||
|
call self.setpos(old_pos) |
||||||
|
call self.draw() |
||||||
|
let input .= s:Input.getchar(0) |
||||||
|
endwhile |
||||||
|
finally |
||||||
|
call self.setline(old_line) |
||||||
|
call self.setpos(old_pos) |
||||||
|
endtry |
||||||
|
call self.__input(input, keymapping) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__update() |
||||||
|
" call self.callevent("on_update") |
||||||
|
" if !getchar(1) |
||||||
|
" continue |
||||||
|
" endif |
||||||
|
" |
||||||
|
" call self.__input(s:getchar(0)) |
||||||
|
" call self.draw() |
||||||
|
|
||||||
|
call self.callevent("on_update") |
||||||
|
call self.__inputting() |
||||||
|
" call self.__input(s:Input.getchar()) |
||||||
|
if self.is_exit() |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
call self.draw() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__main(...) |
||||||
|
try |
||||||
|
call self.__init() |
||||||
|
call self.callevent("on_enter") |
||||||
|
|
||||||
|
call self.__input(get(a:, 1, "")) |
||||||
|
call self.draw() |
||||||
|
while !self.is_exit() |
||||||
|
try |
||||||
|
if self.__update() |
||||||
|
break |
||||||
|
endif |
||||||
|
catch |
||||||
|
call self.callevent("on_exception") |
||||||
|
endtry |
||||||
|
endwhile |
||||||
|
catch |
||||||
|
echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None |
||||||
|
let self.variables.exit_code = -1 |
||||||
|
finally |
||||||
|
call self.__finish() |
||||||
|
call self.callevent("on_leave") |
||||||
|
endtry |
||||||
|
return self.exit_code() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__finish() |
||||||
|
call self.hl_cursor_on() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__is_exit() |
||||||
|
return self.is_exit() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.is_exit() |
||||||
|
return self.variables.exit |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.__get_keymapping() |
||||||
|
let result = {} |
||||||
|
" for module in values(self.variables.modules) |
||||||
|
for module in self.variables.modules.slots() |
||||||
|
if has_key(module, "keymapping") |
||||||
|
if module isnot self |
||||||
|
call extend(result, module.keymapping(self)) |
||||||
|
endif |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return extend(extend(result, self.variables.keymapping), self.keymapping()) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,27 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:get(name) |
||||||
|
if exists("s:" . a:name) |
||||||
|
return s:{a:name} |
||||||
|
endif |
||||||
|
let s:{a:name} = s:V.import('Over.Commandline.Modules.' . a:name) |
||||||
|
return s:{a:name} |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(name, ...) |
||||||
|
let module = s:get(a:name) |
||||||
|
return call(module.make, a:000, module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,164 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_uniq(list) |
||||||
|
let dict = {} |
||||||
|
for _ in a:list |
||||||
|
let dict[_] = 0 |
||||||
|
endfor |
||||||
|
return keys(dict) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "BufferComplete", |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:_buffer_complete() |
||||||
|
return sort(s:_uniq(filter(split(join(getline(1, '$')), '\W'), '!empty(v:val)')), 1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_parse_line(line) |
||||||
|
let keyword = matchstr(a:line, '\zs\w\+\ze$') |
||||||
|
let pos = strchars(a:line) - strchars(keyword) |
||||||
|
return [pos, keyword] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_as_statusline(list, count) |
||||||
|
if empty(a:list) |
||||||
|
return |
||||||
|
endif |
||||||
|
let hl_none = "%#StatusLine#" |
||||||
|
let hl_select = "%#StatusLineNC#" |
||||||
|
let tail = " > " |
||||||
|
let result = a:list[0] |
||||||
|
let pos = 0 |
||||||
|
for i in range(1, len(a:list)-1) |
||||||
|
if strdisplaywidth(result . " " . a:list[i]) > &columns - len(tail) |
||||||
|
if a:count < i |
||||||
|
break |
||||||
|
else |
||||||
|
let pos = -i |
||||||
|
endif |
||||||
|
let result = a:list[i] |
||||||
|
else |
||||||
|
let result .= (" " . a:list[i]) |
||||||
|
endif |
||||||
|
if a:count == i |
||||||
|
let pos = pos + i |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return join(map(split(result, " "), 'v:key == pos ? hl_select . v:val . hl_none : v:val')) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.get_complete_words() |
||||||
|
return s:_buffer_complete() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.complete(cmdline) |
||||||
|
call s:_finish() |
||||||
|
let s:old_statusline = &statusline |
||||||
|
|
||||||
|
let backward = a:cmdline.backward() |
||||||
|
let [pos, keyword] = s:_parse_line(backward) |
||||||
|
|
||||||
|
if !exists("s:complete") |
||||||
|
let s:complete = self.get_complete_words() |
||||||
|
endif |
||||||
|
let s:complete_list = filter(copy(s:complete), 'v:val =~ ''^''.keyword') |
||||||
|
if empty(s:complete_list) |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
|
||||||
|
if pos == 0 |
||||||
|
let backward = "" |
||||||
|
else |
||||||
|
let backward = join(split(backward, '\zs')[ : pos-1 ], "") |
||||||
|
endif |
||||||
|
let s:line = backward . a:cmdline.forward() |
||||||
|
let s:pos = pos |
||||||
|
call a:cmdline.setline(s:line) |
||||||
|
|
||||||
|
let s:count = 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_finish() |
||||||
|
if exists("s:old_statusline") |
||||||
|
let &statusline = s:old_statusline |
||||||
|
unlet s:old_statusline |
||||||
|
redrawstatus |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("<Over>(buffer-complete)") |
||||||
|
\ || a:cmdline.is_input("<Over>(buffer-complete-prev)") |
||||||
|
if self.complete(a:cmdline) == -1 |
||||||
|
call s:_finish() |
||||||
|
call a:cmdline.setchar('') |
||||||
|
return |
||||||
|
endif |
||||||
|
if a:cmdline.is_input("<Over>(buffer-complete-prev)") |
||||||
|
let s:count = len(s:complete_list) - 1 |
||||||
|
endif |
||||||
|
call a:cmdline.setchar('') |
||||||
|
call a:cmdline.tap_keyinput("Completion") |
||||||
|
" elseif a:cmdline.is_input("\<Tab>", "Completion") |
||||||
|
elseif a:cmdline.is_input("<Over>(buffer-complete)", "Completion") |
||||||
|
\ || a:cmdline.is_input("\<Right>", "Completion") |
||||||
|
call a:cmdline.setchar('') |
||||||
|
let s:count += 1 |
||||||
|
if s:count >= len(s:complete_list) |
||||||
|
let s:count = 0 |
||||||
|
endif |
||||||
|
elseif a:cmdline.is_input("<Over>(buffer-complete-prev)", "Completion") |
||||||
|
\ || a:cmdline.is_input("\<Left>", "Completion") |
||||||
|
call a:cmdline.setchar('') |
||||||
|
let s:count -= 1 |
||||||
|
if s:count < 0 |
||||||
|
let s:count = len(s:complete_list) - 1 |
||||||
|
endif |
||||||
|
else |
||||||
|
if a:cmdline.untap_keyinput("Completion") |
||||||
|
call a:cmdline.callevent("on_char_pre") |
||||||
|
endif |
||||||
|
call s:_finish() |
||||||
|
return |
||||||
|
endif |
||||||
|
call a:cmdline.setline(s:line) |
||||||
|
call a:cmdline.insert(s:complete_list[s:count], s:pos) |
||||||
|
if len(s:complete_list) > 1 |
||||||
|
let &statusline = s:_as_statusline(s:complete_list, s:count) |
||||||
|
redrawstatus |
||||||
|
endif |
||||||
|
if len(s:complete_list) == 1 |
||||||
|
call a:cmdline.untap_keyinput("Completion") |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_draw_pre(...) |
||||||
|
" redrawstatus |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_leave(cmdline) |
||||||
|
call s:_finish() |
||||||
|
unlet! s:complete |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,25 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Cancel" |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("\<Esc>") |
||||||
|
\ || a:cmdline.is_input("\<C-c>") |
||||||
|
" call a:cmdline.cancel() |
||||||
|
call a:cmdline.exit(1) |
||||||
|
call a:cmdline.setchar("") |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,43 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "CursorMove" |
||||||
|
\} |
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("\<Right>") |
||||||
|
call a:cmdline.line.next() |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<Left>") |
||||||
|
call a:cmdline.line.prev() |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-b>") |
||||||
|
\ || a:cmdline.is_input("\<Home>") |
||||||
|
call a:cmdline.setline(0) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-e>") |
||||||
|
\ || a:cmdline.is_input("\<End>") |
||||||
|
call a:cmdline.setline(a:cmdline.line.length()) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-Left>") |
||||||
|
\ || a:cmdline.is_input("\<S-Left>") |
||||||
|
call a:cmdline.setline(strridx(a:cmdline.backward()[:-2], ' ') + 1) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-Right>") |
||||||
|
\ || a:cmdline.is_input("\<S-Right>") |
||||||
|
let p = stridx(a:cmdline.forward()[1:], ' ') |
||||||
|
call a:cmdline.setline(p != -1 ? a:cmdline.line.pos() + p + 2 : a:cmdline.line.length()) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,41 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Delete", |
||||||
|
\} |
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("\<C-h>") |
||||||
|
\ || a:cmdline.is_input("\<BS>") |
||||||
|
if a:cmdline.line.length() == 0 |
||||||
|
return a:cmdline.exit(1) |
||||||
|
else |
||||||
|
call a:cmdline.line.remove_prev() |
||||||
|
call a:cmdline.setchar('') |
||||||
|
endif |
||||||
|
elseif a:cmdline.is_input("\<Del>") |
||||||
|
call a:cmdline.line.remove_pos() |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-w>") |
||||||
|
let word = a:cmdline.backward_word() |
||||||
|
let backward = a:cmdline.backward()[ : -strlen(word)-1 ] |
||||||
|
call a:cmdline.setline(backward . a:cmdline.line.pos_char() . a:cmdline.forward()) |
||||||
|
call a:cmdline.setline(strchars(backward)) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
elseif a:cmdline.is_input("\<C-u>") |
||||||
|
call a:cmdline.setline(a:cmdline.line.pos_char() . a:cmdline.forward()) |
||||||
|
call a:cmdline.setline(0) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,106 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:E = s:V.import("Over.Exception") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Over.Exception", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:cache_command = {} |
||||||
|
function! s:doautocmd_user(prefix, command) |
||||||
|
let group = a:prefix . "-vital-over-commandline-doautocmd-dummy" |
||||||
|
if !has_key(s:cache_command, a:prefix) |
||||||
|
let s:cache_command[a:prefix] = {} |
||||||
|
endif |
||||||
|
|
||||||
|
if !has_key(s:cache_command[a:prefix], a:command) |
||||||
|
execute "autocmd " . group |
||||||
|
\ . " User " . a:command." silent! execute ''" |
||||||
|
|
||||||
|
if v:version > 703 || v:version == 703 && has("patch438") |
||||||
|
let s:cache_command[a:prefix][a:command] = "doautocmd <nomodeline> User " . a:command |
||||||
|
else |
||||||
|
let s:cache_command[a:prefix][a:command] = "doautocmd User " . a:command |
||||||
|
endif |
||||||
|
endif |
||||||
|
|
||||||
|
execute s:cache_command[a:prefix][a:command] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:hooks = [ |
||||||
|
\ "enter", |
||||||
|
\ "leave", |
||||||
|
\ "char", |
||||||
|
\ "char_pre", |
||||||
|
\ "draw", |
||||||
|
\ "draw_pre", |
||||||
|
\ "execute_pre", |
||||||
|
\ "execute_failed", |
||||||
|
\ "execute", |
||||||
|
\ "exception", |
||||||
|
\] |
||||||
|
|
||||||
|
let s:hooks_camel = [ |
||||||
|
\ "Enter", |
||||||
|
\ "Leave", |
||||||
|
\ "Char", |
||||||
|
\ "CharPre", |
||||||
|
\ "Draw", |
||||||
|
\ "DrawPre", |
||||||
|
\ "ExecutePre", |
||||||
|
\ "ExecuteFailed", |
||||||
|
\ "Execute", |
||||||
|
\ "Exception", |
||||||
|
\] |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Doautocmd", |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
for s:i in range(len(s:hooks)) |
||||||
|
execute join([ |
||||||
|
\ "function! s:module.on_" . s:hooks[s:i] . "(cmdline, ...)", |
||||||
|
\ " let s:cmdline = a:cmdline", |
||||||
|
\ " call s:doautocmd_user(self.prefix, self.prefix . " . string(s:hooks_camel[s:i]) . ")", |
||||||
|
\ "endfunction", |
||||||
|
\ ], "\n") |
||||||
|
endfor |
||||||
|
|
||||||
|
|
||||||
|
function! s:get_cmdline() |
||||||
|
if !exists("s:cmdline") |
||||||
|
execute s:E.throw_cmd("Undefined cmdline object.", "Over.Commandline.Modules.Doautocmd") |
||||||
|
endif |
||||||
|
return s:cmdline |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(prefix) |
||||||
|
if has_key(s:cache_command, a:prefix) |
||||||
|
unlet! s:cache_command[a:prefix] |
||||||
|
endif |
||||||
|
execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy" |
||||||
|
autocmd! |
||||||
|
augroup END |
||||||
|
|
||||||
|
let module = deepcopy(s:module) |
||||||
|
let module.prefix = a:prefix |
||||||
|
return module |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,140 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "DrawCommandline" |
||||||
|
\} |
||||||
|
|
||||||
|
let s:cmdheight = {} |
||||||
|
|
||||||
|
function! s:cmdheight.save() |
||||||
|
if has_key(self, "value") |
||||||
|
return |
||||||
|
endif |
||||||
|
let self.value = &cmdheight |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:cmdheight.restore() |
||||||
|
if has_key(self, "value") |
||||||
|
let &cmdheight = self.value |
||||||
|
unlet self.value |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:cmdheight.get() |
||||||
|
return self.value |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:suffix(left, suffix) |
||||||
|
let left_len = strdisplaywidth(a:left) |
||||||
|
let len = &columns - left_len % &columns |
||||||
|
let len = len + (&columns * (strdisplaywidth(a:suffix) > (len - 1))) - 1 |
||||||
|
return repeat(" ", len - strdisplaywidth(a:suffix)) . a:suffix |
||||||
|
" return printf("%" . len . "S", a:suffix) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:old_width = 0 |
||||||
|
function! s:_redraw(cmdline) |
||||||
|
let left = a:cmdline.get_prompt() . a:cmdline.getline() . (empty(a:cmdline.line.pos_char()) ? " " : "") |
||||||
|
let width = len(left) + 1 |
||||||
|
|
||||||
|
if a:cmdline.get_suffix() != "" |
||||||
|
let width += len(s:suffix(left, a:cmdline.get_suffix())) - 1 |
||||||
|
endif |
||||||
|
|
||||||
|
if &columns >= width && &columns <= s:old_width && s:old_width >= width |
||||||
|
redraw |
||||||
|
normal! : |
||||||
|
elseif &columns <= width |
||||||
|
normal! : |
||||||
|
else |
||||||
|
redraw |
||||||
|
endif |
||||||
|
let s:old_width = width |
||||||
|
|
||||||
|
call s:cmdheight.save() |
||||||
|
let height = max([(width - 1) / (&columns) + 1, s:cmdheight.get()]) |
||||||
|
if height > &cmdheight || &cmdheight > height |
||||||
|
let &cmdheight = height |
||||||
|
redraw |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_as_echon(str) |
||||||
|
return "echon " . strtrans(string(a:str)) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_draw_pre(cmdline) |
||||||
|
if empty(a:cmdline.line.pos_char()) |
||||||
|
let cursor = "echohl " . a:cmdline.highlights.cursor . " | echon ' '" |
||||||
|
else |
||||||
|
let cursor = "echohl " . a:cmdline.highlights.cursor_on . " | " . s:_as_echon(a:cmdline.line.pos_char()) |
||||||
|
endif |
||||||
|
let suffix = "" |
||||||
|
if a:cmdline.get_suffix() != "" |
||||||
|
let suffix = s:_as_echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix())) |
||||||
|
endif |
||||||
|
let self.draw_command = join([ |
||||||
|
\ "echohl " . a:cmdline.highlights.prompt, |
||||||
|
\ s:_as_echon(a:cmdline.get_prompt()), |
||||||
|
\ "echohl NONE", |
||||||
|
\ s:_as_echon(a:cmdline.backward()), |
||||||
|
\ cursor, |
||||||
|
\ "echohl NONE", |
||||||
|
\ s:_as_echon(a:cmdline.forward()), |
||||||
|
\ suffix, |
||||||
|
\ ], " | ") |
||||||
|
|
||||||
|
call s:_redraw(a:cmdline) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_echon(expr) |
||||||
|
echon strtrans(a:expr) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_draw(cmdline) |
||||||
|
execute self.draw_command |
||||||
|
" execute "echohl" a:cmdline.highlights.prompt |
||||||
|
" call s:echon(a:cmdline.get_prompt()) |
||||||
|
" echohl NONE |
||||||
|
" call s:echon(a:cmdline.backward()) |
||||||
|
" if empty(a:cmdline.line.pos_char()) |
||||||
|
" execute "echohl" a:cmdline.highlights.cursor |
||||||
|
" call s:echon(' ') |
||||||
|
" else |
||||||
|
" execute "echohl" a:cmdline.highlights.cursor_on |
||||||
|
" call s:echon(a:cmdline.line.pos_char()) |
||||||
|
" endif |
||||||
|
" echohl NONE |
||||||
|
" call s:echon(a:cmdline.forward()) |
||||||
|
" if a:cmdline.get_suffix() != "" |
||||||
|
" call s:echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix())) |
||||||
|
" endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_execute_pre(...) |
||||||
|
call s:cmdheight.restore() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_leave(...) |
||||||
|
call s:cmdheight.restore() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,22 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "ExceptionExit", |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_exception(cmdline) |
||||||
|
call a:cmdline.exit(-1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(...) |
||||||
|
let result = deepcopy(s:module) |
||||||
|
let result.exit_code = get(a:, 1, 0) |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,51 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:vname = expand("<sfile>:h:h:h:h:t") |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "ExceptionMessage", |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_exception(cmdline) |
||||||
|
let self.exception = v:exception |
||||||
|
let self.throwpoint = v:throwpoint |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_draw_pre(cmdline) |
||||||
|
if has_key(self, "exception") |
||||||
|
call self.message(a:cmdline) |
||||||
|
unlet self.exception |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.message(...) |
||||||
|
echohl ErrorMsg |
||||||
|
execute self.command string(self.prefix . " : " . self.throwpoint . " " . self.exception) |
||||||
|
echohl None |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_leave(cmdline) |
||||||
|
if has_key(self, "exception") |
||||||
|
call self.message(a:cmdline) |
||||||
|
unlet self.exception |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(...) |
||||||
|
let result = deepcopy(s:module) |
||||||
|
let result.prefix = get(a:, 1, "vital-over(".s:vname.") Exception") |
||||||
|
let result.command = get(a:, 2, "echom") |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,25 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Exit", |
||||||
|
\ "exit_code" : 0 |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("<Over>(exit)") |
||||||
|
call a:cmdline.setchar("") |
||||||
|
call a:cmdline.exit(self.exit_code) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,60 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "History", |
||||||
|
\ "mode" : "cmd", |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:module.histories() |
||||||
|
return map(range(1, &history), 'histget(self.mode, v:val * -1)') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_should_match_cmdline(cmdline) |
||||||
|
return a:cmdline.is_input("\<Up>") |
||||||
|
\ || a:cmdline.is_input("\<Down>") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_reset() |
||||||
|
let s:cmdhist = [] |
||||||
|
let s:count = 0 |
||||||
|
let s:is_match_mode = 0 " <Up>/<Down>: true, <C-n>/<C-p>: false |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_enter(...) |
||||||
|
call s:_reset() |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if !a:cmdline.is_input("\<Up>") && !a:cmdline.is_input("\<Down>") |
||||||
|
\ && !a:cmdline.is_input("\<C-p>") && !a:cmdline.is_input("\<C-n>") |
||||||
|
call s:_reset() |
||||||
|
return |
||||||
|
else |
||||||
|
if s:count == 0 && empty(s:cmdhist) |
||||||
|
\ || s:is_match_mode != s:_should_match_cmdline(a:cmdline) |
||||||
|
let cmdline = '^' . a:cmdline.getline() |
||||||
|
let s:is_match_mode = s:_should_match_cmdline(a:cmdline) |
||||||
|
let s:cmdhist = [a:cmdline.getline()] + (s:is_match_mode ? |
||||||
|
\ filter(self.histories(), 'v:val =~ cmdline') : self.histories()) |
||||||
|
endif |
||||||
|
endif |
||||||
|
call a:cmdline.setchar("") |
||||||
|
if a:cmdline.is_input("\<Down>") || a:cmdline.is_input("\<C-n>") |
||||||
|
let s:count = max([s:count - 1, 0]) |
||||||
|
endif |
||||||
|
if a:cmdline.is_input("\<Up>") || a:cmdline.is_input("\<C-p>") |
||||||
|
let s:count = min([s:count + 1, len(s:cmdhist)]) |
||||||
|
endif |
||||||
|
call a:cmdline.setline(get(s:cmdhist, s:count, a:cmdline.getline())) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:make(...) |
||||||
|
let module = deepcopy(s:module) |
||||||
|
let module.mode = get(a:, 1, "cmd") |
||||||
|
return module |
||||||
|
endfunction |
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,149 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:String = s:V.import("Over.String") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Over.String", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:to_string(expr) |
||||||
|
return type(a:expr) == type("") ? a:expr : string(a:expr) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:input(cmdline) |
||||||
|
let CR_index = index(a:cmdline.input_key_stack(), "\<CR>") |
||||||
|
if CR_index != -1 |
||||||
|
let input = a:cmdline.input_key_stack_string() |
||||||
|
let input = input[ : CR_index-1] |
||||||
|
call a:cmdline.set_input_key_stack(a:cmdline.input_key_stack()[CR_index+1 : ]) |
||||||
|
return eval(input) |
||||||
|
endif |
||||||
|
|
||||||
|
let input_text = "" |
||||||
|
if !empty(a:cmdline.input_key_stack()) |
||||||
|
let input_text = a:cmdline.input_key_stack_string() |
||||||
|
call a:cmdline.set_input_key_stack([]) |
||||||
|
endif |
||||||
|
|
||||||
|
call a:cmdline.hl_cursor_on() |
||||||
|
try |
||||||
|
redraw |
||||||
|
let input = input("=", input_text, "expression") |
||||||
|
if !empty(input) |
||||||
|
let input = s:to_string(eval(input)) |
||||||
|
endif |
||||||
|
catch |
||||||
|
return "" |
||||||
|
finally |
||||||
|
call a:cmdline.hl_cursor_off() |
||||||
|
endtry |
||||||
|
return input |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "InsertRegister" |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function! s:module.reset() |
||||||
|
let self.cword = expand("<cword>") |
||||||
|
let self.cWORD = expand("<cWORD>") |
||||||
|
let self.cfile = expand("<cfile>") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_enter(...) |
||||||
|
call self.reset() |
||||||
|
" let self.prefix_key = "" |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:get_cmdline_cword(backward, cword) |
||||||
|
" let backward = matchstr(a:backward, '.\{-}\zs\k\+$') |
||||||
|
let backward = a:backward |
||||||
|
if &incsearch == 0 || a:cword == "" || a:backward == "" || s:String.index(a:cword, backward) != 0 |
||||||
|
return a:cword |
||||||
|
endif |
||||||
|
return a:cword[len(backward) : ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("\<C-r>") |
||||||
|
call a:cmdline.setchar('"') |
||||||
|
let self.prefix_key = a:cmdline.input_key() |
||||||
|
let self.old_line = a:cmdline.getline() |
||||||
|
let self.old_pos = a:cmdline.getpos() |
||||||
|
return |
||||||
|
elseif exists("self.prefix_key") |
||||||
|
\ && a:cmdline.get_tap_key() == self.prefix_key |
||||||
|
call a:cmdline.setline(self.old_line) |
||||||
|
call a:cmdline.setpos(self.old_pos) |
||||||
|
let char = a:cmdline.input_key() |
||||||
|
if char =~ '^[0-9a-zA-z.%#:/"\-*+]$' |
||||||
|
let register = tr(getreg(char), "\n", "\r") |
||||||
|
call a:cmdline.setchar(register) |
||||||
|
elseif char == "=" |
||||||
|
call a:cmdline.setchar(s:input(a:cmdline)) |
||||||
|
elseif char == "\<C-w>" |
||||||
|
call a:cmdline.setchar(s:get_cmdline_cword(a:cmdline.backward_word(), self.cword)) |
||||||
|
elseif char == "\<C-a>" |
||||||
|
call a:cmdline.setchar(self.cWORD) |
||||||
|
elseif char == "\<C-f>" |
||||||
|
call a:cmdline.setchar(self.cfile) |
||||||
|
elseif char == "\<C-r>" |
||||||
|
call a:cmdline.setchar('"') |
||||||
|
else |
||||||
|
call a:cmdline.setchar("") |
||||||
|
endif |
||||||
|
" elseif a:cmdline.is_input('=', self.prefix_key) |
||||||
|
" call a:cmdline.setchar(s:input(a:cmdline)) |
||||||
|
" elseif a:cmdline.is_input("\<C-w>", self.prefix_key) |
||||||
|
" call a:cmdline.setchar(self.cword) |
||||||
|
" elseif a:cmdline.is_input("\<C-a>", self.prefix_key) |
||||||
|
" call a:cmdline.setchar(self.cWORD) |
||||||
|
" elseif a:cmdline.is_input("\<C-f>", self.prefix_key) |
||||||
|
" call a:cmdline.setchar(self.cfile) |
||||||
|
" elseif a:cmdline.is_input("\<C-r>", self.prefix_key) |
||||||
|
" call a:cmdline.setchar('"') |
||||||
|
" else |
||||||
|
" call a:cmdline.setchar("") |
||||||
|
" endif |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_char(cmdline) |
||||||
|
if a:cmdline.is_input("\<C-r>") |
||||||
|
call a:cmdline.tap_keyinput(self.prefix_key) |
||||||
|
call a:cmdline.disable_keymapping() |
||||||
|
call a:cmdline.setpos(a:cmdline.getpos()-1) |
||||||
|
else |
||||||
|
if exists("self.prefix_key") |
||||||
|
call a:cmdline.untap_keyinput(self.prefix_key) |
||||||
|
call a:cmdline.enable_keymapping() |
||||||
|
unlet! self.prefix_key |
||||||
|
endif |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,124 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:Keymapping = a:V.import("Palette.Keymapping") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Palette.Keymapping", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:emacs = { |
||||||
|
\ "name" : "KeyMapping_emacs_like" |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:emacs.keymapping(cmdline) |
||||||
|
return { |
||||||
|
\ "\<C-f>" : { |
||||||
|
\ "key" : "\<Right>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-b>" : { |
||||||
|
\ "key" : "\<Left>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-n>" : { |
||||||
|
\ "key" : "\<Down>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-p>" : { |
||||||
|
\ "key" : "\<Up>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-a>" : { |
||||||
|
\ "key" : "\<Home>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-e>" : { |
||||||
|
\ "key" : "\<End>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<C-d>" : { |
||||||
|
\ "key" : "\<Del>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<A-d>" : { |
||||||
|
\ "key" : "\<C-w>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<A-b>" : { |
||||||
|
\ "key" : "\<S-Left>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ "\<A-f>" : { |
||||||
|
\ "key" : "\<S-Right>", |
||||||
|
\ "noremap" : 1, |
||||||
|
\ "lock" : 1, |
||||||
|
\ }, |
||||||
|
\ } |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make_emacs() |
||||||
|
return deepcopy(s:emacs) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:vim_cmdline_mapping = { |
||||||
|
\ "name" : "KeyMapping_vim_cmdline_mapping", |
||||||
|
\ "_cmaps" : {} |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:_convert_sid(rhs, sid) abort |
||||||
|
return substitute(a:rhs, '<SID>', '<SNR>' . a:sid . '_', 'g') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:_auto_cmap() |
||||||
|
let cmaps = {} |
||||||
|
let cmap_info = s:Keymapping.rhs_key_list("c", 0, 1) |
||||||
|
" vital-over currently doesn't support <buffer> mappings |
||||||
|
for c in filter(cmap_info, "v:val['buffer'] ==# 0") |
||||||
|
let cmaps[s:Keymapping.escape_special_key(c['lhs'])] = { |
||||||
|
\ 'noremap' : c['noremap'], |
||||||
|
\ 'key' : s:Keymapping.escape_special_key(s:_convert_sid(c['rhs'], c['sid'])), |
||||||
|
\ 'expr' : s:Keymapping.escape_special_key(c['expr']), |
||||||
|
\ } |
||||||
|
endfor |
||||||
|
return cmaps |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:vim_cmdline_mapping.on_enter(cmdline) |
||||||
|
let self._cmaps = s:_auto_cmap() |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:vim_cmdline_mapping.keymapping(cmdline) |
||||||
|
return self._cmaps |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make_vim_cmdline_mapping() |
||||||
|
return deepcopy(s:vim_cmdline_mapping) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,40 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "NoInsert", |
||||||
|
\ "chars" : [] |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.is_no_insert(char) |
||||||
|
return index(self.chars, a:char) >= 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if self.is_no_insert(a:cmdline.char()) |
||||||
|
call a:cmdline.setchar("", 0) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(chars) |
||||||
|
let module = deepcopy(s:module) |
||||||
|
let module.chars = type(a:chars) == type([]) ? a:chars : [a:chars] |
||||||
|
return module |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make_special_chars() |
||||||
|
let module = s:make([]) |
||||||
|
function! module.is_no_insert(char) |
||||||
|
return char2nr(a:char) == 128 || char2nr(a:char) < 27 |
||||||
|
endfunction |
||||||
|
return module |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,25 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Paste" |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:module.on_char_pre(cmdline) |
||||||
|
if a:cmdline.is_input("<Over>(paste)") |
||||||
|
let register = v:register == "" ? '"' : v:register |
||||||
|
call a:cmdline.insert(tr(getreg("*"), "\n", "\r")) |
||||||
|
call a:cmdline.setchar('') |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,57 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:module = { |
||||||
|
\ "name" : "Redraw", |
||||||
|
\} |
||||||
|
|
||||||
|
function! s:module.on_execute_pre(cmdline) |
||||||
|
call self.redraw(a:cmdline) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_enter(...) |
||||||
|
let self.is_execute = 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_execute(...) |
||||||
|
let self.is_execute = 1 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_execute_failed(...) |
||||||
|
let self.is_execute = 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:module.on_leave(cmdline) |
||||||
|
if self.is_execute == 0 && a:cmdline.exit_code() != -1 |
||||||
|
call self.redraw(a:cmdline) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
" function! s:module.on_draw_pre(cmdline) |
||||||
|
" call self.redraw(a:cmdline) |
||||||
|
" endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:module.redraw(cmdline) |
||||||
|
redraw |
||||||
|
" Workaround for the :set cedit=<C-c> |
||||||
|
" https://github.com/osyo-manga/vital-over/issues/52 |
||||||
|
" https://github.com/Lokaltog/vim-easymotion/issues/177#issuecomment-53663431 |
||||||
|
if &cedit != "<C-c>" |
||||||
|
\ ||(v:version >= 704 && has("patch441")) |
||||||
|
normal! : |
||||||
|
else |
||||||
|
execute "normal! :\<Esc>" |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:make() |
||||||
|
return deepcopy(s:module) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,31 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:vname = expand("<sfile>:h:h:t") |
||||||
|
let s:prefix = printf("vital-over(%s) Exception", s:vname) |
||||||
|
|
||||||
|
function! s:set_prefix(prefix) |
||||||
|
let s:prefix = a:prefix |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:throw_cmd(exp, where) |
||||||
|
return 'throw ' . string(s:prefix . " : " . a:exp . " in " . a:where) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:throw(exp, where) |
||||||
|
execute s:throw_cmd(a:exp, a:where) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:error(text, where) |
||||||
|
echohl ErrorMsg |
||||||
|
echom s:prefix . " : " . a:text . " in " . a:where |
||||||
|
echohl None |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,25 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:getchar(...) |
||||||
|
let mode = get(a:, 1, 0) |
||||||
|
while 1 |
||||||
|
" Workaround for https://github.com/osyo-manga/vital-over/issues/53 |
||||||
|
try |
||||||
|
let char = call("getchar", a:000) |
||||||
|
catch /^Vim:Interrupt$/ |
||||||
|
let char = 3 " <C-c> |
||||||
|
endtry |
||||||
|
" Workaround for the <expr> mappings |
||||||
|
if string(char) !=# "\x80\xfd`" |
||||||
|
return mode == 1 ? !!char |
||||||
|
\ : type(char) == type(0) ? nr2char(char) : char |
||||||
|
endif |
||||||
|
endwhile |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,80 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:String = s:V.import("Over.String") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Over.String", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:as_key_config(config) |
||||||
|
let base = { |
||||||
|
\ "noremap" : 0, |
||||||
|
\ "lock" : 0, |
||||||
|
\ "expr" : 0, |
||||||
|
\ } |
||||||
|
return type(a:config) == type({}) ? extend(base, a:config) |
||||||
|
\ : extend(base, { |
||||||
|
\ "key" : a:config, |
||||||
|
\ }) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:match_key(keymapping, key) |
||||||
|
let keys = sort(keys(a:keymapping)) |
||||||
|
return get(filter(keys, 'stridx(a:key, v:val) == 0'), -1, '') |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_safe_eval(expr, ...) |
||||||
|
call extend(l:, get(a:, 1, {})) |
||||||
|
let result = get(a:, 2, "") |
||||||
|
try |
||||||
|
let result = eval(a:expr) |
||||||
|
catch |
||||||
|
echohl ErrorMsg | echom v:exception | echohl None |
||||||
|
endtry |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_get_key(conf) |
||||||
|
" call extend(l:, a:conf) |
||||||
|
let self = a:conf |
||||||
|
return get(a:conf, "expr", 0) ? s:_safe_eval(a:conf.key, l:) : a:conf.key |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:unmapping(keymapping, key, ...) |
||||||
|
let is_locking = get(a:, 1, 0) |
||||||
|
let key = s:match_key(a:keymapping, a:key) |
||||||
|
if key == "" |
||||||
|
return s:String.length(a:key) <= 1 ? a:key : s:unmapping(a:keymapping, a:key[0], is_locking) . s:unmapping(a:keymapping, a:key[1:], is_locking) |
||||||
|
endif |
||||||
|
|
||||||
|
let map_conf = s:as_key_config(a:keymapping[key]) |
||||||
|
|
||||||
|
let next_input = s:unmapping(a:keymapping, a:key[len(key) : ], is_locking) |
||||||
|
if map_conf.lock == 0 && is_locking |
||||||
|
return key . next_input |
||||||
|
elseif map_conf.lock |
||||||
|
return s:unmapping(a:keymapping, s:_get_key(map_conf), is_locking) . next_input |
||||||
|
else |
||||||
|
return s:unmapping(a:keymapping, s:_get_key(map_conf), map_conf.noremap) . next_input |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,104 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:L = s:V.import("Data.List") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return ["Data.List"] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:base = { |
||||||
|
\ "variables" : { |
||||||
|
\ "slots" : [], |
||||||
|
\ "counter" : 0, |
||||||
|
\ } |
||||||
|
\} |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.connect(slot) |
||||||
|
let self.variables.counter += 1 |
||||||
|
let slot = { "id" : self.variables.counter, "slot" : a:slot } |
||||||
|
call add(self.variables.slots, slot) |
||||||
|
return slot |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.disconnect(slot) |
||||||
|
if empty(a:slot) |
||||||
|
return -1 |
||||||
|
endif |
||||||
|
for i in range(len(self.variables.slots)) |
||||||
|
if self.variables.slots[i].id == a:slot.id |
||||||
|
unlet self.variables.slots[i] |
||||||
|
return |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return -1 |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.disconnect_by(expr) |
||||||
|
return self.disconnect(self.find_first_by(a:expr)) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:call(list, func, ...) |
||||||
|
let args = get(a:, 1, []) |
||||||
|
let def = get(a:, 2, 0) |
||||||
|
return map(copy(a:list), "has_key(v:val, a:func) ? call(v:val.".a:func.", args, v:val) : def") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.call(func, ...) |
||||||
|
return call("s:call", [self.slots(), a:func] + a:000) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.find_by(expr) |
||||||
|
return filter(copy(self.variables.slots), a:expr) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.find_first_by(expr) |
||||||
|
return get(self.find_by(a:expr), 0, {}) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.sort_by(expr) |
||||||
|
let self.variables.slots = s:L.sort_by(self.variables.slots, a:expr) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.get_slot(val) |
||||||
|
return a:val.slot |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:base.slots() |
||||||
|
return map(copy(self.variables.slots), "self.get_slot(v:val)") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
" function! s:base.dict() |
||||||
|
" let result = {} |
||||||
|
" for _ in self.variables.slots |
||||||
|
" let result[_.id] = _.value |
||||||
|
" endfor |
||||||
|
" return result |
||||||
|
" endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make() |
||||||
|
let result = deepcopy(s:base) |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,149 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:List = s:V.import("Data.List") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Data.List", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_clamp(x, max, min) |
||||||
|
return min([max([a:x, a:max]), a:min]) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let s:base = {} |
||||||
|
|
||||||
|
function! s:base.set(item) |
||||||
|
return type(a:item) == type("") ? self.set_str(a:item) |
||||||
|
\ : type(a:item) == type(0) ? self.set_pos(a:item) |
||||||
|
\ : self |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.str() |
||||||
|
return join(self.list, "") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.set_pos(pos) |
||||||
|
let self.col = s:_clamp(a:pos, 0, self.length()) |
||||||
|
return self |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.backward() |
||||||
|
return self.col > 0 ? join(self.list[ : self.col-1], '') : "" |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.forward() |
||||||
|
return join(self.list[self.col+1 : ], '') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.pos_char() |
||||||
|
return get(self.list, self.col, "") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.set_str(str) |
||||||
|
let self.list = split(a:str, '\zs') |
||||||
|
let self.col = strchars(a:str) |
||||||
|
return self |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.pos() |
||||||
|
return self.col |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.input(str) |
||||||
|
call extend(self.list, split(a:str, '\zs'), self.col) |
||||||
|
let self.col += len(split(a:str, '\zs')) |
||||||
|
return self |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.length() |
||||||
|
return len(self.list) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.next() |
||||||
|
return self.set_pos(self.col + 1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.prev() |
||||||
|
return self.set_pos(self.col - 1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.remove(index) |
||||||
|
if a:index < 0 || self.length() <= a:index |
||||||
|
return "" |
||||||
|
endif |
||||||
|
let result = self.list[a:index] |
||||||
|
unlet self.list[a:index] |
||||||
|
if a:index < self.col |
||||||
|
call self.set(self.col - 1) |
||||||
|
endif |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.remove_pos() |
||||||
|
return self.remove(self.col) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.remove_prev() |
||||||
|
return self.remove(self.col - 1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:base.remove_next() |
||||||
|
return self.remove(self.col + 1) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:make(...) |
||||||
|
let default = get(a:, 1, "") |
||||||
|
let result = deepcopy(s:base) |
||||||
|
call result.set(default) |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
" NOTE: old regexpengine has a bug with string which contains binary |
||||||
|
" :echo "\x80" =~ "\\%#=1\x80" | " => 0 |
||||||
|
" But it matches correctly with :h /collection |
||||||
|
" :echo "\x80" =~ "\\%#=1[\x80]" | " => 1 |
||||||
|
" http://lingr.com/room/vim/archives/2015/02/13#message-21261450 |
||||||
|
let s:_engine = exists("+regexpengine") ? '\%#=2' : '' |
||||||
|
" \<A-]> => Û\xfdQ |
||||||
|
" \<A-@> => À\xfeX |
||||||
|
let s:_regex = exists("+regexpengine") |
||||||
|
\ ? "\\%(Û\xfdQ\\|À\xfeX\\|\x80\xfc.\\%(\x80..\\|.\\)\\|\x80..\\|.\\)\\zs" |
||||||
|
\ : "\\%(Û[\xfd]Q\\|À[\xfe]X\\|[\x80][\xfc].\\%([\x80]..\\|.\\)\\|[\x80]..\\|.\\)\\zs" |
||||||
|
function! s:_split_keystring(str, ...) |
||||||
|
return split(a:str, s:_engine . '\m\%(' . get(a:, 1, '') . s:_regex . '\)') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:split_by_keys(str) |
||||||
|
return s:_split_keystring(a:str, "\\%(\<Plug>\\|<Over>\\)(.\\{-})\\zs\\|") |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:index(haystack, needle, ...) |
||||||
|
let start = get(a:, 1, 0) |
||||||
|
let ignorecase = get(a:, 2, &ignorecase) |
||||||
|
if ignorecase |
||||||
|
return stridx(tolower(a:haystack), tolower(a:needle), start) |
||||||
|
else |
||||||
|
return stridx(a:haystack, a:needle, start) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:length(str) |
||||||
|
return len(s:split_by_keys(a:str)) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,59 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:verbosefiles = [] |
||||||
|
|
||||||
|
function! s:_verbosefile_push(file) |
||||||
|
call add(s:verbosefiles, &verbosefile) |
||||||
|
let &verbosefile = a:file |
||||||
|
return a:file |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_verbosefile_pop() |
||||||
|
let filename = &verbosefile |
||||||
|
let &verbosefile = get(s:verbosefiles, -1) |
||||||
|
call remove(s:verbosefiles, -1) |
||||||
|
return filename |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_reset() |
||||||
|
let s:verbosefiles = [] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:extend(dict, src) |
||||||
|
for [key, value] in items(a:src) |
||||||
|
let a:dict[key] = value |
||||||
|
unlet value |
||||||
|
endfor |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:command(cmd, ...) |
||||||
|
" Workaround : Vim 7.3.xxx in Travis and Ubuntu |
||||||
|
" https://github.com/osyo-manga/vital-palette/issues/5 |
||||||
|
" call extend(l:, get(a:, 1, {})) |
||||||
|
if a:0 > 0 |
||||||
|
call s:extend(l:, a:1) |
||||||
|
endif |
||||||
|
|
||||||
|
call s:_verbosefile_push(tempname()) |
||||||
|
try |
||||||
|
redir =>result |
||||||
|
silent execute a:cmd |
||||||
|
finally |
||||||
|
redir END |
||||||
|
endtry |
||||||
|
call s:_verbosefile_pop() |
||||||
|
" let result = substitute(result, "<SRN>", "\<SNR>", "g") |
||||||
|
" let result = substitute(result, "<SID>", "\<SID>", "g") |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,118 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:Message = s:V.import("Vim.Message") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Vim.Message", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_execute(cmd) |
||||||
|
execute a:cmd |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:capture(name) |
||||||
|
if hlexists(a:name) == 0 |
||||||
|
return "" |
||||||
|
endif |
||||||
|
return s:Message.capture("highlight " . a:name) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:links_to(highlight) |
||||||
|
return matchstr(a:highlight, '^\S\+\s\+xxx links to \zs.*\ze$') |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:parse_to_name(highlight) |
||||||
|
return matchstr(a:highlight, '^\zs\w\+\ze') |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:parse(highlight) |
||||||
|
let highlight = a:highlight |
||||||
|
|
||||||
|
if highlight !~# '^\w\+\s\+xxx\s' |
||||||
|
return {} |
||||||
|
endif |
||||||
|
|
||||||
|
let name = s:parse_to_name(a:highlight) |
||||||
|
let result = { "_name" : name } |
||||||
|
|
||||||
|
if highlight =~# '^\w\+\s\+xxx cleared' |
||||||
|
let result.cleared = 1 |
||||||
|
return result |
||||||
|
endif |
||||||
|
|
||||||
|
let link = s:links_to(highlight) |
||||||
|
if link != "" |
||||||
|
let result.link = link |
||||||
|
return result |
||||||
|
endif |
||||||
|
|
||||||
|
let attrs = [ |
||||||
|
\ "term", |
||||||
|
\ "cterm", |
||||||
|
\ "ctermfg", |
||||||
|
\ "ctermbg", |
||||||
|
\ "gui", |
||||||
|
\ "font", |
||||||
|
\ "guifg", |
||||||
|
\ "guibg", |
||||||
|
\ "guisp", |
||||||
|
\ ] |
||||||
|
for attr in attrs |
||||||
|
let item = matchstr(highlight, '\s' . attr . '=\zs#\?\w\+\ze') |
||||||
|
if item != "" |
||||||
|
let result[attr] = item |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:get(name, ...) |
||||||
|
if !hlexists(a:name) |
||||||
|
return {} |
||||||
|
endif |
||||||
|
let result = s:parse(substitute(s:capture(a:name), "\n", "", "g")) |
||||||
|
if has_key(result, "link") && get(a:, 1, 0) |
||||||
|
return s:get(result.link, get(a:, 1, 0)) |
||||||
|
else |
||||||
|
return result |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:set(name, config) |
||||||
|
if type(a:config) == type("") |
||||||
|
return s:set(a:config, s:get(a:config)) |
||||||
|
endif |
||||||
|
if has_key(a:config, "cleared") |
||||||
|
return s:_execute("highlight clear " . a:name) |
||||||
|
endif |
||||||
|
if has_key(a:config, "link") |
||||||
|
return s:_execute("highlight link " . a:name . " " . a:config.link) |
||||||
|
endif |
||||||
|
return s:_execute("highlight " . a:name . " " . join(map(items(filter(a:config, "v:key !=# '_name'")), "v:val[0] . '=' . v:val[1]"), " ")) |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:group_list() |
||||||
|
let highlights = split(s:Message.capture("highlight"), "\n") |
||||||
|
return filter(map(highlights, "s:parse_to_name(v:val)"), "v:val != ''") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,106 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
let s:modep = "[nvoicsxl]" |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_loaded(V) |
||||||
|
let s:V = a:V |
||||||
|
let s:Capture = s:V.import("Palette.Capture") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_vital_depends() |
||||||
|
return [ |
||||||
|
\ "Palette.Capture", |
||||||
|
\ ] |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
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 |
||||||
|
|
||||||
|
|
||||||
|
function! s:capture(...) |
||||||
|
let mode = get(a:, 1, "") |
||||||
|
let modes = split(mode, '\zs') |
||||||
|
return join(map(modes, "s:_capture(v:val)"), "\n") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:_keymapping(str) |
||||||
|
return a:str =~ '^[!nvoicsxl]\s' |
||||||
|
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) |
||||||
|
" Workaround : <C-?> https://github.com/osyo-manga/vital-palette/issues/5 |
||||||
|
if a:key ==# "<^?>" |
||||||
|
return "\<C-?>" |
||||||
|
endif |
||||||
|
execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"' |
||||||
|
return result |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
function! s:parse_lhs(text, ...) |
||||||
|
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\+') |
||||||
|
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 |
||||||
|
|
||||||
|
|
||||||
|
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 |
||||||
|
|
||||||
|
|
||||||
|
function! s:rhs_key_list(...) |
||||||
|
let mode = get(a:, 1, "") |
||||||
|
let abbr = get(a:, 2, 0) |
||||||
|
let dict = get(a:, 3, 0) |
||||||
|
|
||||||
|
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") |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
@ -0,0 +1,56 @@ |
|||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function! s:echomsg(hl, msg) abort |
||||||
|
execute 'echohl' a:hl |
||||||
|
try |
||||||
|
for m in split(a:msg, "\n") |
||||||
|
echomsg m |
||||||
|
endfor |
||||||
|
finally |
||||||
|
echohl None |
||||||
|
endtry |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:error(msg) abort |
||||||
|
call s:echomsg('ErrorMsg', a:msg) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:warn(msg) abort |
||||||
|
call s:echomsg('WarningMsg', a:msg) |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:capture(command) abort |
||||||
|
try |
||||||
|
redir => out |
||||||
|
silent execute a:command |
||||||
|
finally |
||||||
|
redir END |
||||||
|
endtry |
||||||
|
return out |
||||||
|
endfunction |
||||||
|
|
||||||
|
" * Get max length of |hit-enter|. |
||||||
|
" If a string length of a message is greater than the max length, |
||||||
|
" Vim waits for user input according to |hit-enter|. |
||||||
|
" XXX: Those fixed values may be different between different OSes? |
||||||
|
" Currently tested on only Windows. |
||||||
|
function! s:get_hit_enter_max_length() abort |
||||||
|
let maxlen = &columns * &cmdheight - 1 |
||||||
|
if &ruler |
||||||
|
" TODO |
||||||
|
endif |
||||||
|
if &showcmd |
||||||
|
let maxlen -= 11 |
||||||
|
endif |
||||||
|
return maxlen |
||||||
|
endfunction |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
|
||||||
|
" vim:set et ts=2 sts=2 sw=2 tw=0: |
@ -0,0 +1,19 @@ |
|||||||
|
easymotion |
||||||
|
423c2c0 |
||||||
|
|
||||||
|
Over.Commandline.Base |
||||||
|
Over.Commandline.Modules.Cancel |
||||||
|
Over.Commandline.Modules.BufferComplete |
||||||
|
Over.Commandline.Modules.Paste |
||||||
|
Over.Commandline.Modules.KeyMapping |
||||||
|
Over.Commandline.Modules.Doautocmd |
||||||
|
Over.Commandline.Modules.CursorMove |
||||||
|
Over.Commandline.Modules.Delete |
||||||
|
Over.Commandline.Modules.Redraw |
||||||
|
Over.Commandline.Modules.InsertRegister |
||||||
|
Over.Commandline.Modules.History |
||||||
|
Over.Commandline.Modules.NoInsert |
||||||
|
Over.Commandline.Modules.Exit |
||||||
|
Over.Commandline.Modules.DrawCommandline |
||||||
|
Over.Commandline.Modules.ExceptionMessage |
||||||
|
Over.Commandline.Modules.ExceptionExit |
File diff suppressed because it is too large
Load Diff
@ -1,73 +1,283 @@ |
|||||||
|
scriptencoding utf-8 |
||||||
" EasyMotion - Vim motions on speed! |
" EasyMotion - Vim motions on speed! |
||||||
" |
" |
||||||
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com> |
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com> |
||||||
" Source repository: https://github.com/Lokaltog/vim-easymotion |
" haya14busa <hayabusa1419@gmail.com> |
||||||
|
" Source: https://github.com/easymotion/vim-easymotion |
||||||
" Script initialization {{{ |
" == Script initialization {{{ |
||||||
if exists('g:EasyMotion_loaded') || &compatible || version < 702 |
if expand("%:p") ==# expand("<sfile>:p") |
||||||
|
unlet! g:EasyMotion_loaded |
||||||
|
endif |
||||||
|
if exists('g:EasyMotion_loaded') || &compatible || version < 703 |
||||||
finish |
finish |
||||||
endif |
endif |
||||||
|
|
||||||
|
let g:EasyMotion_loaded = 1 |
||||||
|
" }}} |
||||||
|
|
||||||
|
" == Saving 'cpoptions' {{{ |
||||||
|
let s:save_cpo = &cpo |
||||||
|
set cpo&vim |
||||||
|
" }}} |
||||||
|
|
||||||
|
" == Default configuration {{{ |
||||||
|
" -- Option ------------------------------ {{{ |
||||||
|
let g:EasyMotion_keys = get(g:, |
||||||
|
\ 'EasyMotion_keys', 'asdghklqwertyuiopzxcvbnmfj;') |
||||||
|
" \ 'EasyMotion_keys', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
||||||
|
let g:EasyMotion_do_mapping = get(g: , 'EasyMotion_do_mapping' , 1) |
||||||
|
let g:EasyMotion_do_shade = get(g: , 'EasyMotion_do_shade' , 1) |
||||||
|
let g:EasyMotion_grouping = get(g: , 'EasyMotion_grouping' , 1) |
||||||
|
let g:EasyMotion_startofline = get(g: , 'EasyMotion_startofline' , 1) |
||||||
|
let g:EasyMotion_smartcase = get(g: , 'EasyMotion_smartcase' , 0) |
||||||
|
let g:EasyMotion_skipfoldedline = get(g: , 'EasyMotion_skipfoldedline' , 1) |
||||||
|
let g:EasyMotion_use_migemo = get(g: , 'EasyMotion_use_migemo' , 0) |
||||||
|
let g:EasyMotion_use_upper = get(g: , 'EasyMotion_use_upper' , 0) |
||||||
|
let g:EasyMotion_enter_jump_first = get(g: , 'EasyMotion_enter_jump_first' , 0) |
||||||
|
let g:EasyMotion_space_jump_first = get(g: , 'EasyMotion_space_jump_first' , 0) |
||||||
|
let g:EasyMotion_inc_highlight = get(g: , 'EasyMotion_inc_highlight' , 1) |
||||||
|
let g:EasyMotion_move_highlight = get(g: , 'EasyMotion_move_highlight' , 1) |
||||||
|
let g:EasyMotion_landing_highlight = get(g: , 'EasyMotion_landing_highlight' , 0) |
||||||
|
let g:EasyMotion_cursor_highlight = get(g: , 'EasyMotion_cursor_highlight' , 1) |
||||||
|
let g:EasyMotion_use_regexp = get(g: , 'EasyMotion_use_regexp' , 1) |
||||||
|
let g:EasyMotion_add_search_history = get(g: , 'EasyMotion_add_search_history' , 1) |
||||||
|
let g:EasyMotion_off_screen_search = get(g: , 'EasyMotion_off_screen_search' , 1) |
||||||
|
let g:EasyMotion_force_csapprox = get(g: , 'EasyMotion_force_csapprox' , 0) |
||||||
|
let g:EasyMotion_show_prompt = get(g: , 'EasyMotion_show_prompt' , 1) |
||||||
|
let g:EasyMotion_prompt = |
||||||
|
\ get(g: , 'EasyMotion_prompt' , 'Search for {n} character(s): ') |
||||||
|
let g:EasyMotion_command_line_key_mappings = |
||||||
|
\ get(g: , 'EasyMotion_command_line_key_mappings' , {}) |
||||||
|
let g:EasyMotion_disable_two_key_combo = |
||||||
|
\ get(g: , 'EasyMotion_disable_two_key_combo' , 0) |
||||||
|
|
||||||
|
"}}} |
||||||
|
|
||||||
let g:EasyMotion_loaded = 1 |
|
||||||
" }}} |
" }}} |
||||||
" Default configuration {{{ |
|
||||||
" Default options {{{ |
" == <Plug> Mapping {{{ |
||||||
call EasyMotion#InitOptions({ |
" Note: bd is short for bidirectional |
||||||
\ 'leader_key' : '<Leader><Leader>' |
" l is short for (within) line |
||||||
\ , 'keys' : 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
||||||
\ , 'do_shade' : 1 |
function! s:motion_map_helper(motions) "{{{ |
||||||
\ , 'do_mapping' : 1 |
for [name, dict] in items(a:motions) |
||||||
\ , 'grouping' : 1 |
let mapargs = [] |
||||||
|
let xmapargs = [] |
||||||
|
if dict.fnc ==# 'S' || dict.fnc ==# 'SL' || dict.fnc ==# 'T' || dict.fnc ==# 'TL' |
||||||
|
let mapargs += [dict.cnt, 0, dict.direction] |
||||||
|
let xmapargs += [dict.cnt, 1, dict.direction] |
||||||
|
elseif dict.fnc ==# 'Search' |
||||||
|
let mapargs += [0, dict.direction, dict.respect_direction] |
||||||
|
let xmapargs += [1, dict.direction, dict.respect_direction] |
||||||
|
else |
||||||
|
let mapargs += [0, dict.direction] |
||||||
|
let xmapargs += [1, dict.direction] |
||||||
|
endif |
||||||
|
|
||||||
|
silent exec 'noremap <silent><Plug>(easymotion-'.name.')' . |
||||||
|
\ ' :<C-u>call EasyMotion#' . dict.fnc . '('. join(mapargs, ',') . ')<CR>' |
||||||
|
silent exec 'xnoremap <silent><Plug>(easymotion-'.name.')' . |
||||||
|
\ ' <Esc>:<C-u>call EasyMotion#' . dict.fnc . '('. join(xmapargs, ',') . ')<CR>' |
||||||
|
" Example: |
||||||
|
" noremap <silent><Plug>(easymotion-f2) :<C-u>call EasyMotion#S(2,1,0)<CR> |
||||||
|
" xnoremap <silent><Plug>(easymotion-f2) <Esc>:<C-u>call EasyMotion#S(2,1,0)<CR> |
||||||
|
endfor |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Find Motion: {{{ |
||||||
|
call s:motion_map_helper({ |
||||||
|
\ 'f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 0}, |
||||||
|
\ 'F' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 1}, |
||||||
|
\ 's' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2}, |
||||||
|
\ 'bd-f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2}, |
||||||
|
\ 't' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 0}, |
||||||
|
\ 'T' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 1}, |
||||||
|
\ 'bd-t' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 2}, |
||||||
|
\ 'fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 0}, |
||||||
|
\ 'Fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 1}, |
||||||
|
\ 'sl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 2}, |
||||||
|
\ 'bd-fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 2}, |
||||||
|
\ 'tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 0}, |
||||||
|
\ 'Tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 1}, |
||||||
|
\ 'bd-tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 2}, |
||||||
\ |
\ |
||||||
\ , 'hl_group_target' : 'EasyMotionTarget' |
\ 'f2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 0}, |
||||||
\ , 'hl_group_shade' : 'EasyMotionShade' |
\ 'F2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 1}, |
||||||
|
\ 's2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ 'bd-f2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ 't2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 0}, |
||||||
|
\ 'T2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 1}, |
||||||
|
\ 'bd-t2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ 'fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 0}, |
||||||
|
\ 'Fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 1}, |
||||||
|
\ 'sl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ 'bd-fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ 'tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 0}, |
||||||
|
\ 'Tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 1}, |
||||||
|
\ 'bd-tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 2}, |
||||||
|
\ |
||||||
|
\ 'fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 0}, |
||||||
|
\ 'Fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 1}, |
||||||
|
\ 'sn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 2}, |
||||||
|
\ 'bd-fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 2}, |
||||||
|
\ 'tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 0}, |
||||||
|
\ 'Tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 1}, |
||||||
|
\ 'bd-tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 2}, |
||||||
|
\ 'fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 0}, |
||||||
|
\ 'Fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 1}, |
||||||
|
\ 'sln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 2}, |
||||||
|
\ 'bd-fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 2}, |
||||||
|
\ 'tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 0}, |
||||||
|
\ 'Tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 1}, |
||||||
|
\ 'bd-tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 2}, |
||||||
\ }) |
\ }) |
||||||
" }}} |
"}}} |
||||||
" Default highlighting {{{ |
|
||||||
let s:target_hl_defaults = { |
" -- Word Motion {{{ |
||||||
\ 'gui' : ['NONE', '#ff0000' , 'bold'] |
call s:motion_map_helper({ |
||||||
\ , 'cterm256': ['NONE', '196' , 'bold'] |
\ 'w' : {'fnc' : 'WB' , 'direction' : 0}, |
||||||
\ , 'cterm' : ['NONE', 'red' , 'bold'] |
\ 'b' : {'fnc' : 'WB' , 'direction' : 1}, |
||||||
\ } |
\ 'bd-w' : {'fnc' : 'WB' , 'direction' : 2}, |
||||||
|
\ 'W' : {'fnc' : 'WBW', 'direction' : 0}, |
||||||
let s:shade_hl_defaults = { |
\ 'B' : {'fnc' : 'WBW', 'direction' : 1}, |
||||||
\ 'gui' : ['NONE', '#777777' , 'NONE'] |
\ 'bd-W' : {'fnc' : 'WBW', 'direction' : 2}, |
||||||
\ , 'cterm256': ['NONE', '242' , 'NONE'] |
\ 'iskeyword-w' : {'fnc' : 'WBK', 'direction' : 0}, |
||||||
\ , 'cterm' : ['NONE', 'grey' , 'NONE'] |
\ 'iskeyword-b' : {'fnc' : 'WBK', 'direction' : 1}, |
||||||
\ } |
\ 'iskeyword-bd-w' : {'fnc' : 'WBK', 'direction' : 2}, |
||||||
|
\ |
||||||
call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults) |
\ 'e' : {'fnc' : 'E' , 'direction' : 0}, |
||||||
call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults) |
\ 'ge' : {'fnc' : 'E' , 'direction' : 1}, |
||||||
|
\ 'bd-e' : {'fnc' : 'E' , 'direction' : 2}, |
||||||
" Reset highlighting after loading a new color scheme {{{ |
\ 'E' : {'fnc' : 'EW' , 'direction' : 0}, |
||||||
augroup EasyMotionInitHL |
\ 'gE' : {'fnc' : 'EW' , 'direction' : 1}, |
||||||
autocmd! |
\ 'bd-E' : {'fnc' : 'EW' , 'direction' : 2}, |
||||||
|
\ 'iskeyword-e' : {'fnc' : 'EK' , 'direction' : 0}, |
||||||
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_target, s:target_hl_defaults) |
\ 'iskeyword-ge' : {'fnc' : 'EK' , 'direction' : 1}, |
||||||
autocmd ColorScheme * call EasyMotion#InitHL(g:EasyMotion_hl_group_shade, s:shade_hl_defaults) |
\ 'iskeyword-bd-e' : {'fnc' : 'EK' , 'direction' : 2}, |
||||||
augroup end |
\ }) |
||||||
" }}} |
"}}} |
||||||
" }}} |
|
||||||
" Default key mapping {{{ |
" -- JK Motion {{{ |
||||||
call EasyMotion#InitMappings({ |
call s:motion_map_helper({ |
||||||
\ 'f' : { 'name': 'F' , 'dir': 0 } |
\ 'j' : {'fnc' : 'JK' , 'direction' : 0}, |
||||||
\ , 'F' : { 'name': 'F' , 'dir': 1 } |
\ 'k' : {'fnc' : 'JK' , 'direction' : 1}, |
||||||
\ , 't' : { 'name': 'T' , 'dir': 0 } |
\ 'bd-jk' : {'fnc' : 'JK' , 'direction' : 2}, |
||||||
\ , 'T' : { 'name': 'T' , 'dir': 1 } |
\ 'sol-j' : {'fnc' : 'Sol', 'direction' : 0}, |
||||||
\ , 'w' : { 'name': 'WB' , 'dir': 0 } |
\ 'sol-k' : {'fnc' : 'Sol', 'direction' : 1}, |
||||||
\ , 'W' : { 'name': 'WBW', 'dir': 0 } |
\ 'sol-bd-jk' : {'fnc' : 'Sol', 'direction' : 2}, |
||||||
\ , 'b' : { 'name': 'WB' , 'dir': 1 } |
\ 'eol-j' : {'fnc' : 'Eol', 'direction' : 0}, |
||||||
\ , 'B' : { 'name': 'WBW', 'dir': 1 } |
\ 'eol-k' : {'fnc' : 'Eol', 'direction' : 1}, |
||||||
\ , 'e' : { 'name': 'E' , 'dir': 0 } |
\ 'eol-bd-jk' : {'fnc' : 'Eol', 'direction' : 2}, |
||||||
\ , 'E' : { 'name': 'EW' , 'dir': 0 } |
|
||||||
\ , 'ge': { 'name': 'E' , 'dir': 1 } |
|
||||||
\ , 'gE': { 'name': 'EW' , 'dir': 1 } |
|
||||||
\ , 'j' : { 'name': 'JK' , 'dir': 0 } |
|
||||||
\ , 'k' : { 'name': 'JK' , 'dir': 1 } |
|
||||||
\ , 'n' : { 'name': 'Search' , 'dir': 0 } |
|
||||||
\ , 'N' : { 'name': 'Search' , 'dir': 1 } |
|
||||||
\ }) |
\ }) |
||||||
" }}} |
"}}} |
||||||
|
|
||||||
|
" -- Search Motion {{{ |
||||||
|
call s:motion_map_helper({ |
||||||
|
\ 'n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 0}, |
||||||
|
\ 'N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 0}, |
||||||
|
\ 'bd-n' : {'fnc' : 'Search', 'direction': 2, 'respect_direction': 0}, |
||||||
|
\ 'vim-n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 1}, |
||||||
|
\ 'vim-N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 1}, |
||||||
|
\ }) |
||||||
|
"}}} |
||||||
|
|
||||||
|
" -- Jump To Anywhere Motion {{{ |
||||||
|
call s:motion_map_helper({ |
||||||
|
\ 'jumptoanywhere' : {'fnc' : 'JumpToAnywhere', 'direction': 2}, |
||||||
|
\ }) |
||||||
|
"}}} |
||||||
|
|
||||||
|
" -- Line Motion {{{ |
||||||
|
call s:motion_map_helper({ |
||||||
|
\ 'wl' : {'fnc' : 'WBL', 'direction': 0}, |
||||||
|
\ 'bl' : {'fnc' : 'WBL', 'direction': 1}, |
||||||
|
\ 'bd-wl' : {'fnc' : 'WBL', 'direction': 2}, |
||||||
|
\ 'el' : {'fnc' : 'EL' , 'direction': 0}, |
||||||
|
\ 'gel' : {'fnc' : 'EL' , 'direction': 1}, |
||||||
|
\ 'bd-el' : {'fnc' : 'EL' , 'direction': 2}, |
||||||
|
\ 'lineforward' : {'fnc' : 'LineAnywhere', 'direction': 0}, |
||||||
|
\ 'linebackward' : {'fnc' : 'LineAnywhere', 'direction': 1}, |
||||||
|
\ 'lineanywhere' : {'fnc' : 'LineAnywhere', 'direction': 2}, |
||||||
|
\ }) |
||||||
|
"}}} |
||||||
|
|
||||||
|
" -- Next, Previous Motion {{{ |
||||||
|
noremap <silent><Plug>(easymotion-next) |
||||||
|
\ :<C-u>call EasyMotion#NextPrevious(0,0)<CR> |
||||||
|
xnoremap <silent><Plug>(easymotion-next) |
||||||
|
\ :<C-u>call EasyMotion#NextPrevious(1,0)<CR> |
||||||
|
|
||||||
|
noremap <silent><Plug>(easymotion-prev) |
||||||
|
\ :<C-u>call EasyMotion#NextPrevious(0,1)<CR> |
||||||
|
xnoremap <silent><Plug>(easymotion-prev) |
||||||
|
\ :<C-u>call EasyMotion#NextPrevious(1,1)<CR> |
||||||
|
"}}} |
||||||
|
|
||||||
|
" -- Repeat Motion {{{ |
||||||
|
noremap <silent><Plug>(easymotion-repeat) |
||||||
|
\ :<C-u>call EasyMotion#Repeat(0)<CR> |
||||||
|
xnoremap <silent><Plug>(easymotion-repeat) |
||||||
|
\ <Esc>:<C-u>call EasyMotion#Repeat(1)<CR> |
||||||
|
|
||||||
|
noremap <silent><Plug>(easymotion-dotrepeat) |
||||||
|
\ :<C-u>call EasyMotion#DotRepeat()<CR> |
||||||
|
"}}} |
||||||
|
|
||||||
|
noremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(0)<CR> |
||||||
|
xnoremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(1)<CR> |
||||||
" }}} |
" }}} |
||||||
|
|
||||||
" vim: fdm=marker:noet:ts=4:sw=4:sts=4 |
" == Default key mapping {{{ |
||||||
|
if g:EasyMotion_do_mapping == 1 |
||||||
|
" Prepare Prefix: {{{ |
||||||
|
if exists('g:EasyMotion_leader_key') |
||||||
|
exec 'map ' . g:EasyMotion_leader_key . ' <Plug>(easymotion-prefix)' |
||||||
|
else |
||||||
|
if !hasmapto('<Plug>(easymotion-prefix)') |
||||||
|
map <Leader><Leader> <Plug>(easymotion-prefix) |
||||||
|
endif |
||||||
|
endif |
||||||
|
"}}} |
||||||
|
|
||||||
|
function! s:default_mapping(motions, do_mapping) "{{{ |
||||||
|
for motion in a:motions |
||||||
|
" Mapping {{{ |
||||||
|
if exists('g:EasyMotion_mapping_' . motion) |
||||||
|
" Backward compatible mapping [deprecated] |
||||||
|
silent exec 'map <silent> ' . |
||||||
|
\ eval('g:EasyMotion_mapping_' . motion) . ' <Plug>(easymotion-' . motion . ')' |
||||||
|
elseif a:do_mapping |
||||||
|
\ && !hasmapto('<Plug>(easymotion-' . motion . ')') |
||||||
|
\ && empty(maparg('<Plug>(easymotion-prefix)' . motion, 'nov')) |
||||||
|
|
||||||
|
" Do mapping |
||||||
|
silent exec 'map <silent> ' . |
||||||
|
\'<Plug>(easymotion-prefix)' . motion . ' <Plug>(easymotion-' . motion . ')' |
||||||
|
endif "}}} |
||||||
|
endfor |
||||||
|
endfunction "}}} |
||||||
|
|
||||||
|
" Default Mapping: |
||||||
|
call s:default_mapping( |
||||||
|
\ ['f', 'F', 's', 't', 'T', |
||||||
|
\ 'w', 'W', 'b', 'B', 'e', 'E', 'ge', 'gE', |
||||||
|
\ 'j', 'k', 'n', 'N'], g:EasyMotion_do_mapping) |
||||||
|
endif "}}} |
||||||
|
|
||||||
|
" == CommandLine Mapping {{{ |
||||||
|
command! -nargs=* |
||||||
|
\ EMCommandLineNoreMap |
||||||
|
\ call EasyMotion#command_line#cnoremap([<f-args>]) |
||||||
|
command! -nargs=* |
||||||
|
\ EMCommandLineMap |
||||||
|
\ call EasyMotion#command_line#cmap([<f-args>]) |
||||||
|
command! -nargs=1 |
||||||
|
\ EMCommandLineUnMap |
||||||
|
\ call EasyMotion#command_line#cunmap(<f-args>) |
||||||
|
"}}} |
||||||
|
|
||||||
|
" == Restore 'cpoptions' {{{ |
||||||
|
let &cpo = s:save_cpo |
||||||
|
unlet s:save_cpo |
||||||
|
" }}} |
||||||
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4 |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,110 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: t/operator_pending_spec.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
|
||||||
|
" Avoid source test files {{{ |
||||||
|
if expand("%:p") ==# expand("<sfile>:p") |
||||||
|
finish |
||||||
|
endif |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Setup {{{ |
||||||
|
let s:root_dir = matchstr(system('git rev-parse --show-cdup'), '[^\n]\+') |
||||||
|
execute 'set' 'rtp +=./'.s:root_dir |
||||||
|
runtime! plugin/EasyMotion.vim |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Functions for Test {{{ |
||||||
|
function! AddLine(str) |
||||||
|
put! =a:str |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! CursorPos() |
||||||
|
return [line('.'), col('.'), getline('.')[col('.')-1]] |
||||||
|
endfunction |
||||||
|
"}}} |
||||||
|
|
||||||
|
|
||||||
|
" NOTE: |
||||||
|
" I cannot test inclusive motion because mode() doesn't works well with |
||||||
|
" vim-vspec |
||||||
|
|
||||||
|
" word motions {{{ |
||||||
|
describe 'word motions' |
||||||
|
before |
||||||
|
new |
||||||
|
let g:EasyMotion_keys = '123456789' |
||||||
|
omap f <Plug>(easymotion-f) |
||||||
|
omap w <Plug>(easymotion-w) |
||||||
|
omap b <Plug>(easymotion-b) |
||||||
|
call EasyMotion#init() |
||||||
|
call AddLine('vim deco vim deco vim deco') |
||||||
|
" 123456789012345678901234567890 |
||||||
|
end |
||||||
|
|
||||||
|
after |
||||||
|
close! |
||||||
|
end |
||||||
|
|
||||||
|
it '<Plug>(easymotion-w)' |
||||||
|
" Default position |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,'v'] |
||||||
|
|
||||||
|
normal dw1 |
||||||
|
Expect CursorPos() == [l,1,'d'] |
||||||
|
normal! u |
||||||
|
normal! 0 |
||||||
|
Expect CursorPos() == [l,1,'v'] |
||||||
|
|
||||||
|
normal dw2 |
||||||
|
Expect CursorPos() == [l,1,'v'] |
||||||
|
normal! 0 |
||||||
|
normal! u |
||||||
|
normal! 0 |
||||||
|
Expect CursorPos() == [l,1,'v'] |
||||||
|
end |
||||||
|
|
||||||
|
it '<Plug>(easymotion-b)' |
||||||
|
" Default position |
||||||
|
normal! $ |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,26,'o'] |
||||||
|
|
||||||
|
normal db1 |
||||||
|
Expect CursorPos() == [l,23,'o'] |
||||||
|
normal! u |
||||||
|
normal! $ |
||||||
|
Expect CursorPos() == [l,26,'o'] |
||||||
|
|
||||||
|
normal db2 |
||||||
|
Expect CursorPos() == [l,19,'o'] |
||||||
|
normal! u |
||||||
|
normal! $ |
||||||
|
Expect CursorPos() == [l,26,'o'] |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
@ -0,0 +1,575 @@ |
|||||||
|
"============================================================================= |
||||||
|
" FILE: t/smartsign_spec.vim |
||||||
|
" AUTHOR: haya14busa |
||||||
|
" License: MIT license {{{ |
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
" a copy of this software and associated documentation files (the |
||||||
|
" "Software"), to deal in the Software without restriction, including |
||||||
|
" without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
" permit persons to whom the Software is furnished to do so, subject to |
||||||
|
" the following conditions: |
||||||
|
" |
||||||
|
" The above copyright notice and this permission notice shall be included |
||||||
|
" in all copies or substantial portions of the Software. |
||||||
|
" |
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
" }}} |
||||||
|
"============================================================================= |
||||||
|
|
||||||
|
" Test for `smartsign` feature for find motions |
||||||
|
|
||||||
|
" Avoid source test files {{{ |
||||||
|
if expand("%:p") ==# expand("<sfile>:p") |
||||||
|
finish |
||||||
|
endif |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Setup {{{ |
||||||
|
let s:root_dir = matchstr(system('git rev-parse --show-cdup'), '[^\n]\+') |
||||||
|
execute 'set' 'rtp +=./'.s:root_dir |
||||||
|
runtime! plugin/EasyMotion.vim |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Functions for Test {{{ |
||||||
|
function! AddLine(str) |
||||||
|
put! =a:str |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! CursorPos() |
||||||
|
return [line('.'), col('.'), getline('.')[col('.')-1]] |
||||||
|
endfunction |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Smartsign configulation {{{ |
||||||
|
describe 'Smartsign configulation' |
||||||
|
it 'provide default dictionary' |
||||||
|
let smartdict_us = g:EasyMotion#sticky_table#us |
||||||
|
let smartdict_jp = g:EasyMotion#sticky_table#jp |
||||||
|
Expect smartdict_us !=# {} |
||||||
|
Expect smartdict_jp !=# {} |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Basic Smartsign feature with 1-key findmotions with US layout {{{ |
||||||
|
describe 'Basic Smartsign feature with 1-key findmotions with US layout' |
||||||
|
before |
||||||
|
new |
||||||
|
let g:EasyMotion_keys = '123456789' |
||||||
|
let g:EasyMotion_use_smartsign_us = 1 |
||||||
|
map s <Plug>(easymotion-s) |
||||||
|
call EasyMotion#init() |
||||||
|
call AddLine(' -_ =+ ;: [{ ]} `~ ''" \|') |
||||||
|
call AddLine(' 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0)') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
" 123456789012345678901234567890 |
||||||
|
" 1 2 3 |
||||||
|
" |
||||||
|
" ',' : '<', '.' : '>', '/' : '?', |
||||||
|
" '1' : '!', '2' : '@', '3' : '#', '4' : '$', '5' : '%', |
||||||
|
" '6' : '^', '7' : '&', '8' : '*', '9' : '(', '0' : ')', '-' : '_', '=' : '+', |
||||||
|
" ';' : ':', '[' : '{', ']' : '}', '`' : '~', "'" : "\"", '\' : '|', |
||||||
|
end |
||||||
|
|
||||||
|
after |
||||||
|
close! |
||||||
|
end |
||||||
|
|
||||||
|
it 'works well for all sign as a target char' |
||||||
|
" Default position |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
|
||||||
|
" ,< |
||||||
|
normal s,1 |
||||||
|
Expect CursorPos() == [l,2,','] |
||||||
|
normal! 0 |
||||||
|
normal s,2 |
||||||
|
Expect CursorPos() == [l,3,'<'] |
||||||
|
normal! 0 |
||||||
|
normal s<1 |
||||||
|
Expect CursorPos() == [l,3,'<'] |
||||||
|
normal! 0 |
||||||
|
normal s,3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" .> |
||||||
|
normal s.1 |
||||||
|
Expect CursorPos() == [l,5,'.'] |
||||||
|
normal! 0 |
||||||
|
normal s.2 |
||||||
|
Expect CursorPos() == [l,6,'>'] |
||||||
|
normal! 0 |
||||||
|
normal s>1 |
||||||
|
Expect CursorPos() == [l,6,'>'] |
||||||
|
normal! 0 |
||||||
|
normal s.3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" /? |
||||||
|
normal s/1 |
||||||
|
Expect CursorPos() == [l,8,'/'] |
||||||
|
normal! 0 |
||||||
|
normal s/2 |
||||||
|
Expect CursorPos() == [l,9,'?'] |
||||||
|
normal! 0 |
||||||
|
normal s?1 |
||||||
|
Expect CursorPos() == [l,9,'?'] |
||||||
|
normal! 0 |
||||||
|
normal s/3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 1! |
||||||
|
normal s11 |
||||||
|
Expect CursorPos() == [l+1,2,'1'] |
||||||
|
normal! 0 |
||||||
|
normal s12 |
||||||
|
Expect CursorPos() == [l+1,3,'!'] |
||||||
|
normal! 0 |
||||||
|
normal s!1 |
||||||
|
Expect CursorPos() == [l+1,3,'!'] |
||||||
|
normal! 0 |
||||||
|
normal s13 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 2@ |
||||||
|
normal s21 |
||||||
|
Expect CursorPos() == [l+1,5,'2'] |
||||||
|
normal! 0 |
||||||
|
normal s22 |
||||||
|
Expect CursorPos() == [l+1,6,'@'] |
||||||
|
normal! 0 |
||||||
|
normal s@1 |
||||||
|
Expect CursorPos() == [l+1,6,'@'] |
||||||
|
normal! 0 |
||||||
|
normal s23 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 3# |
||||||
|
normal s31 |
||||||
|
Expect CursorPos() == [l+1,8,'3'] |
||||||
|
normal! 0 |
||||||
|
normal s32 |
||||||
|
Expect CursorPos() == [l+1,9,'#'] |
||||||
|
normal! 0 |
||||||
|
normal s#1 |
||||||
|
Expect CursorPos() == [l+1,9,'#'] |
||||||
|
normal! 0 |
||||||
|
normal s33 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 4$ |
||||||
|
normal s41 |
||||||
|
Expect CursorPos() == [l+1,11,'4'] |
||||||
|
normal! 0 |
||||||
|
normal s42 |
||||||
|
Expect CursorPos() == [l+1,12,'$'] |
||||||
|
normal! 0 |
||||||
|
normal s$1 |
||||||
|
Expect CursorPos() == [l+1,12,'$'] |
||||||
|
normal! 0 |
||||||
|
normal s43 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 5% |
||||||
|
normal s51 |
||||||
|
Expect CursorPos() == [l+1,14,'5'] |
||||||
|
normal! 0 |
||||||
|
normal s52 |
||||||
|
Expect CursorPos() == [l+1,15,'%'] |
||||||
|
normal! 0 |
||||||
|
normal s%1 |
||||||
|
Expect CursorPos() == [l+1,15,'%'] |
||||||
|
normal! 0 |
||||||
|
normal s53 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 6^ |
||||||
|
normal s61 |
||||||
|
Expect CursorPos() == [l+1,17,'6'] |
||||||
|
normal! 0 |
||||||
|
normal s62 |
||||||
|
Expect CursorPos() == [l+1,18,'^'] |
||||||
|
normal! 0 |
||||||
|
normal s^1 |
||||||
|
Expect CursorPos() == [l+1,18,'^'] |
||||||
|
normal! 0 |
||||||
|
normal s63 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 7& |
||||||
|
normal s71 |
||||||
|
Expect CursorPos() == [l+1,20,'7'] |
||||||
|
normal! 0 |
||||||
|
normal s72 |
||||||
|
Expect CursorPos() == [l+1,21,'&'] |
||||||
|
normal! 0 |
||||||
|
normal s&1 |
||||||
|
Expect CursorPos() == [l+1,21,'&'] |
||||||
|
normal! 0 |
||||||
|
normal s73 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 8* |
||||||
|
normal s81 |
||||||
|
Expect CursorPos() == [l+1,23,'8'] |
||||||
|
normal! 0 |
||||||
|
normal s82 |
||||||
|
Expect CursorPos() == [l+1,24,'*'] |
||||||
|
normal! 0 |
||||||
|
normal s*1 |
||||||
|
Expect CursorPos() == [l+1,24,'*'] |
||||||
|
normal! 0 |
||||||
|
normal s83 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 9( |
||||||
|
normal s91 |
||||||
|
Expect CursorPos() == [l+1,26,'9'] |
||||||
|
normal! 0 |
||||||
|
normal s92 |
||||||
|
Expect CursorPos() == [l+1,27,'('] |
||||||
|
normal! 0 |
||||||
|
normal s(1 |
||||||
|
Expect CursorPos() == [l+1,27,'('] |
||||||
|
normal! 0 |
||||||
|
normal s93 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" 0) |
||||||
|
normal s01 |
||||||
|
Expect CursorPos() == [l+1,29,'0'] |
||||||
|
normal! 0 |
||||||
|
normal s02 |
||||||
|
Expect CursorPos() == [l+1,30,')'] |
||||||
|
normal! 0 |
||||||
|
normal s)1 |
||||||
|
Expect CursorPos() == [l+1,30,')'] |
||||||
|
normal! 0 |
||||||
|
normal s03 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" -_ |
||||||
|
normal s-1 |
||||||
|
Expect CursorPos() == [l+2,2,'-'] |
||||||
|
normal! 0 |
||||||
|
normal s-2 |
||||||
|
Expect CursorPos() == [l+2,3,'_'] |
||||||
|
normal! 0 |
||||||
|
normal s_1 |
||||||
|
Expect CursorPos() == [l+2,3,'_'] |
||||||
|
normal! 0 |
||||||
|
normal s-3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" =+ |
||||||
|
normal s=1 |
||||||
|
Expect CursorPos() == [l+2,5,'='] |
||||||
|
normal! 0 |
||||||
|
normal s=2 |
||||||
|
Expect CursorPos() == [l+2,6,'+'] |
||||||
|
normal! 0 |
||||||
|
normal s+1 |
||||||
|
Expect CursorPos() == [l+2,6,'+'] |
||||||
|
normal! 0 |
||||||
|
normal s=3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" ;: |
||||||
|
normal s;1 |
||||||
|
Expect CursorPos() == [l+2,8,';'] |
||||||
|
normal! 0 |
||||||
|
normal s;2 |
||||||
|
Expect CursorPos() == [l+2,9,':'] |
||||||
|
normal! 0 |
||||||
|
normal s:1 |
||||||
|
Expect CursorPos() == [l+2,9,':'] |
||||||
|
normal! 0 |
||||||
|
normal s;3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" [{ |
||||||
|
normal s[1 |
||||||
|
Expect CursorPos() == [l+2,11,'['] |
||||||
|
normal! 0 |
||||||
|
normal s[2 |
||||||
|
Expect CursorPos() == [l+2,12,'{'] |
||||||
|
normal! 0 |
||||||
|
normal s{1 |
||||||
|
Expect CursorPos() == [l+2,12,'{'] |
||||||
|
normal! 0 |
||||||
|
normal s[3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" ]} |
||||||
|
normal s]1 |
||||||
|
Expect CursorPos() == [l+2,14,']'] |
||||||
|
normal! 0 |
||||||
|
normal s]2 |
||||||
|
Expect CursorPos() == [l+2,15,'}'] |
||||||
|
normal! 0 |
||||||
|
normal s}1 |
||||||
|
Expect CursorPos() == [l+2,15,'}'] |
||||||
|
normal! 0 |
||||||
|
normal s]3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" `~ |
||||||
|
normal s`1 |
||||||
|
Expect CursorPos() == [l+2,17,'`'] |
||||||
|
normal! 0 |
||||||
|
normal s`2 |
||||||
|
Expect CursorPos() == [l+2,18,'~'] |
||||||
|
normal! 0 |
||||||
|
normal s~1 |
||||||
|
Expect CursorPos() == [l+2,18,'~'] |
||||||
|
normal! 0 |
||||||
|
normal s`3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" '" |
||||||
|
normal s'1 |
||||||
|
Expect CursorPos() == [l+2,20,''''] |
||||||
|
normal! 0 |
||||||
|
normal s'2 |
||||||
|
Expect CursorPos() == [l+2,21,'"'] |
||||||
|
normal! 0 |
||||||
|
normal s"1 |
||||||
|
Expect CursorPos() == [l+2,21,'"'] |
||||||
|
normal! 0 |
||||||
|
normal s'3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
|
||||||
|
" \| |
||||||
|
normal s\1 |
||||||
|
Expect CursorPos() == [l+2,23,'\'] |
||||||
|
normal! 0 |
||||||
|
normal s\2 |
||||||
|
Expect CursorPos() == [l+2,24,'|'] |
||||||
|
normal! 0 |
||||||
|
normal s|1 |
||||||
|
Expect CursorPos() == [l+2,24,'|'] |
||||||
|
normal! 0 |
||||||
|
normal s\3 |
||||||
|
Expect CursorPos() == [l+2,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Smartsign with 2-key find motions with US layout {{{ |
||||||
|
describe 'Smartsign with 2-key find motions with US layout' |
||||||
|
before |
||||||
|
new |
||||||
|
let g:EasyMotion_keys = '123456789' |
||||||
|
let g:EasyMotion_use_smartsign_us = 1 |
||||||
|
map s <Plug>(easymotion-s2) |
||||||
|
call EasyMotion#init() |
||||||
|
call AddLine(' -_ =+ ;: [{ ]} `~ ''" \|') |
||||||
|
call AddLine(' 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0)') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
call AddLine(' -_ =+ ;: [{ ]} `~ ''" \|') |
||||||
|
call AddLine(' 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0)') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
" 123456789012345678901234567890 |
||||||
|
" 1 2 3 |
||||||
|
end |
||||||
|
|
||||||
|
after |
||||||
|
close! |
||||||
|
end |
||||||
|
|
||||||
|
it 'works well' |
||||||
|
" Default position |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
|
||||||
|
" ,< |
||||||
|
normal s,,1 |
||||||
|
Expect CursorPos() == [l,2,','] |
||||||
|
normal! 0 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal s,,3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s, 1 |
||||||
|
Expect CursorPos() == [l,3,'<'] |
||||||
|
normal! 0 |
||||||
|
normal s<<1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s,<1 |
||||||
|
Expect CursorPos() == [l,2,','] |
||||||
|
normal! 0 |
||||||
|
normal s<,1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
it ': s,,3' |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal s,,3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
|
||||||
|
it 'escape * asterisc #151' |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal s1*22 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s8*1 |
||||||
|
Expect CursorPos() == [l+1,23,'8'] |
||||||
|
normal! 0 |
||||||
|
normal s881 |
||||||
|
Expect CursorPos() == [l+1,23,'8'] |
||||||
|
normal! 0 |
||||||
|
normal s**1 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s*81 |
||||||
|
Expect CursorPos() == [l+1,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Smartsign with 2-key find motions with JP layout {{{ |
||||||
|
describe 'Smartsign with 2-key find motions with JP layout' |
||||||
|
before |
||||||
|
new |
||||||
|
let g:EasyMotion_keys = '123456789' |
||||||
|
let g:EasyMotion_use_smartsign_jp = 1 |
||||||
|
map s <Plug>(easymotion-s2) |
||||||
|
call EasyMotion#init() |
||||||
|
call AddLine(' -= ^~ ;+ :* [{ ]} @` \|') |
||||||
|
call AddLine(' 1! 2" 3# 4$ 5% 6& 7'' 8( 9) 0_') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
call AddLine(' -= ^~ ;+ :* [{ ]} @` \|') |
||||||
|
call AddLine(' 1! 2" 3# 4$ 5% 6& 7'' 8( 9) 0_') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
" 123456789012345678901234567890 |
||||||
|
" 1 2 3 |
||||||
|
" |
||||||
|
"',' : '<', '.' : '>', '/' : '?', |
||||||
|
"'1' : '!', '2' : '"', '3' : '#', '4' : '$', '5' : '%', |
||||||
|
"'6' : '&', '7' : "'", '8' : '(', '9' : ')', '0' : '_', '-' : '=', '^' : '~', |
||||||
|
"';' : '+', ':' : '*', '[' : '{', ']' : '}', '@' : '`', '\' : '|', |
||||||
|
" |
||||||
|
end |
||||||
|
|
||||||
|
after |
||||||
|
close! |
||||||
|
end |
||||||
|
|
||||||
|
it 'works well' |
||||||
|
" Default position |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
|
||||||
|
" ,< |
||||||
|
normal s,,1 |
||||||
|
Expect CursorPos() == [l,2,','] |
||||||
|
normal! 0 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal s,,3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s, 1 |
||||||
|
Expect CursorPos() == [l,3,'<'] |
||||||
|
normal! 0 |
||||||
|
normal s<<1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal s,<1 |
||||||
|
Expect CursorPos() == [l,2,','] |
||||||
|
normal! 0 |
||||||
|
normal s<,1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
it ': s,,3' |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal s,,3 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
||||||
|
" Smartsign with n-key find search motions {{{ |
||||||
|
describe 'Smartsign with n-key find search motions' |
||||||
|
before |
||||||
|
new |
||||||
|
let g:EasyMotion_keys = '123456789' |
||||||
|
let g:EasyMotion_use_smartsign_jp = 1 |
||||||
|
map / <Plug>(easymotion-sn) |
||||||
|
call EasyMotion#init() |
||||||
|
call AddLine(' -= ^~ ;+ :* [{ ]} @` \|') |
||||||
|
call AddLine(' 1! 2" 3# 4$ 5% 6& 7'' 8( 9) 0_') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
call AddLine(' -= ^~ ;+ :* [{ ]} @` \|') |
||||||
|
call AddLine(' 1! 2" 3# 4$ 5% 6& 7'' 8( 9) 0_') |
||||||
|
call AddLine(' ,< .> /?') |
||||||
|
end |
||||||
|
|
||||||
|
after |
||||||
|
close! |
||||||
|
end |
||||||
|
|
||||||
|
it 'do not work' |
||||||
|
" Default position |
||||||
|
normal! 0 |
||||||
|
let l = line('.') |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
|
||||||
|
" ,< |
||||||
|
normal /,,1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
normal /,<1 |
||||||
|
Expect CursorPos() == [l,1,' '] |
||||||
|
normal! 0 |
||||||
|
end |
||||||
|
end |
||||||
|
"}}} |
||||||
|
|
||||||
|
" __END__ {{{ |
||||||
|
" vim: expandtab softtabstop=4 shiftwidth=4 |
||||||
|
" vim: foldmethod=marker |
||||||
|
" }}} |
Loading…
Reference in new issue