Update vital-over

This commit is contained in:
haya14busa 2014-02-12 13:31:44 +09:00
parent 6775683ce6
commit 893fc516e0
10 changed files with 226 additions and 167 deletions

View File

@ -2,7 +2,7 @@
" FILE: autoload/EasyMotion/command_line.vim
" AUTHOR: haya14busa
" Reference: https://github.com/osyo-manga/vim-over
" Last Change: 09 Feb 2014.
" Last Change: 16 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
@ -31,20 +31,25 @@ set cpo&vim
" }}}
" CommandLine:
let s:cmdline = vital#of("easymotion").import("Over.Commandline")
let s:search = s:cmdline.make_plain("/")
let s:search.highlights.prompt = "Question"
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(s:modules.get("Execute").make_no_execute())
call s:search.connect('Cancel')
call s:search.connect('Redraw')
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'))
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",
@ -154,6 +159,7 @@ function! s:search.on_char(cmdline) "{{{
call s:search.exit()
endif
endfunction "}}}
"}}}
" Main:
function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{

View File

@ -3,26 +3,11 @@ let s:save_cpo = &cpo
set cpo&vim
let s:modules = [
\ "Scroll",
\ "CursorMove",
\ "Delete",
\ "HistAdd",
\ "History",
\ "Cancel",
\ "Enter",
\ "NoInsert",
\ "InsertRegister",
\]
function! s:_vital_loaded(V)
let s:V = a: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")
let s:Signals = s:V.import("Over.Signals")
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
@ -34,43 +19,22 @@ function! s:_vital_depends()
return [
\ "Over.String",
\ "Over.Signals",
\ ] + map(copy(s:modules), "'Over.Commandline.Modules.' . v:val")
\ "Over.Commandline.Modules",
\ ]
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 = s:make(a:prompt)
let result.prompt = a:prompt
call result.connect("Enter")
call result.connect("Cancel")
function! s:make(...)
let prompt = get(a:, 1, ":")
let result = deepcopy(s:base)
let result.prompt = prompt
call result.connect(result, "_")
return result
endfunction
function! s:make_standard(prompt)
let result = s:make_plain(a:prompt)
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 deepcopy(s:base)
function! s:make_plain()
return deepcpy(s:base)
endfunction
@ -86,9 +50,9 @@ let s:base = {
\ },
\ "highlights" : {
\ "prompt" : "NONE",
\ "cursor" : "OverCommandLineDefaultCursor",
\ "cursor_on" : "OverCommandLineDefaultCursorOn",
\ "cursor_insert" : "OverCommandLineDefaultOnCursor",
\ "cursor" : "VitalOverCommandLineCursor",
\ "cursor_on" : "VitalOverCommandLineCursorOn",
\ "cursor_insert" : "VitalOverCommandLineOnCursor",
\ },
\}
@ -100,7 +64,6 @@ if exists("s:Signals")
endif
function! s:base.getline()
return self.line.str()
endfunction
@ -116,8 +79,13 @@ function! s:base.char()
endfunction
function! s:base.setchar(char)
function! s:base.setchar(char, ...)
" 1 の場合は既に設定されていても上書きする
" 0 の場合は既に設定されていれば上書きしない
let overwrite = get(a:, 1, 1)
if overwrite || self.variables.input == self.char()
let self.variables.input = a:char
endif
endfunction
@ -180,7 +148,10 @@ endfunction
function! s:base.connect(module, ...)
if type(a:module) == type("")
return call(self.connect, [s:get_module(a:module).make()] + a:000, self)
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))
@ -201,6 +172,12 @@ function! s:base.disconnect(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])
@ -231,8 +208,10 @@ function! s:base.keymapping()
endfunction
function! s:base.execute()
execute self.getline()
function! s:base.execute(...)
let command = get(a:, 1, self.getline())
call self._execute(command)
" execute self.getline()
endfunction
@ -271,8 +250,9 @@ function! s:base.hl_cursor_off()
if exists("self.variables.old_t_ve")
return
endif
let self.variables.old_guicursor = &guicursor
set guicursor=a:-NONE
set guicursor=n:block-NONE
let self.variables.old_t_ve = &t_ve
set t_ve=
endfunction
@ -280,17 +260,25 @@ endfunction
function! s:base.start(...)
let exit_code = call(self._main, a:000, self)
if exit_code == 0
call self._execute()
endif
return exit_code
endfunction
function! s:base.__empty(...)
endfunction
function! s:base.get(...)
let exit_code = call(self._main, a:000, self)
let Old_execute = self.execute
let self.execute = self.__empty
try
let exit_code = self.start()
if exit_code == 0
return self.getline()
endif
finally
let self.execute = Old_execute
endtry
return ""
endfunction
@ -302,23 +290,22 @@ function! s:base._init()
let self.variables.exit = 0
let self.variables.exit_code = 1
call self.hl_cursor_off()
if !hlexists("OverCommandLineDefaultCursor")
highlight link OverCommandLineDefaultCursor Cursor
if !hlexists(self.highlights.cursor)
execute "highlight link " . self.highlights.cursor . " Cursor"
endif
if !hlexists("OverCommandLineDefaultCursorOn")
highlight link OverCommandLineDefaultCursorOn OverCommandLineDefaultCursor
if !hlexists(self.highlights.cursor_on)
execute "highlight link " . self.highlights.cursor_on . " " . self.highlights.cursor
endif
if !hlexists("OverCommandLineDefaultCursorInsert")
highlight OverCommandLineDefaultCursorInsert cterm=underline term=underline gui=underline
if !hlexists(self.highlights.cursor_insert)
execute "highlight " . self.highlights.cursor_insert . " cterm=underline term=underline gui=underline"
endif
endfunction
function! s:base._execute()
call s:redraw()
function! s:base._execute(command)
call self.callevent("on_execute_pre")
try
call self.execute()
execute a:command
catch
echohl ErrorMsg
echo matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze')
@ -354,7 +341,6 @@ function! s:base._main(...)
return -1
finally
call self._finish()
call s:redraw()
call self.callevent("on_leave")
endtry
return self.exit_code()

