Merge branch 'update/vital-over' into master

This commit is contained in:
haya14busa 2014-03-15 01:10:57 +09:00
commit f7f1b8ba70
10 changed files with 284 additions and 133 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: 21 Feb 2014.
" Last Change: 15 Mar 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
@ -38,14 +38,17 @@ let s:search = s:cmdline.make()
let s:search.highlights.prompt = 'Question'
" Add Module: {{{
call s:search.connect('Execute')
call s:search.connect('Exit')
call s:search.connect('Cancel')
call s:search.connect('Redraw')
call s:search.connect('DrawCommandline')
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('ExceptionExit')
call s:search.connect(s:modules.get('ExceptionMessage').make('EasyMotion: ', 'echom'))
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())
@ -100,6 +103,11 @@ function! s:search.keymapping() "{{{
\ "key" : "<Over>(em-openallfold)",
\ "noremap" : 1,
\ },
\ "\<CR>" : {
\ "key" : "<Over>(exit)",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ }
endfunction "}}}
@ -136,6 +144,8 @@ function! s:search.on_enter(cmdline) "{{{
endif
call EasyMotion#highlight#add_highlight('\%#',
\ g:EasyMotion_hl_inc_cursor)
call a:cmdline.set_suffix(printf("col:%d", a:cmdline.getpos()))
" redraw
endif
endfunction "}}}
function! s:search.on_leave(cmdline) "{{{
@ -158,6 +168,9 @@ function! s:search.on_char(cmdline) "{{{
if g:EasyMotion_off_screen_search
call s:off_screen_search(re)
endif
call a:cmdline.set_suffix(printf("col:%d", a:cmdline.getpos()))
"redraw
" throw 'vital-over excetion'
elseif s:search.line.length() >= s:num_strokes
call s:search.exit()
endif
@ -184,7 +197,7 @@ 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
elseif s:search.exit_code() == 1 || s:search.exit_code() == -1
call s:Cancell()
return ''
else
@ -243,6 +256,7 @@ function! s:off_screen_search(re) "{{{
keepjumps call setpos('.', s:orig_pos)
endif
endif
" redraw
endfunction "}}}
function! s:adjust_screen() "{{{
if s:save_direction != 'b'

View File

@ -235,6 +235,12 @@ function! s:base.execute(...)
endfunction
function! s:base.draw()
call self.callevent("on_draw_pre")
call self.callevent("on_draw")
endfunction
function! s:base.exit(...)
let self.variables.exit = 1
let self.variables.exit_code = get(a:, 1, 0)
@ -344,7 +350,8 @@ function! s:base._main(...)
call self.callevent("on_enter")
while !self._is_exit()
call s:_echo_cmdline(self)
try
call self.draw()
let self.variables.input_key = s:_getchar()
let self.variables.char = s:_unmap(self._get_keymapping(), self.variables.input_key)
@ -355,10 +362,13 @@ function! s:base._main(...)
call self.callevent("on_char_pre")
call self.insert(self.variables.input)
call self.callevent("on_char")
catch
call self.callevent("on_exception")
endtry
endwhile
catch
echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None
return -1
let self.variables.exit_code = -1
finally
call self._finish()
call self.callevent("on_leave")
@ -372,37 +382,6 @@ function! s:base._finish()
endfunction
function! s:suffix(left, suffix)
let left_len = strdisplaywidth(a:left)
let len = &columns - left_len % &columns
let len = len + (&columns * (strdisplaywidth(a:suffix) > (len - 1))) - 1
return printf("%" . len . "S", a:suffix)
endfunction
function! s:echon(expr)
echon strtrans(a:expr)
endfunction
function! s:_echo_cmdline(cmdline)
call a:cmdline.redraw()
execute "echohl" a:cmdline.highlights.prompt
call s:echon(a:cmdline.get_prompt())
echohl NONE
call s:echon(a:cmdline.backward())
if empty(a:cmdline.line.pos_word())
execute "echohl" a:cmdline.highlights.cursor
call s:echon(' ')
else
execute "echohl" a:cmdline.highlights.cursor_on
call s:echon(a:cmdline.line.pos_word())
endif
echohl NONE
call s:echon(a:cmdline.forward())
" call s:echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_word())), a:cmdline.get_suffix()))
endfunction
function! s:base._is_exit()
return self.variables.exit
endfunction
@ -446,17 +425,6 @@ function! s:base._get_keymapping()
return extend(extend(result, self.variables.keymapping), self.keymapping())
endfunction
function! s:_redraw()
" normal! :
redraw
" echo ""
endfunction
function! s:base.redraw()
call s:_redraw()
endfunction
function! s:_getchar()
let char = getchar()

