2014-01-12 07:45:21 -05:00
|
|
|
"=============================================================================
|
|
|
|
" FILE: autoload/EasyMotion/helper.vim
|
|
|
|
" AUTHOR: haya14busa
|
2014-02-22 04:31:13 -05:00
|
|
|
" Last Change: 22 Feb 2014.
|
2014-01-12 07:45:21 -05:00
|
|
|
" 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) "{{{
|
2014-01-17 03:39:26 -05:00
|
|
|
return mode(a:flag) == "\<C-v>" ? "C-v" : mode(a:flag)
|
2014-01-12 07:45:21 -05:00
|
|
|
endfunction "}}}
|
|
|
|
|
2014-01-13 13:12:02 -05:00
|
|
|
function! EasyMotion#helper#is_greater_coords(coords1, coords2) "{{{
|
2014-01-17 03:39:26 -05:00
|
|
|
" [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
|
2014-01-13 13:12:02 -05:00
|
|
|
|
2014-01-17 03:39:26 -05:00
|
|
|
if a:coords1[0] < a:coords2[0]
|
|
|
|
return 1
|
|
|
|
elseif a:coords1[0] > a:coords2[0]
|
|
|
|
return -1
|
|
|
|
endif
|
2014-01-13 13:12:02 -05:00
|
|
|
|
2014-01-17 03:39:26 -05:00
|
|
|
" Same line
|
|
|
|
if a:coords1[1] < a:coords2[1]
|
|
|
|
return 1
|
|
|
|
elseif a:coords1[1] > a:coords2[1]
|
|
|
|
return -1
|
|
|
|
endif
|
2014-01-13 13:12:02 -05:00
|
|
|
endfunction "}}}
|
2014-01-26 03:25:11 -05:00
|
|
|
|
|
|
|
function! EasyMotion#helper#is_folded(line) "{{{
|
|
|
|
" Return false if g:EasyMotion_skipfoldedline == 1
|
|
|
|
" and line is start of folded lines
|
2014-02-22 04:31:13 -05:00
|
|
|
let _foldclosed = foldclosed(a:line)
|
|
|
|
return _foldclosed != -1 &&
|
|
|
|
\ (g:EasyMotion_skipfoldedline == 1 || a:line != _foldclosed)
|
2014-01-26 03:25:11 -05:00
|
|
|
endfunction "}}}
|
2014-02-06 08:12:52 -05:00
|
|
|
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
|
2014-01-26 03:25:11 -05:00
|
|
|
endif
|
2014-02-06 08:12:52 -05:00
|
|
|
|
|
|
|
if (g:EasyMotion_smartcase == 1 && match(a:input, '\u') == -1) ||
|
|
|
|
\ (&ignorecase && &smartcase && match(a:input, '\u') == -1) ||
|
|
|
|
\ (&ignorecase && !&smartcase)
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
2014-01-26 03:25:11 -05:00
|
|
|
endfunction "}}}
|
2014-02-12 21:27:07 -05:00
|
|
|
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)
|
2014-02-12 21:40:01 -05:00
|
|
|
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
|
2014-02-12 21:27:07 -05:00
|
|
|
endfunction "}}}
|
2014-02-16 05:45:32 -05:00
|
|
|
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
|
|
|
|
" setbufbar( 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 "}}}
|
2014-01-13 13:12:02 -05:00
|
|
|
|
2014-01-13 18:48:26 -05:00
|
|
|
" Migemo {{{
|
|
|
|
function! EasyMotion#helper#load_migemo_dict() "{{{
|
2014-01-17 03:39:26 -05:00
|
|
|
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
|
2014-01-13 18:48:26 -05:00
|
|
|
endfunction "}}}
|
|
|
|
|
|
|
|
" EasyMotion#helper#strchars() {{{
|
|
|
|
if exists('*strchars')
|
2014-01-17 03:39:26 -05:00
|
|
|
function! EasyMotion#helper#strchars(str)
|
|
|
|
return strchars(a:str)
|
|
|
|
endfunction
|
2014-01-13 18:48:26 -05:00
|
|
|
else
|
2014-01-17 03:39:26 -05:00
|
|
|
function! EasyMotion#helper#strchars(str)
|
|
|
|
return strlen(substitute(str, ".", "x", "g"))
|
|
|
|
endfunction
|
2014-01-13 18:48:26 -05:00
|
|
|
endif "}}}
|
|
|
|
function! EasyMotion#helper#include_multibyte_char(str) "{{{
|
|
|
|
return strlen(a:str) != EasyMotion#helper#strchars(a:str)
|
|
|
|
endfunction "}}}
|
|
|
|
"}}}
|
|
|
|
|
2014-01-12 07:45:21 -05:00
|
|
|
" Restore 'cpoptions' {{{
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
" }}}
|
2014-01-17 03:39:26 -05:00
|
|
|
" vim: fdm=marker:et:ts=4:sw=4:sts=4
|