Merge branch 'improve/commandline' into dev

This commit is contained in:
haya14busa 2014-02-06 19:44:30 +09:00
commit 5475bd72f6
12 changed files with 585 additions and 332 deletions

View File

@ -2,7 +2,7 @@
" FILE: autoload/EasyMotion/command_line.vim " FILE: autoload/EasyMotion/command_line.vim
" AUTHOR: haya14busa " AUTHOR: haya14busa
" Reference: https://github.com/osyo-manga/vim-over " Reference: https://github.com/osyo-manga/vim-over
" Last Change: 05 Feb 2014. " Last Change: 06 Feb 2014.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " 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" let s:search.highlights.prompt = "Question"
" Add Module: {{{ " Add Module: {{{
call s:search.connect(s:cmdline.module_delete()) call s:search.connect('Delete')
call s:search.connect(s:cmdline.module_cursor_move()) call s:search.connect('CursorMove')
call s:search.connect(s:cmdline.module_paste()) call s:search.connect('Paste')
call s:search.connect(s:cmdline.module_buffer_complete()) call s:search.connect('BufferComplete')
call s:search.connect(s:cmdline.module_history("/")) call s:search.connect('InsertRegister')
call s:search.connect(s:cmdline.module_no_insert_special_chars()) 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 = { let s:module = {
\ "name" : "EasyMotion", \ "name" : "EasyMotion",
@ -70,20 +73,51 @@ call s:search.connect(s:module)
"}}} "}}}
" CommandLine Keymap: {{{ " CommandLine Keymap: {{{
let s:default_key_mapping = { function! s:search.keymapping() "{{{
\ "\<C-d>" : "<Over>(buffer-complete)", return {
\ "\<Tab>" : "<Over>(em-scroll-f)", \ "\<C-l>" : {
\ "\<S-Tab>" : "<Over>(em-scroll-b)", \ "key" : "<Over>(buffer-complete)",
\ "\<C-o>" : "<Over>(em-jumpback)", \ "noremap" : 1,
\ "\<C-z>" : "<Over>(em-openallfold)", \ },
\} \ "\<Tab>" : {
function! EasyMotion#command_line#keymaps() "{{{ \ "key" : "<Over>(em-scroll-f)",
return extend(deepcopy(s:default_key_mapping), \ "noremap" : 1,
\ g:EasyMotion_command_line_key_mappings) \ },
endfunction "}}} \ "\<S-Tab>" : {
function! s:search.keymappings() "{{{ \ "key" : "<Over>(em-scroll-b)",
return EasyMotion#command_line#keymaps() \ "noremap" : 1,
\ },
\ "\<C-o>" : {
\ "key" : "<Over>(em-jumpback)",
\ "noremap" : 1,
\ },
\ "\<C-z>" : {
\ "key" : "<Over>(em-openallfold)",
\ "noremap" : 1,
\ },
\ }
endfunction "}}} 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: {{{ " Event: {{{
@ -117,11 +151,6 @@ function! s:search.on_char() "{{{
call s:search.exit() call s:search.exit()
endif endif
endfunction "}}} endfunction "}}}
function! s:search.on_cancel() "{{{
call s:Cancell()
call s:search.setline('')
endfunction "}}}
"}}}
" Main: " Main:
function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{ 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() let input = s:search.get()
if input == '' && ! s:search.exit_code() if input == '' && ! s:search.exit_code()
return a:prev return a:prev
elseif s:search.exit_code() == 1 " cancelled
call s:Cancell()
return ''
else else
return input return input
endif endif

View File

@ -7,28 +7,12 @@ let s:modules = [
\ "Scroll", \ "Scroll",
\ "CursorMove", \ "CursorMove",
\ "Delete", \ "Delete",
\ "Paste",
\ "HistAdd", \ "HistAdd",
\ "History", \ "History",
\ "Incsearch",
\ "BufferComplete",
\ "Cancel", \ "Cancel",
\ "Enter", \ "Enter",
\ "NoInsert", \ "NoInsert",
\] \ "InsertRegister",
let s:modules_snake = [
\ "scroll",
\ "cursor_move",
\ "delete",
\ "paste",
\ "histadd",
\ "history",
\ "incsearch",
\ "buffer_complete",
\ "cancel",
\ "enter",
\ "no_insert",
\] \]
@ -37,60 +21,67 @@ function! s:_vital_loaded(V)
for module in s:modules for module in s:modules
let s:{module} = s:V.import('Over.Commandline.Modules.' . module) let s:{module} = s:V.import('Over.Commandline.Modules.' . module)
endfor endfor
let s:String = s:V.import("Over.String")
endfunction endfunction
function! s:_vital_depends() 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 endfunction
function! s:make_plain(prompt) function! s:make_plain(prompt)
let result = deepcopy(s:base) let result = s:make(a:prompt)
let result.prompt = a:prompt let result.prompt = a:prompt
call result.connect(s:module_cancel()) call result.connect("Enter")
call result.connect(s:module_enter()) call result.connect("Cancel")
return result return result
endfunction endfunction
function! s:make_simple(prompt) function! s:make_standard(prompt)
let result = s:make_plain(a:prompt) let result = s:make_plain(a:prompt)
call result.connect(s:module_scroll()) call result.connect("Delete")
call result.connect(s:module_delete()) call result.connect("CursorMove")
call result.connect(s:module_cursor_move()) call result.connect("HistAdd")
call result.connect(s:module_histadd()) call result.connect("History")
call result.connect(s:module_history()) call result.connect("InsertRegister")
call result.connect(s:module_buffer_complete()) call result.connect(s:get_module("NoInsert").make_special_chars())
call result.connect(s:module_no_insert_special_chars())
return result return result
endfunction endfunction
function! s:make(prompt) function! s:make(prompt)
return s:make_simple(a:prompt) return deepcopy(s:base)
endfunction endfunction
let s:base = { let s:base = {
\ "prompt" : "> ", \ "prompt" : "",
\ "line" : {}, \ "line" : {},
\ "variables" : { \ "variables" : {
\ "char" : "", \ "char" : "",
\ "input" : "", \ "input" : "",
\ "wait_key" : "", \ "tap_key" : "",
\ "exit" : 0, \ "exit" : 0,
\ "keymapping" : {},
\ "modules" : {},
\ }, \ },
\ "highlights" : { \ "highlights" : {
\ "prompt" : "NONE", \ "prompt" : "NONE",
\ "cursor" : "OverCommandLineDefaultCursor", \ "cursor" : "OverCommandLineDefaultCursor",
\ "cursor_insert" : "OverCommandLineDefaultCursorInsert" \ "cursor_insert" : "OverCommandLineDefaultCursorInsert"
\ }, \ },
\ "modules" : {},
\ "keys" : {
\ "quit" : "\<Esc>",
\ "enter" : "\<CR>",
\ }
\} \}
@ -120,32 +111,37 @@ endfunction
function! s:base.setpos(pos) function! s:base.setpos(pos)
return self.line.set_pos(pos) return self.line.set_pos(a:pos)
endfunction endfunction
function! s:base.wait_keyinput_on(key) function! s:base.tap_keyinput(key)
let self.variables.wait_key = a:key let self.variables.tap_key = a:key
endfunction endfunction
function! s:base.wait_keyinput_off(key) function! s:base.untap_keyinput(key)
if self.variables.wait_key == a:key if self.variables.tap_key == a:key
let self.variables.wait_key = "" let self.variables.tap_key = ""
return 1 return 1
endif endif
endfunction endfunction
function! s:base.get_wait_keyinput() function! s:base.get_tap_key()
return self.variables.wait_key return self.variables.tap_key
endfunction endfunction
function! s:base.is_input(key, ...) function! s:base.is_input(key, ...)
let prekey = get(a:, 1, "") let prekey = get(a:, 1, "")
return self.get_wait_keyinput() == prekey return self.get_tap_key() == prekey
\ && get(self.keymappings(), self.char(), self.char()) == a:key \ && self.char() == a:key
endfunction
function! s:base.input_key()
return self.variables.input_key
endfunction endfunction
@ -166,20 +162,23 @@ endfunction
function! s:base.connect(module, ...) 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 name = get(a:, 1, a:module.name)
let self.modules[name] = a:module let self.variables.modules[name] = a:module
endfunction endfunction
function! s:base.disconnect(name) function! s:base.disconnect(name)
unlet self.modules[a:name] = a:module unlet self.variables.modules[a:name] = a:module
endfunction endfunction
for s:_ in ["enter", "leave", "char", "char_pre", "execute_pre", "execute_failed", "execute", "cancel"] for s:_ in ["enter", "leave", "char", "char_pre", "execute_pre", "execute_failed", "execute", "cancel"]
execute join([ execute join([
\ "function! s:base._on_" . s:_ . "()", \ "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:_ . "()", \ " call self.on_" . s:_ . "()",
\ "endfunction", \ "endfunction",
\ ], "\n") \ ], "\n")
@ -190,8 +189,25 @@ endfor
unlet s:_ unlet s:_
" Overridable function! s:base.cmap(lhs, rhs)
function! s:base.keymappings() 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 {} return {}
endfunction endfunction
@ -207,10 +223,10 @@ function! s:base.exit(...)
endfunction endfunction
function! s:base.cancel() " function! s:base.cancel()
call self.exit(1) " call self.exit(1)
call self._on_cancel() " call self._on_cancel()
endfunction " endfunction
function! s:base.exit_code() function! s:base.exit_code()
@ -218,6 +234,46 @@ function! s:base.exit_code()
endfunction 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(...) function! s:base.start(...)
let exit_code = call(self._main, a:000, self) let exit_code = call(self._main, a:000, self)
if exit_code == 0 if exit_code == 0
@ -236,25 +292,23 @@ endfunction
function! s:base._init() function! s:base._init()
let self.variables.wait_key = "" let self.variables.tap_key = ""
let self.variables.char = "" let self.variables.char = ""
let self.variables.input = "" let self.variables.input = ""
let self.variables.exit = 0 let self.variables.exit = 0
let self.variables.exit_code = 1 let self.variables.exit_code = 1
let hl_cursor = s:_hl_cursor_off() let hl_cursor = self.hl_cursor_off()
if !hlexists("OverCommandLineDefaultCursor") if !hlexists("OverCommandLineDefaultCursor")
execute "highlight OverCommandLineDefaultCursor " . hl_cursor execute "highlight OverCommandLineDefaultCursor " . hl_cursor
endif endif
if !hlexists("OverCommandLineDefaultCursorInsert") if !hlexists("OverCommandLineDefaultCursorInsert")
execute "highlight OverCommandLineDefaultCursorInsert " . hl_cursor . " term=underline gui=underline" execute "highlight OverCommandLineDefaultCursorInsert " . hl_cursor . " term=underline gui=underline"
endif endif
let s:old_t_ve = &t_ve
set t_ve=
endfunction endfunction
function! s:base._execute() function! s:base._execute()
call s:_redraw() call s:redraw()
call self._on_execute_pre() call self._on_execute_pre()
try try
call self.execute() call self.execute()
@ -272,13 +326,15 @@ endfunction
function! s:base._main(...) function! s:base._main(...)
try try
call self._init() 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() call self._on_enter()
while !self._is_exit() while !self._is_exit()
call s:_echo_cmdline(self) 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.setchar(self.variables.char)
call self._on_char_pre() call self._on_char_pre()
@ -287,23 +343,23 @@ function! s:base._main(...)
endwhile endwhile
catch catch
echohl ErrorMsg | echo v:throwpoint . " " . v:exception | echohl None echohl ErrorMsg | echo v:throwpoint . " " . v:exception | echohl None
return -1
finally finally
call self._finish() call self._finish()
call self._on_leave() call self._on_leave()
call s:_redraw()
endtry endtry
call s:redraw()
return self.exit_code() return self.exit_code()
endfunction endfunction
function! s:base._finish() function! s:base._finish()
cal s:_hl_cursor_on() call self.hl_cursor_on()
let &t_ve = s:old_t_ve
endfunction endfunction
function! s:_echo_cmdline(cmdline) function! s:_echo_cmdline(cmdline)
call s:_redraw() call s:redraw()
execute "echohl" a:cmdline.highlights.prompt execute "echohl" a:cmdline.highlights.prompt
echon a:cmdline.prompt echon a:cmdline.prompt
echohl NONE echohl NONE
@ -325,22 +381,43 @@ function! s:base._is_exit()
endfunction endfunction
function! s:_as_key_config(config)
for s:i in range(len(s:modules_snake)) let base = {
execute join([ \ "noremap" : 0,
\ "function! s:module_" . s:modules_snake[s:i] . "(...)", \ "lock" : 0,
\ " return call(s:" . s:modules[s:i] . ".make, a:000, s:" . s:modules[s:i] . ")", \ }
\ "endfunction", return type(a:config) == type({}) ? extend(base, a:config)
\ ], "\n") \ : extend(base, {
endfor \ "key" : a:config,
unlet s:i \ })
function! s:module_no_insert_special_chars()
return s:NoInsert.make_special_chars()
endfunction 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 redraw
echo "" echo ""
endfunction endfunction
@ -352,131 +429,5 @@ function! s:_getchar()
endfunction 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 let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo

View File

@ -105,7 +105,7 @@ function! s:module.on_char_pre(cmdline)
return return
endif endif
call a:cmdline.setchar('') 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") elseif a:cmdline.is_input("<Over>(buffer-complete)", "Completion")
\ || a:cmdline.is_input("\<Right>", "Completion") \ || a:cmdline.is_input("\<Right>", "Completion")
call a:cmdline.setchar('') call a:cmdline.setchar('')
@ -120,7 +120,7 @@ function! s:module.on_char_pre(cmdline)
let s:count = len(s:complete_list) - 1 let s:count = len(s:complete_list) - 1
endif endif
else else
if a:cmdline.wait_keyinput_off("Completion") if a:cmdline.untap_keyinput("Completion")
call a:cmdline._on_char_pre() call a:cmdline._on_char_pre()
endif endif
call s:_finish() call s:_finish()
@ -132,7 +132,7 @@ function! s:module.on_char_pre(cmdline)
let &statusline = s:_as_statusline(s:complete_list, s:count) let &statusline = s:_as_statusline(s:complete_list, s:count)
endif endif
if len(s:complete_list) == 1 if len(s:complete_list) == 1
call a:cmdline.wait_keyinput_off("Completion") call a:cmdline.untap_keyinput("Completion")
endif endif
endfunction endfunction

View File

@ -11,7 +11,8 @@ function! s:module.on_char_pre(cmdline)
\ || a:cmdline.is_input("\<C-c>") \ || a:cmdline.is_input("\<C-c>")
\ ||(a:cmdline.is_input("\<BS>") && a:cmdline.line.length() == 0) \ ||(a:cmdline.is_input("\<BS>") && a:cmdline.line.length() == 0)
\ ||(a:cmdline.is_input("\<C-h>") && 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("") call a:cmdline.setchar("")
endif endif
endfunction endfunction

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View 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

View File

@ -1,4 +1,8 @@
easymotion easymotion
2b8ba7f 39d8e9c
Over.Commandline Over.Commandline
Over.Commandline.Modules.BufferComplete
Over.Commandline.Modules.Paste
Over.Commandline.Modules.KeyMapping
Over.Commandline.Modules.Doautocmd

View File

@ -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 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 Note: These settings are experimental. They could be changed in the near
future. future.
@ -515,19 +517,21 @@ Find Motion Command Line~
----------------------- |---------------------------------------------- ----------------------- |----------------------------------------------
<CR> | Execute EasyMotion. <CR> | Execute EasyMotion.
<ESC> or <C-c> | Cancel <ESC> or <C-c> | Cancel
<Right> | Cursor right <Right> or <C-f> | Cursor right
<Left> | Cursor left <Left> or <C-b> | Cursor left
<Home> or <C-b> | cursor to beginning of command-line <Home> or <C-a> | cursor to beginning of command-line
<End> or <C-e> | cursor to end of command-line <End> or <C-e> | cursor to end of command-line
<BS> or <C-h> | Delete one character <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-w> | Delete the word before the cursor
<C-u> | Delete all entered characters before the cursor <C-u> | Delete all entered characters before the cursor
<Up> | Recall older (previous) search from history <Up> or <C-p> | Recall older (previous) search from history
<Down> | Recall more recent (next) 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 <Over>(paste) | Paste yanked text to the command line
| Default: <C-v> | 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 *<Over>(em-scroll-f)* | Scroll window forward & jump to the next match
| Default: <Tab> | Default: <Tab>
*<Over>(em-scroll-b)* | Scroll window backward & jump to previous match *<Over>(em-scroll-b)* | Scroll window backward & jump to previous match
@ -538,21 +542,30 @@ Find Motion Command Line~
| Default: <C-z> | Default: <C-z>
Customize Command Line Mappings~ Customize Command Line Mappings~
*EMCommandLineNoremap* *EMCommandLineNoreMap*
You can use |EMCommandLineNoremap| to customize find motion command line You can use |EMCommandLineNoreMap| (like |cnoremap|) to customize find motion
key mappings by vimrc. This mapping is always no recursive mapping, so command line key mappings by vimrc. This mapping is always no recursive
you should map to not <Tab> but <Over>(em-scroll-f). mapping, so you should map to not <Tab> but |<Over>(em-scroll-f)|.
Example: Example:
> >
" EM is short for EasyMotion " == EM is short for EasyMotion
EMCommandLineNoremap <C-;> <CR> " Enter by <Space> to excute faster & easily
EMCommandLineNoremap <C-f> <Right> EMCommandLineNoreMap <Space> <CR>
EMCommandLineNoremap <C-b> <Left> EMCommandLineNoreMap <C-j> <Space>
EMCommandLineNoremap <C-a> <Home> " Enter by `;` to excute faster & easily
EMCommandLineNoremap <C-l> <Over>(buffer-complete) 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 Note(again): These settings, especially about keymappings are
__EXPERIMENTAL__. They could be changed in the near future. However, it __EXPERIMENTAL__. They could be changed in the near future. However, it
works well and so useful, so I release it. works well and so useful, so I release it.

View File

@ -3,7 +3,7 @@
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com> " Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
" haya14busa <hayabusa1419@gmail.com> " haya14busa <hayabusa1419@gmail.com>
" Source: https://github.com/Lokaltog/vim-easymotion " Source: https://github.com/Lokaltog/vim-easymotion
" Last Change: 05 Feb 2014. " Last Change: 06 Feb 2014.
" == Script initialization {{{ " == Script initialization {{{
if expand("%:p") ==# expand("<sfile>:p") if expand("%:p") ==# expand("<sfile>:p")
unlet! g:EasyMotion_loaded unlet! g:EasyMotion_loaded
@ -306,18 +306,15 @@ if g:EasyMotion_do_mapping == 1
endif "}}} endif "}}}
" == CommandLine Mapping {{{ " == 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=* command! -nargs=*
\ EMCommandLineNoremap \ EMCommandLineNoreMap
\ call call("s:key_mapping", map([<f-args>], "s:as_keymapping(v:val)")) \ 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' {{{ " == Restore 'cpoptions' {{{