View File

@ -94,15 +94,12 @@ function! s:_finish()
if exists("s:old_statusline")
let &statusline = s:old_statusline
unlet s:old_statusline
redrawstatus
endif
endfunction
function! s:module.on_char_pre(cmdline)
" echom "-----"
" echom a:cmdline.char()
" echom "Completion\<Tab>"
" echom "Completion\<Tab>" == a:cmdline.char()
if a:cmdline.is_input("<Over>(buffer-complete)")
if self.complete(a:cmdline) == -1
call s:_finish()
@ -127,7 +124,7 @@ function! s:module.on_char_pre(cmdline)
endif
else
if a:cmdline.untap_keyinput("Completion")
" call a:cmdline._on_char_pre()
call a:cmdline.callevent("on_char_pre")
endif
call s:_finish()
return
@ -136,6 +133,7 @@ function! s:module.on_char_pre(cmdline)
call a:cmdline.insert(s:complete_list[s:count], s:pos)
if len(s:complete_list) > 1
let &statusline = s:_as_statusline(s:complete_list, s:count)
redrawstatus
endif
if len(s:complete_list) == 1
call a:cmdline.untap_keyinput("Completion")
@ -143,6 +141,11 @@ function! s:module.on_char_pre(cmdline)
endfunction
function! s:module.on_draw_pre(...)
" redrawstatus
endfunction
function! s:module.on_leave(cmdline)
call s:_finish()
unlet! s:complete

View File

