Merge branch 'improve/commandline' into dev
This commit is contained in:
commit
5475bd72f6
@ -2,7 +2,7 @@
|
||||
" FILE: autoload/EasyMotion/command_line.vim
|
||||
" AUTHOR: haya14busa
|
||||
" Reference: https://github.com/osyo-manga/vim-over
|
||||
" Last Change: 05 Feb 2014.
|
||||
" Last Change: 06 Feb 2014.
|
||||
" License: MIT license {{{
|
||||
" Permission is hereby granted, free of charge, to any person obtaining
|
||||
" a copy of this software and associated documentation files (the
|
||||
@ -36,12 +36,15 @@ let s:search = s:cmdline.make_plain("/")
|
||||
let s:search.highlights.prompt = "Question"
|
||||
|
||||
" Add Module: {{{
|
||||
call s:search.connect(s:cmdline.module_delete())
|
||||
call s:search.connect(s:cmdline.module_cursor_move())
|
||||
call s:search.connect(s:cmdline.module_paste())
|
||||
call s:search.connect(s:cmdline.module_buffer_complete())
|
||||
call s:search.connect(s:cmdline.module_history("/"))
|
||||
call s:search.connect(s:cmdline.module_no_insert_special_chars())
|
||||
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(s:cmdline.get_module('History').make('/'))
|
||||
call s:search.connect(s:cmdline.get_module('NoInsert').make_special_chars())
|
||||
call s:search.connect(s:cmdline.get_module('KeyMapping').make_emacs())
|
||||
call s:search.connect(s:cmdline.get_module('Doautocmd').make('EMCommandLine'))
|
||||
|
||||
let s:module = {
|
||||
\ "name" : "EasyMotion",
|
||||
@ -70,20 +73,51 @@ call s:search.connect(s:module)
|
||||
"}}}
|
||||
|
||||
" CommandLine Keymap: {{{
|
||||
let s:default_key_mapping = {
|
||||
\ "\<C-d>" : "<Over>(buffer-complete)",
|
||||
\ "\<Tab>" : "<Over>(em-scroll-f)",
|
||||
\ "\<S-Tab>" : "<Over>(em-scroll-b)",
|
||||
\ "\<C-o>" : "<Over>(em-jumpback)",
|
||||
\ "\<C-z>" : "<Over>(em-openallfold)",
|
||||
\}
|
||||
function! EasyMotion#command_line#keymaps() "{{{
|
||||
return extend(deepcopy(s:default_key_mapping),
|
||||
\ g:EasyMotion_command_line_key_mappings)
|
||||
endfunction "}}}
|
||||
function! s:search.keymappings() "{{{
|
||||
return EasyMotion#command_line#keymaps()
|
||||
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,
|
||||
\ },
|
||||
\ }
|
||||
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: {{{
|
||||
@ -117,11 +151,6 @@ function! s:search.on_char() "{{{
|
||||
call s:search.exit()
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:search.on_cancel() "{{{
|
||||
call s:Cancell()
|
||||
call s:search.setline('')
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Main:
|
||||
function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
|
||||
@ -142,6 +171,9 @@ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
|
||||
let input = s:search.get()
|
||||
if input == '' && ! s:search.exit_code()
|
||||
return a:prev
|
||||
elseif s:search.exit_code() == 1 " cancelled
|
||||
call s:Cancell()
|
||||
return ''
|
||||
else
|
||||
return input
|
||||
endif
|
||||
|
@ -7,28 +7,12 @@ let s:modules = [
|
||||
\ "Scroll",
|
||||
\ "CursorMove",
|
||||
\ "Delete",
|
||||
\ "Paste",
|
||||
\ "HistAdd",
|
||||
\ "History",
|
||||
\ "Incsearch",
|
||||
\ "BufferComplete",
|
||||
\ "Cancel",
|
||||
\ "Enter",
|
||||
\ "NoInsert",
|
||||
\]
|
||||
|
||||
let s:modules_snake = [
|
||||
\ "scroll",
|
||||
\ "cursor_move",
|
||||
\ "delete",
|
||||
\ "paste",
|
||||
\ "histadd",
|
||||
\ "history",
|
||||
\ "incsearch",
|
||||
\ "buffer_complete",
|
||||
\ "cancel",
|
||||
\ "enter",
|
||||
\ "no_insert",
|
||||
\ "InsertRegister",
|
||||
\]
|
||||
|
||||
|
||||
@ -37,60 +21,67 @@ function! s:_vital_loaded(V)
|
||||
for module in s:modules
|
||||
let s:{module} = s:V.import('Over.Commandline.Modules.' . module)
|
||||
endfor
|
||||
let s:String = s:V.import("Over.String")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return map(copy(s:modules), "'Over.Commandline.Modules.' . v:val")
|
||||
return ["Over.String"]
|
||||
\ + map(copy(s:modules), "'Over.Commandline.Modules.' . v:val")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_module(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_plain(prompt)
|
||||
let result = deepcopy(s:base)
|
||||
let result = s:make(a:prompt)
|
||||
let result.prompt = a:prompt
|
||||
call result.connect(s:module_cancel())
|
||||
call result.connect(s:module_enter())
|
||||
call result.connect("Enter")
|
||||
call result.connect("Cancel")
|
||||
return result
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make_simple(prompt)
|
||||
function! s:make_standard(prompt)
|
||||
let result = s:make_plain(a:prompt)
|
||||
call result.connect(s:module_scroll())
|
||||
call result.connect(s:module_delete())
|
||||
call result.connect(s:module_cursor_move())
|
||||
call result.connect(s:module_histadd())
|
||||
call result.connect(s:module_history())
|
||||
call result.connect(s:module_buffer_complete())
|
||||
call result.connect(s:module_no_insert_special_chars())
|
||||
call result.connect("Delete")
|
||||
call result.connect("CursorMove")
|
||||
call result.connect("HistAdd")
|
||||
call result.connect("History")
|
||||
call result.connect("InsertRegister")
|
||||
call result.connect(s:get_module("NoInsert").make_special_chars())
|
||||
return result
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make(prompt)
|
||||
return s:make_simple(a:prompt)
|
||||
return deepcopy(s:base)
|
||||
endfunction
|
||||
|
||||
|
||||
let s:base = {
|
||||
\ "prompt" : "> ",
|
||||
\ "prompt" : "",
|
||||
\ "line" : {},
|
||||
\ "variables" : {
|
||||
\ "char" : "",
|
||||
\ "input" : "",
|
||||
\ "wait_key" : "",
|
||||
\ "tap_key" : "",
|
||||
\ "exit" : 0,
|
||||
\ "keymapping" : {},
|
||||
\ "modules" : {},
|
||||
\ },
|
||||
\ "highlights" : {
|
||||
\ "prompt" : "NONE",
|
||||
\ "cursor" : "OverCommandLineDefaultCursor",
|
||||
\ "cursor_insert" : "OverCommandLineDefaultCursorInsert"
|
||||
\ },
|
||||
\ "modules" : {},
|
||||
\ "keys" : {
|
||||
\ "quit" : "\<Esc>",
|
||||
\ "enter" : "\<CR>",
|
||||
\ }
|
||||
\}
|
||||
|
||||
|
||||
@ -120,32 +111,37 @@ endfunction
|
||||
|
||||
|
||||
function! s:base.setpos(pos)
|
||||
return self.line.set_pos(pos)
|
||||
return self.line.set_pos(a:pos)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.wait_keyinput_on(key)
|
||||
let self.variables.wait_key = a:key
|
||||
function! s:base.tap_keyinput(key)
|
||||
let self.variables.tap_key = a:key
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.wait_keyinput_off(key)
|
||||
if self.variables.wait_key == a:key
|
||||
let self.variables.wait_key = ""
|
||||
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_wait_keyinput()
|
||||
return self.variables.wait_key
|
||||
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_wait_keyinput() == prekey
|
||||
\ && get(self.keymappings(), self.char(), self.char()) == a:key
|
||||
return self.get_tap_key() == prekey
|
||||
\ && self.char() == a:key
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.input_key()
|
||||
return self.variables.input_key
|
||||
endfunction
|
||||
|
||||
|
||||
@ -166,20 +162,23 @@ endfunction
|
||||
|
||||
|
||||
function! s:base.connect(module, ...)
|
||||
if type(a:module) == type("")
|
||||
return self.connect(s:get_module(a:module).make())
|
||||
endif
|
||||
let name = get(a:, 1, a:module.name)
|
||||
let self.modules[name] = a:module
|
||||
let self.variables.modules[name] = a:module
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.disconnect(name)
|
||||
unlet self.modules[a:name] = a:module
|
||||
unlet self.variables.modules[a:name] = a:module
|
||||
endfunction
|
||||
|
||||
|
||||
for s:_ in ["enter", "leave", "char", "char_pre", "execute_pre", "execute_failed", "execute", "cancel"]
|
||||
execute join([
|
||||
\ "function! s:base._on_" . s:_ . "()",
|
||||
\ " call map(copy(self.modules), 'has_key(v:val, \"on_" . s:_ . "\") ? v:val.on_" . s:_ . "(self) : 0')",
|
||||
\ " call map(copy(self.variables.modules), 'has_key(v:val, \"on_" . s:_ . "\") ? v:val.on_" . s:_ . "(self) : 0')",
|
||||
\ " call self.on_" . s:_ . "()",
|
||||
\ "endfunction",
|
||||
\ ], "\n")
|
||||
@ -190,8 +189,25 @@ endfor
|
||||
unlet s:_
|
||||
|
||||
|
||||
" Overridable
|
||||
function! s:base.keymappings()
|
||||
function! s:base.cmap(lhs, rhs)
|
||||
let self.variables.keymapping[a:lhs] = a:rhs
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.cnoremap(lhs, rhs)
|
||||
let self.variables.keymapping[a:lhs] = {
|
||||
\ "key" : a:rhs,
|
||||
\ "noremap" : 1,
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.cunmap(lhs)
|
||||
unlet self.variables.keymapping[a:lhs]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.keymapping()
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
@ -207,10 +223,10 @@ function! s:base.exit(...)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.cancel()
|
||||
call self.exit(1)
|
||||
call self._on_cancel()
|
||||
endfunction
|
||||
" function! s:base.cancel()
|
||||
" call self.exit(1)
|
||||
" call self._on_cancel()
|
||||
" endfunction
|
||||
|
||||
|
||||
function! s:base.exit_code()
|
||||
@ -218,6 +234,46 @@ function! s:base.exit_code()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.hl_cursor_on()
|
||||
if exists("self.variables.old_hi_cursor")
|
||||
execute "highlight Cursor " . self.variables.old_hi_cursor
|
||||
unlet self.variables.old_hi_cursor
|
||||
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_hi_cursor")
|
||||
return self.variables.old_hi_cursor
|
||||
endif
|
||||
let self.variables.old_hi_cursor = "cterm=reverse"
|
||||
if hlexists("Cursor")
|
||||
let save_verbose = &verbose
|
||||
let &verbose = 0
|
||||
try
|
||||
redir => cursor
|
||||
silent highlight Cursor
|
||||
redir END
|
||||
finally
|
||||
let &verbose = save_verbose
|
||||
endtry
|
||||
let hl = substitute(matchstr(cursor, 'xxx \zs.*'), '[ \t\n]\+\|cleared', ' ', 'g')
|
||||
if !empty(substitute(hl, '\s', '', 'g'))
|
||||
let self.variables.old_hi_cursor = hl
|
||||
endif
|
||||
highlight Cursor NONE
|
||||
endif
|
||||
let self.variables.old_t_ve = &t_ve
|
||||
set t_ve=
|
||||
|
||||
return self.variables.old_hi_cursor
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.start(...)
|
||||
let exit_code = call(self._main, a:000, self)
|
||||
if exit_code == 0
|
||||
@ -236,25 +292,23 @@ endfunction
|
||||
|
||||
|
||||
function! s:base._init()
|
||||
let self.variables.wait_key = ""
|
||||
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 hl_cursor = s:_hl_cursor_off()
|
||||
let hl_cursor = self.hl_cursor_off()
|
||||
if !hlexists("OverCommandLineDefaultCursor")
|
||||
execute "highlight OverCommandLineDefaultCursor " . hl_cursor
|
||||
endif
|
||||
if !hlexists("OverCommandLineDefaultCursorInsert")
|
||||
execute "highlight OverCommandLineDefaultCursorInsert " . hl_cursor . " term=underline gui=underline"
|
||||
endif
|
||||
let s:old_t_ve = &t_ve
|
||||
set t_ve=
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base._execute()
|
||||
call s:_redraw()
|
||||
call s:redraw()
|
||||
call self._on_execute_pre()
|
||||
try
|
||||
call self.execute()
|
||||
@ -272,13 +326,15 @@ endfunction
|
||||
function! s:base._main(...)
|
||||
try
|
||||
call self._init()
|
||||
let self.line = deepcopy(s:_string_with_pos(get(a:, 1, "")))
|
||||
let self.line = deepcopy(s:String.make(get(a:, 1, "")))
|
||||
call self._on_enter()
|
||||
|
||||
while !self._is_exit()
|
||||
call s:_echo_cmdline(self)
|
||||
|
||||
let self.variables.char = s:_getchar()
|
||||
let self.variables.input_key = s:_getchar()
|
||||
let self.variables.char = s:_unmap(self._get_keymapping(), self.variables.input_key)
|
||||
|
||||
call self.setchar(self.variables.char)
|
||||
|
||||
call self._on_char_pre()
|
||||
@ -287,23 +343,23 @@ function! s:base._main(...)
|
||||
endwhile
|
||||
catch
|
||||
echohl ErrorMsg | echo v:throwpoint . " " . v:exception | echohl None
|
||||
return -1
|
||||
finally
|
||||
call self._finish()
|
||||
call self._on_leave()
|
||||
call s:_redraw()
|
||||
endtry
|
||||
call s:redraw()
|
||||
return self.exit_code()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base._finish()
|
||||
cal s:_hl_cursor_on()
|
||||
let &t_ve = s:old_t_ve
|
||||
call self.hl_cursor_on()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_echo_cmdline(cmdline)
|
||||
call s:_redraw()
|
||||
call s:redraw()
|
||||
execute "echohl" a:cmdline.highlights.prompt
|
||||
echon a:cmdline.prompt
|
||||
echohl NONE
|
||||
@ -325,22 +381,43 @@ function! s:base._is_exit()
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
for s:i in range(len(s:modules_snake))
|
||||
execute join([
|
||||
\ "function! s:module_" . s:modules_snake[s:i] . "(...)",
|
||||
\ " return call(s:" . s:modules[s:i] . ".make, a:000, s:" . s:modules[s:i] . ")",
|
||||
\ "endfunction",
|
||||
\ ], "\n")
|
||||
endfor
|
||||
unlet s:i
|
||||
|
||||
function! s:module_no_insert_special_chars()
|
||||
return s:NoInsert.make_special_chars()
|
||||
function! s:_as_key_config(config)
|
||||
let base = {
|
||||
\ "noremap" : 0,
|
||||
\ "lock" : 0,
|
||||
\ }
|
||||
return type(a:config) == type({}) ? extend(base, a:config)
|
||||
\ : extend(base, {
|
||||
\ "key" : a:config,
|
||||
\ })
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_redraw()
|
||||
function! s:_unmap(mapping, key)
|
||||
if !has_key(a:mapping, a:key)
|
||||
return a:key
|
||||
endif
|
||||
let rhs = s:_as_key_config(a:mapping[a:key])
|
||||
let next = s:_as_key_config(get(a:mapping, rhs.key, {}))
|
||||
if rhs.noremap && next.lock == 0
|
||||
return rhs.key
|
||||
endif
|
||||
return s:_unmap(a:mapping, rhs.key)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base._get_keymapping()
|
||||
let result = {}
|
||||
for module in values(self.variables.modules)
|
||||
if has_key(module, "keymapping")
|
||||
call extend(result, module.keymapping(self))
|
||||
endif
|
||||
endfor
|
||||
return extend(extend(result, self.variables.keymapping), self.keymapping())
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:redraw()
|
||||
redraw
|
||||
echo ""
|
||||
endfunction
|
||||
@ -352,131 +429,5 @@ function! s:_getchar()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_hl_cursor_on()
|
||||
if exists("s:old_hi_cursor")
|
||||
execute "highlight Cursor " . s:old_hi_cursor
|
||||
unlet s:old_hi_cursor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_hl_cursor_off()
|
||||
if exists("s:old_hi_cursor")
|
||||
return s:old_hi_cursor
|
||||
endif
|
||||
let s:old_hi_cursor = "cterm=reverse"
|
||||
if hlexists("Cursor")
|
||||
let save_verbose = &verbose
|
||||
let &verbose = 0
|
||||
try
|
||||
redir => cursor
|
||||
silent highlight Cursor
|
||||
redir END
|
||||
finally
|
||||
let &verbose = save_verbose
|
||||
endtry
|
||||
let hl = substitute(matchstr(cursor, 'xxx \zs.*'), '[ \t\n]\+\|cleared', ' ', 'g')
|
||||
if !empty(substitute(hl, '\s', '', 'g'))
|
||||
let s:old_hi_cursor = hl
|
||||
endif
|
||||
highlight Cursor NONE
|
||||
endif
|
||||
return s:old_hi_cursor
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_clamp(x, max, min)
|
||||
return min([max([a:x, a:max]), a:min])
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_string_with_pos(...)
|
||||
let default = get(a:, 1, "")
|
||||
let self = {}
|
||||
|
||||
function! self.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! self.str()
|
||||
return join(self.list, "")
|
||||
endfunction
|
||||
|
||||
function! self.set_pos(pos)
|
||||
let self.col = s:_clamp(a:pos, 0, self.length())
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! self.backward()
|
||||
return self.col > 0 ? join(self.list[ : self.col-1], '') : ""
|
||||
endfunction
|
||||
|
||||
function! self.forward()
|
||||
return join(self.list[self.col+1 : ], '')
|
||||
endfunction
|
||||
|
||||
function! self.pos_word()
|
||||
return get(self.list, self.col, "")
|
||||
endfunction
|
||||
|
||||
function! self.set_str(str)
|
||||
let self.list = split(a:str, '\zs')
|
||||
let self.col = strchars(a:str)
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! self.pos()
|
||||
return self.col
|
||||
endfunction
|
||||
|
||||
function! self.input(str)
|
||||
call extend(self.list, split(a:str, '\zs'), self.col)
|
||||
let self.col += len(split(a:str, '\zs'))
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! self.length()
|
||||
return len(self.list)
|
||||
endfunction
|
||||
|
||||
function! self.next()
|
||||
return self.set_pos(self.col + 1)
|
||||
endfunction
|
||||
|
||||
function! self.prev()
|
||||
return self.set_pos(self.col - 1)
|
||||
endfunction
|
||||
|
||||
function! self.remove(index)
|
||||
if a:index < 0 || self.length() <= a:index
|
||||
return self
|
||||
endif
|
||||
unlet self.list[a:index]
|
||||
if a:index < self.col
|
||||
call self.set(self.col - 1)
|
||||
endif
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! self.remove_pos()
|
||||
return self.remove(self.col)
|
||||
endfunction
|
||||
|
||||
function! self.remove_prev()
|
||||
return self.remove(self.col - 1)
|
||||
endfunction
|
||||
|
||||
function! self.remove_next()
|
||||
return self.remove(self.col + 1)
|
||||
endfunction
|
||||
|
||||
call self.set(default)
|
||||
return self
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -105,7 +105,7 @@ function! s:module.on_char_pre(cmdline)
|
||||
return
|
||||
endif
|
||||
call a:cmdline.setchar('')
|
||||
call a:cmdline.wait_keyinput_on("Completion")
|
||||
call a:cmdline.tap_keyinput("Completion")
|
||||
elseif a:cmdline.is_input("<Over>(buffer-complete)", "Completion")
|
||||
\ || a:cmdline.is_input("\<Right>", "Completion")
|
||||
call a:cmdline.setchar('')
|
||||
@ -120,7 +120,7 @@ function! s:module.on_char_pre(cmdline)
|
||||
let s:count = len(s:complete_list) - 1
|
||||
endif
|
||||
else
|
||||
if a:cmdline.wait_keyinput_off("Completion")
|
||||
if a:cmdline.untap_keyinput("Completion")
|
||||
call a:cmdline._on_char_pre()
|
||||
endif
|
||||
call s:_finish()
|
||||
@ -132,7 +132,7 @@ function! s:module.on_char_pre(cmdline)
|
||||
let &statusline = s:_as_statusline(s:complete_list, s:count)
|
||||
endif
|
||||
if len(s:complete_list) == 1
|
||||
call a:cmdline.wait_keyinput_off("Completion")
|
||||
call a:cmdline.untap_keyinput("Completion")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -11,7 +11,8 @@ function! s:module.on_char_pre(cmdline)
|
||||
\ || a:cmdline.is_input("\<C-c>")
|
||||
\ ||(a:cmdline.is_input("\<BS>") && a:cmdline.line.length() == 0)
|
||||
\ ||(a:cmdline.is_input("\<C-h>") && a:cmdline.line.length() == 0)
|
||||
call a:cmdline.cancel()
|
||||
" call a:cmdline.cancel()
|
||||
call a:cmdline.exit(1)
|
||||
call a:cmdline.setchar("")
|
||||
endif
|
||||
endfunction
|
||||
|
@ -0,0 +1,72 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
augroup vital-over-commandline-doautocmd-dummy
|
||||
autocmd!
|
||||
augroup END
|
||||
|
||||
|
||||
let s:cache_command = {}
|
||||
function! s:doautocmd_user(command)
|
||||
if !has_key(s:cache_command, a:command)
|
||||
execute "autocmd vital-over-commandline-doautocmd-dummy"
|
||||
\ . " User " . a:command." silent! execute ''"
|
||||
|
||||
if v:version > 703 || v:version == 703 && has("patch438")
|
||||
let s:cache_command[a:command] = "doautocmd <nomodeline> User " . a:command
|
||||
else
|
||||
let s:cache_command[a:command] = "doautocmd User " . a:command
|
||||
endif
|
||||
endif
|
||||
|
||||
execute s:cache_command[a:command]
|
||||
endfunction
|
||||
|
||||
let s:hooks = [
|
||||
\ "enter",
|
||||
\ "leave",
|
||||
\ "char",
|
||||
\ "char_pre",
|
||||
\ "execute_pre",
|
||||
\ "execute_failed",
|
||||
\ "execute",
|
||||
\ "cancel"
|
||||
\]
|
||||
|
||||
let s:hooks_camel = [
|
||||
\ "Enter",
|
||||
\ "Leave",
|
||||
\ "Char",
|
||||
\ "CharPre",
|
||||
\ "ExecutePre",
|
||||
\ "ExecuteFailed",
|
||||
\ "Execute",
|
||||
\ "Cancel"
|
||||
\]
|
||||
|
||||
|
||||
let s:module = {
|
||||
\ "name" : "Doautocmd",
|
||||
\}
|
||||
|
||||
|
||||
for s:i in range(len(s:hooks))
|
||||
execute join([
|
||||
\ "function! s:module.on_" . s:hooks[s:i] . "(...)",
|
||||
\ " call s:doautocmd_user(self.prefix . " . string(s:hooks_camel[s:i]) . ")",
|
||||
\ "endfunction",
|
||||
\ ], "\n")
|
||||
endfor
|
||||
|
||||
|
||||
function! s:make(prefix)
|
||||
let module = deepcopy(s:module)
|
||||
let module.prefix = a:prefix
|
||||
return module
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,67 +0,0 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
|
||||
let s:module = {
|
||||
\ "name" : "Incsearch",
|
||||
\ "highlights" : {
|
||||
\ "incserach" : "IncSearch"
|
||||
\ },
|
||||
\ "pattern" : "",
|
||||
\ "search_flag" : "",
|
||||
\ "mode" : "",
|
||||
\}
|
||||
|
||||
|
||||
function! s:module.search_hl_off()
|
||||
if exists("self.search_hl_id")
|
||||
call matchdelete(self.search_hl_id)
|
||||
unlet self.search_hl_id
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:module.search_hl_on(pattern)
|
||||
call self.search_hl_off()
|
||||
let self.search_hl_id = matchadd(self.highlights.incserach, a:pattern)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:module.on_enter(...)
|
||||
let self.old_pos = getpos(".")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:module.on_leave(...)
|
||||
call setpos(".", self.old_pos)
|
||||
call self.search_hl_off()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:module.on_char(cmdline)
|
||||
call self.search_hl_off()
|
||||
let line = a:cmdline.getline()
|
||||
let result = get(matchlist(line, self.pattern), 1, "")
|
||||
if result != ""
|
||||
let pos = searchpos(result, self.search_flag)
|
||||
if pos == [0, 0]
|
||||
return
|
||||
endif
|
||||
call self.search_hl_on('\%' . pos[0] . 'l' . (&ignorecase ? '\c' : "") . result)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:make(...)
|
||||
let module = deepcopy(s:module)
|
||||
let module.mode = get(a:, 1, "/")
|
||||
let module.pattern = get(a:, 2, '^\(.\+\)')
|
||||
let module.search_flag = get(a:, 3, 'c')
|
||||
return module
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -0,0 +1,87 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
|
||||
function! s:to_string(expr)
|
||||
return type(a:expr) == type("") ? a:expr : string(a:expr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:input(cmdline)
|
||||
call a:cmdline.hl_cursor_on()
|
||||
try
|
||||
redraw
|
||||
let input = input("=", "", "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.on_enter(...)
|
||||
let self.cword = expand("<cword>")
|
||||
let self.cWORD = expand("cWORD")
|
||||
let self.cfile = expand("<cfile>")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:module.on_char_pre(cmdline)
|
||||
if a:cmdline.is_input("\<C-r>")
|
||||
call a:cmdline.setchar('"')
|
||||
call a:cmdline.tap_keyinput("InsertRegister")
|
||||
let self.old_line = a:cmdline.getline()
|
||||
let self.old_pos = a:cmdline.getpos()
|
||||
return
|
||||
elseif a:cmdline.get_tap_key() == "InsertRegister"
|
||||
call a:cmdline.setline(self.old_line)
|
||||
call a:cmdline.setpos(self.old_pos)
|
||||
let char = a:cmdline.char()
|
||||
if char =~ '^[0-9a-zA-z.%#:/"\-*]$'
|
||||
execute "let regist = @" . char
|
||||
call a:cmdline.setchar(regist)
|
||||
elseif a:cmdline.is_input('=', "InsertRegister")
|
||||
call a:cmdline.setchar(s:input(a:cmdline))
|
||||
elseif a:cmdline.is_input("\<C-w>", "InsertRegister")
|
||||
call a:cmdline.setchar(self.cword)
|
||||
elseif a:cmdline.is_input("\<C-a>", "InsertRegister")
|
||||
call a:cmdline.setchar(self.cWORD)
|
||||
elseif a:cmdline.is_input("\<C-f>", "InsertRegister")
|
||||
call a:cmdline.setchar(self.cfile)
|
||||
elseif a:cmdline.is_input("\<C-r>", "InsertRegister")
|
||||
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>", "InsertRegister")
|
||||
call a:cmdline.setpos(a:cmdline.getpos()-1)
|
||||
else
|
||||
call a:cmdline.untap_keyinput("InsertRegister")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:make()
|
||||
return deepcopy(s:module)
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -0,0 +1,62 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
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,
|
||||
\ },
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make_emacs()
|
||||
return deepcopy(s:emacs)
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
101
autoload/vital/_easymotion/Over/String.vim
Normal file
101
autoload/vital/_easymotion/Over/String.vim
Normal file
@ -0,0 +1,101 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
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_word()
|
||||
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 self
|
||||
endif
|
||||
unlet self.list[a:index]
|
||||
if a:index < self.col
|
||||
call self.set(self.col - 1)
|
||||
endif
|
||||
return self
|
||||
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
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,4 +1,8 @@
|
||||
easymotion
|
||||
2b8ba7f
|
||||
39d8e9c
|
||||
|
||||
Over.Commandline
|
||||
Over.Commandline.Modules.BufferComplete
|
||||
Over.Commandline.Modules.Paste
|
||||
Over.Commandline.Modules.KeyMapping
|
||||
Over.Commandline.Modules.Doautocmd
|
||||
|
@ -1,4 +1,4 @@
|
||||
*easymotion.txt* Version 2.0 Last change:02 Feb 2014.
|
||||
*easymotion.txt* Version 2.0 Last change:06 Feb 2014.
|
||||
|
||||
|
||||
______ __ ___ __ _
|
||||
@ -504,6 +504,8 @@ Find Motion Command Line~
|
||||
|
||||
https://github.com/osyo-manga/vim-over
|
||||
|
||||
Library: https://github.com/osyo-manga/vital-over
|
||||
|
||||
Note: These settings are experimental. They could be changed in the near
|
||||
future.
|
||||
|
||||
@ -515,19 +517,21 @@ Find Motion Command Line~
|
||||
----------------------- |----------------------------------------------
|
||||
<CR> | Execute EasyMotion.
|
||||
<ESC> or <C-c> | Cancel
|
||||
<Right> | Cursor right
|
||||
<Left> | Cursor left
|
||||
<Home> or <C-b> | cursor to beginning of command-line
|
||||
<Right> or <C-f> | Cursor right
|
||||
<Left> or <C-b> | Cursor left
|
||||
<Home> or <C-a> | cursor to beginning of command-line
|
||||
<End> or <C-e> | cursor to end of command-line
|
||||
<BS> or <C-h> | Delete one character
|
||||
<C-d> | Delete one character at the cursor pos
|
||||
<C-w> | Delete the word before the cursor
|
||||
<C-u> | Delete all entered characters before the cursor
|
||||
<Up> | Recall older (previous) search from history
|
||||
<Down> | Recall more recent (next) search from history
|
||||
<Up> or <C-p> | Recall older (previous) search from history
|
||||
<Down> or <C-n> | Recall more recent (next) search from history
|
||||
<C-r> {0-9a-z"%#:-=.} | Insert Register. See |c_Ctrl-R|
|
||||
------------------------|---------------------------------------
|
||||
<Over>(paste) | Paste yanked text to the command line
|
||||
| Default: <C-v>
|
||||
<Over>(buffer-complete) | Completion of buffer text Default: <C-d>
|
||||
<Over>(buffer-complete) | Completion of buffer text Default: <C-l>
|
||||
*<Over>(em-scroll-f)* | Scroll window forward & jump to the next match
|
||||
| Default: <Tab>
|
||||
*<Over>(em-scroll-b)* | Scroll window backward & jump to previous match
|
||||
@ -538,21 +542,30 @@ Find Motion Command Line~
|
||||
| Default: <C-z>
|
||||
|
||||
Customize Command Line Mappings~
|
||||
*EMCommandLineNoremap*
|
||||
*EMCommandLineNoreMap*
|
||||
|
||||
You can use |EMCommandLineNoremap| to customize find motion command line
|
||||
key mappings by vimrc. This mapping is always no recursive mapping, so
|
||||
you should map to not <Tab> but <Over>(em-scroll-f).
|
||||
You can use |EMCommandLineNoreMap| (like |cnoremap|) to customize find motion
|
||||
command line key mappings by vimrc. This mapping is always no recursive
|
||||
mapping, so you should map to not <Tab> but |<Over>(em-scroll-f)|.
|
||||
|
||||
Example:
|
||||
>
|
||||
" EM is short for EasyMotion
|
||||
EMCommandLineNoremap <C-;> <CR>
|
||||
EMCommandLineNoremap <C-f> <Right>
|
||||
EMCommandLineNoremap <C-b> <Left>
|
||||
EMCommandLineNoremap <C-a> <Home>
|
||||
EMCommandLineNoremap <C-l> <Over>(buffer-complete)
|
||||
" == EM is short for EasyMotion
|
||||
" Enter by <Space> to excute faster & easily
|
||||
EMCommandLineNoreMap <Space> <CR>
|
||||
EMCommandLineNoreMap <C-j> <Space>
|
||||
" Enter by `;` to excute faster & easily
|
||||
EMCommandLineNoreMap ; <CR>
|
||||
EMCommandLineNoreMap <C-j> ;
|
||||
" Buffer Completion with Ctrl-D
|
||||
EMCommandLineNoreMap <C-d> <Over>(buffer-complete)
|
||||
<
|
||||
*EMCommandLineMap*
|
||||
*EMCommandLineUnMap*
|
||||
EasyMotion also provide |EMCommandLineMap| (like |cmap|) and
|
||||
|EMCommandLineUnMap| (like |cunmap|) command, but probably you don't need
|
||||
these command because there is no case it require recursive mappings.
|
||||
|
||||
Note(again): These settings, especially about keymappings are
|
||||
__EXPERIMENTAL__. They could be changed in the near future. However, it
|
||||
works well and so useful, so I release it.
|
||||
|
@ -3,7 +3,7 @@
|
||||
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
|
||||
" haya14busa <hayabusa1419@gmail.com>
|
||||
" Source: https://github.com/Lokaltog/vim-easymotion
|
||||
" Last Change: 05 Feb 2014.
|
||||
" Last Change: 06 Feb 2014.
|
||||
" == Script initialization {{{
|
||||
if expand("%:p") ==# expand("<sfile>:p")
|
||||
unlet! g:EasyMotion_loaded
|
||||
@ -306,18 +306,15 @@ if g:EasyMotion_do_mapping == 1
|
||||
endif "}}}
|
||||
|
||||
" == CommandLine Mapping {{{
|
||||
function! s:key_mapping(lhs, rhs)
|
||||
let g:EasyMotion_command_line_key_mappings[a:lhs] = a:rhs
|
||||
endfunction
|
||||
|
||||
function! s:as_keymapping(key)
|
||||
execute 'let result = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"'
|
||||
return result
|
||||
endfunction
|
||||
|
||||
command! -nargs=*
|
||||
\ EMCommandLineNoremap
|
||||
\ call call("s:key_mapping", map([<f-args>], "s:as_keymapping(v:val)"))
|
||||
\ 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' {{{
|
||||
|
Loading…
Reference in New Issue
Block a user