View File

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

View File

@ -1,25 +0,0 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "Enter"
\}
function! s:module.on_char_pre(cmdline)
if a:cmdline.is_input("\<CR>")
\ || a:cmdline.is_input("\<NL>")
\ || a:cmdline.is_input("\<C-j>")
call a:cmdline.exit(0)
call a:cmdline.setchar("")
endif
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,73 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
function! s:_is_input_enter(cmdline)
return a:cmdline.is_input("\<CR>")
\ || a:cmdline.is_input("\<NL>")
\ || a:cmdline.is_input("\<C-j>")
endfunction
let s:module = {
\ "name" : "Execute"
\}
function! s:module.on_char_pre(cmdline)
if s:_is_input_enter(a:cmdline)
call self.execute(a:cmdline)
call a:cmdline.setchar("")
call a:cmdline.exit(0)
endif
if a:cmdline.is_input("<Over>(execute-no-exit)")
call self.execute(a:cmdline)
call a:cmdline.setchar("")
endif
endfunction
function! s:module.execute(cmdline)
return a:cmdline.execute()
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let s:empty = deepcopy(s:module)
function! s:empty.execute(...)
endfunction
function! s:make_no_execute()
return deepcopy(s:empty)
endfunction
let s:search = deepcopy(s:module)
let s:search.prefix = "/"
function! s:search.execute(cmdline)
" let cmd = printf("call feedkeys(\"%s%s\<CR>\", 'n')", self.prefix, a:cmdline.getline())
let cmd = printf("call search('%s')", a:cmdline.getline())
call a:cmdline.execute(cmd)
let @/ = a:cmdline.getline()
let &hlsearch = &hlsearch
call feedkeys(":set hlsearch | set incsearch\<CR>", 'n')
endfunction
function! s:make_search(...)
let result = deepcopy(s:search)
let result.prefix = get(a:, 1, "/")
return result
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,23 +0,0 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "HistAdd",
\ "mode" : "cmd"
\}
function! s:module.on_leave(cmdline)
call histadd(self.mode, 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

View File

@ -15,7 +15,8 @@ endfunction
function! s:module.on_char_pre(cmdline)
if self.is_insert(a:cmdline.char())
call a:cmdline.setchar("")
\ && a:cmdline.char() == a:cmdline.variables.input
call a:cmdline.setchar("", 0)
endif
endfunction

View File

@ -0,0 +1,43 @@
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
call self.redraw(a:cmdline)
endif
endfunction
function! s:module.redraw(...)
redraw
echo ""
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,37 +0,0 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "Scroll"
\}
function! s:module.on_char_pre(cmdline)
if a:cmdline.is_input("<Over>(scroll-y)")
execute "normal! \<C-y>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-u)")
execute "normal! \<C-u>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-f)")
execute "normal! \<C-f>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-e)")
execute "normal! \<C-e>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-d)")
execute "normal! \<C-d>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-b)")
execute "normal! \<C-b>"
call a:cmdline.setchar('')
endif
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,8 +1,16 @@
easymotion
39d8e9c
Over.Commandline
Over.Commandline.Base
Over.Commandline.Modules.Cancel
Over.Commandline.Modules.Execute
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