@ -0,0 +1,140 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "DrawCommandline"
\}
let s:cmdheight = {}
function! s:cmdheight.save()
if has_key(self, "value")
return
endif
let self.value = &cmdheight
endfunction
function! s:cmdheight.restore()
if has_key(self, "value")
let &cmdheight = self.value
unlet self.value
endif
endfunction
function! s:cmdheight.get()
return self.value
endfunction
function! s:suffix(left, suffix)
let left_len = strdisplaywidth(a:left)
let len = &columns - left_len % &columns
let len = len + (&columns * (strdisplaywidth(a:suffix) > (len - 1))) - 1
return repeat(" ", len - strdisplaywidth(a:suffix)) . a:suffix
" return printf("%" . len . "S", a:suffix)
endfunction
let s:old_width = 0
function! s:_redraw(cmdline)
let left = a:cmdline.get_prompt() . a:cmdline.getline() . (empty(a:cmdline.line.pos_word()) ? " " : "")
let width = len(left) + 1
if a:cmdline.get_suffix() != ""
let width += len(s:suffix(left, a:cmdline.get_suffix())) - 1
endif
if &columns >= width && &columns <= s:old_width && s:old_width >= width
redraw
normal! :
elseif &columns <= width
normal! :
else
redraw
endif
let s:old_width = width
call s:cmdheight.save()
let height = max([(width - 1) / (&columns) + 1, s:cmdheight.get()])
if height > &cmdheight || &cmdheight > height
let &cmdheight = height
redraw
endif
endfunction
function! s:_as_echon(str)
return "echon " . string(a:str)
endfunction
function! s:module.on_draw_pre(cmdline)
if empty(a:cmdline.line.pos_word())
let cursor = "echohl " . a:cmdline.highlights.cursor . " | echon ' '"
else
let cursor = "echohl " . a:cmdline.highlights.cursor_on . " | " . s:_as_echon(a:cmdline.line.pos_word())
endif
let suffix = ""
if a:cmdline.get_suffix() != ""
let suffix = s:_as_echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_word())), a:cmdline.get_suffix()))
endif
let self.draw_command = join([
\ "echohl " . a:cmdline.highlights.prompt,
\ s:_as_echon(a:cmdline.get_prompt()),
\ "echohl NONE",
\ s:_as_echon(a:cmdline.backward()),
\ cursor,
\ "echohl NONE",
\ s:_as_echon(a:cmdline.forward()),
\ suffix,
\ ], " | ")
call s:_redraw(a:cmdline)
endfunction
function! s:_echon(expr)
echon strtrans(a:expr)
endfunction
function! s:module.on_draw(cmdline)
execute self.draw_command
" execute "echohl" a:cmdline.highlights.prompt
" call s:echon(a:cmdline.get_prompt())
" echohl NONE
" call s:echon(a:cmdline.backward())
" if empty(a:cmdline.line.pos_word())
" execute "echohl" a:cmdline.highlights.cursor
" call s:echon(' ')
" else
" execute "echohl" a:cmdline.highlights.cursor_on
" call s:echon(a:cmdline.line.pos_word())
" endif
" echohl NONE
" call s:echon(a:cmdline.forward())
" if a:cmdline.get_suffix() != ""
" call s:echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_word())), a:cmdline.get_suffix()))
" endif
endfunction
function! s:module.on_execute_pre(...)
call s:cmdheight.restore()
endfunction
function! s:module.on_leave(...)
call s:cmdheight.restore()
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,22 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "ExceptionExit",
\}
function! s:module.on_exception(cmdline)
call a:cmdline.exit(-1)
endfunction
function! s:make(...)
let result = deepcopy(s:module)
let result.exit_code = get(a:, 1, 0)
return result
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,45 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:module = {
\ "name" : "ExceptionMessage",
\}
function! s:module.on_exception(cmdline)
let self.exception = v:exception
let self.throwpoint = v:throwpoint
endfunction
function! s:module.on_draw_pre(cmdline)
if has_key(self, "exception")
call self.message(a:cmdline)
unlet self.exception
endif
endfunction
function! s:module.message(...)
echohl ErrorMsg
execute self.command string(self.prefix . self.throwpoint . " " . self.exception)
echohl None
endfunction
function! s:module.on_leave(cmdline)
if has_key(self, "exception")
call self.message(a:cmdline)
unlet self.exception
endif
endfunction
function! s:make(...)
let result = deepcopy(s:module)
let result.prefix = get(a:, 1, "vital-over:")
let result.command = get(a:, 2, "echo")
return result
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,76 +0,0 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
function! s:silent_feedkeys(expr, name, ...)
let mode = get(a:, 1, "m")
let map = printf("<Plug>(%s)", a:name)
if mode == "n"
let command = "nnoremap"
else
let command = "nmap"
endif
execute command "<silent>" map printf("%s:nunmap %s<CR>", a:expr, map)
call feedkeys(printf("\<Plug>(%s)", a:name))
endfunction
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:search = deepcopy(s:module)
let s:search.prefix = "/"
function! s:search.execute(cmdline)
call s:silent_feedkeys(":call histdel('/', -1)\<CR>", "remove_hist", "n")
let cmd = printf("call s:silent_feedkeys(\"%s%s\<CR>\", 'search', 'n')", self.prefix, a:cmdline.getline())
execute cmd
" let cmd = printf("call search('%s')", a:cmdline.getline())
" call a:cmdline.execute(cmd)
" let @/ = a:cmdline.getline()
" call s:silent_feedkeys(":let &hlsearch = &hlsearch\<CR>", "hlsearch", "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

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

View File

@ -24,13 +24,20 @@ function! s:module.on_execute_failed(...)
endfunction
function! s:module.on_leave(cmdline)
if self.is_execute == 0
if self.is_execute == 0 && a:cmdline.exit_code() != -1
call self.redraw(a:cmdline)
endif
endfunction
" function! s:module.on_draw_pre(cmdline)
" call self.redraw(a:cmdline)
" endfunction
function! s:module.redraw(cmdline)
call a:cmdline.redraw()
redraw
normal! :
endfunction
function! s:make()

View File

@ -3,7 +3,6 @@ easymotion
Over.Commandline.Base
Over.Commandline.Modules.Cancel
Over.Commandline.Modules.Execute
Over.Commandline.Modules.BufferComplete
Over.Commandline.Modules.Paste
Over.Commandline.Modules.KeyMapping
@ -14,3 +13,7 @@ Over.Commandline.Modules.Redraw
Over.Commandline.Modules.InsertRegister
Over.Commandline.Modules.History
Over.Commandline.Modules.NoInsert
Over.Commandline.Modules.Exit
Over.Commandline.Modules.DrawCommandline
Over.Commandline.Modules.ExceptionMessage
Over.Commandline.Modules.ExceptionExit