vim-easymotion/autoload/vital/_easymotion/Over/Commandline/Modules/DrawCommandline.vim

167 lines
4.2 KiB
VimL
Raw Normal View History

2014-02-23 23:43:16 -05:00
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)
2015-02-23 11:19:17 -05:00
let left = a:cmdline.get_prompt() . a:cmdline.getline() . (empty(a:cmdline.line.pos_char()) ? " " : "")
2014-02-23 23:43:16 -05:00
let width = len(left) + 1
2014-11-23 12:07:19 -05:00
if a:cmdline.get_suffix() != ""
2014-02-23 23:43:16 -05:00
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)
2014-06-06 12:35:19 -04:00
return "echon " . strtrans(string(a:str))
2014-02-23 23:43:16 -05:00
endfunction
function! s:module.on_draw_pre(cmdline)
2015-02-23 11:19:17 -05:00
if empty(a:cmdline.line.pos_char())
2014-02-23 23:43:16 -05:00
let cursor = "echohl " . a:cmdline.highlights.cursor . " | echon ' '"
else
2015-02-23 11:19:17 -05:00
let cursor = "echohl " . a:cmdline.highlights.cursor_on . " | " . s:_as_echon(a:cmdline.line.pos_char())
2014-02-23 23:43:16 -05:00
endif
let suffix = ""
if a:cmdline.get_suffix() != ""
2015-02-23 11:19:17 -05:00
let suffix = s:_as_echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix()))
2014-02-23 23:43:16 -05:00
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())
2015-02-23 11:19:17 -05:00
" if empty(a:cmdline.line.pos_char())
2014-02-23 23:43:16 -05:00
" execute "echohl" a:cmdline.highlights.cursor
" call s:echon(' ')
" else
" execute "echohl" a:cmdline.highlights.cursor_on
2015-02-23 11:19:17 -05:00
" call s:echon(a:cmdline.line.pos_char())
2014-02-23 23:43:16 -05:00
" endif
" echohl NONE
" call s:echon(a:cmdline.forward())
" if a:cmdline.get_suffix() != ""
2015-02-23 11:19:17 -05:00
" call s:echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix()))
2014-02-23 23:43:16 -05:00
" 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
2016-03-22 08:55:42 -04:00
" ___Revitalizer___
" NOTE: below code is generated by :Revitalize.
" Do not mofidify the code nor append new lines
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:___revitalizer_function___(fstr) abort
return function(a:fstr)
endfunction
else
function! s:___revitalizer_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze____revitalizer_SID$')
endfunction
let s:___revitalizer_sid = '<SNR>' . s:___revitalizer_SID() . '_'
function! s:___revitalizer_function___(fstr) abort
return function(substitute(a:fstr, 's:', s:___revitalizer_sid, 'g'))
endfunction
endif
2016-03-22 10:04:08 -04:00
let s:___revitalizer_functions___ = {'make': s:___revitalizer_function___('s:make'),'suffix': s:___revitalizer_function___('s:suffix')}
2016-03-22 08:55:42 -04:00
unlet! s:___revitalizer_sid
delfunction s:___revitalizer_function___
function! vital#_easymotion#Over#Commandline#Modules#DrawCommandline#import() abort
return s:___revitalizer_functions___
endfunction
" ___Revitalizer___