2016-03-27 05:39:03 -04:00
|
|
|
" ___vital___
|
|
|
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
|
|
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
|
|
|
if v:version > 703 || v:version == 703 && has('patch1170')
|
|
|
|
function! vital#_easymotion#Over#Commandline#Modules#History#import() abort
|
|
|
|
return map({'make': ''}, 'function("s:" . v:key)')
|
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
function! s:_SID() abort
|
|
|
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
|
|
|
endfunction
|
|
|
|
execute join(['function! vital#_easymotion#Over#Commandline#Modules#History#import() abort', printf("return map({'make': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
|
|
|
delfunction s:_SID
|
|
|
|
endif
|
|
|
|
" ___vital___
|
2014-01-29 00:29:23 -05:00
|
|
|
scriptencoding utf-8
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
let s:module = {
|
|
|
|
\ "name" : "History",
|
|
|
|
\ "mode" : "cmd",
|
|
|
|
\}
|
|
|
|
|
|
|
|
function! s:module.histories()
|
2014-11-23 12:07:19 -05:00
|
|
|
return map(range(1, &history), 'histget(self.mode, v:val * -1)')
|
2014-01-29 00:29:23 -05:00
|
|
|
endfunction
|
|
|
|
|
2014-11-23 12:07:19 -05:00
|
|
|
function! s:_should_match_cmdline(cmdline)
|
|
|
|
return a:cmdline.is_input("\<Up>")
|
|
|
|
\ || a:cmdline.is_input("\<Down>")
|
|
|
|
endfunction
|
2014-01-29 00:29:23 -05:00
|
|
|
|
2014-11-23 12:07:19 -05:00
|
|
|
function! s:_reset()
|
2014-01-29 00:29:23 -05:00
|
|
|
let s:cmdhist = []
|
|
|
|
let s:count = 0
|
2014-11-23 12:07:19 -05:00
|
|
|
let s:is_match_mode = 0 " <Up>/<Down>: true, <C-n>/<C-p>: false
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:module.on_enter(...)
|
|
|
|
call s:_reset()
|
2014-01-29 00:29:23 -05:00
|
|
|
endfunction
|
|
|
|
|
2014-01-30 01:31:25 -05:00
|
|
|
function! s:module.on_char_pre(cmdline)
|
|
|
|
if !a:cmdline.is_input("\<Up>") && !a:cmdline.is_input("\<Down>")
|
2014-11-23 12:07:19 -05:00
|
|
|
\ && !a:cmdline.is_input("\<C-p>") && !a:cmdline.is_input("\<C-n>")
|
|
|
|
call s:_reset()
|
2014-01-29 00:29:23 -05:00
|
|
|
return
|
|
|
|
else
|
|
|
|
if s:count == 0 && empty(s:cmdhist)
|
2014-11-23 12:07:19 -05:00
|
|
|
\ || s:is_match_mode != s:_should_match_cmdline(a:cmdline)
|
2014-01-29 00:29:23 -05:00
|
|
|
let cmdline = '^' . a:cmdline.getline()
|
2014-11-23 12:07:19 -05:00
|
|
|
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())
|
2014-01-29 00:29:23 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
call a:cmdline.setchar("")
|
2014-11-23 12:07:19 -05:00
|
|
|
if a:cmdline.is_input("\<Down>") || a:cmdline.is_input("\<C-n>")
|
2014-01-29 00:29:23 -05:00
|
|
|
let s:count = max([s:count - 1, 0])
|
|
|
|
endif
|
2014-11-23 12:07:19 -05:00
|
|
|
if a:cmdline.is_input("\<Up>") || a:cmdline.is_input("\<C-p>")
|
2014-01-29 00:29:23 -05:00
|
|
|
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
|