diff --git a/autoload/vital/_brightest/Coaster/Window.vim b/autoload/vital/_brightest/Coaster/Window.vim index e464006..7c670b8 100644 --- a/autoload/vital/_brightest/Coaster/Window.vim +++ b/autoload/vital/_brightest/Coaster/Window.vim @@ -3,8 +3,21 @@ let s:save_cpo = &cpo set cpo&vim +function! s:_vital_loaded(V) + let s:V = a:V + let s:Buffer = a:V.import("Vim.Buffer") +endfunction + + +function! s:_vital_depends() + return [ +\ "Vim.Buffer", +\ ] +endfunction + + function! s:windo(func, args, obj) - if len(tabpagebuflist()) <= 1 + if len(tabpagebuflist()) <= 1 || s:Buffer.is_cmdwin() return call(a:func, a:args, a:obj) endif let pre_winnr = winnr() diff --git a/autoload/vital/_brightest/Vim/Buffer.vim b/autoload/vital/_brightest/Vim/Buffer.vim new file mode 100644 index 0000000..ad12c08 --- /dev/null +++ b/autoload/vital/_brightest/Vim/Buffer.vim @@ -0,0 +1,96 @@ +let s:save_cpo = &cpo +set cpo&vim + +function! s:_vital_loaded(V) abort + let s:V = a:V + let s:P = s:V.import('Prelude') +endfunction + +function! s:_vital_depends() abort + return ['Prelude'] +endfunction + +if exists('*getcmdwintype') + function! s:is_cmdwin() abort + return getcmdwintype() !=# '' + endfunction +else + function! s:is_cmdwin() abort + return bufname('%') ==# '[Command Line]' + endfunction +endif + +function! s:open(buffer, opener) abort + let save_wildignore = &wildignore + let &wildignore = '' + try + if s:P.is_funcref(a:opener) + let loaded = !bufloaded(a:buffer) + call a:opener(a:buffer) + elseif a:buffer is 0 || a:buffer is '' + let loaded = 1 + silent execute a:opener + enew + else + let loaded = !bufloaded(a:buffer) + if s:P.is_string(a:buffer) + execute a:opener '`=a:buffer`' + elseif s:P.is_number(a:buffer) + silent execute a:opener + execute a:buffer 'buffer' + else + throw 'vital: Vim.Buffer: Unknown opener type.' + endif + endif + finally + let &wildignore = save_wildignore + endtry + return loaded +endfunction + +function! s:get_selected_text(...) abort + echohl WarningMsg + echom "[WARN] s:get_selected_text() is deprecated. Use 's:get_last_selected()'." + echohl None + return call('s:get_last_selected', a:000) +endfunction + +" Get the last selected text in visual mode +" without using |gv| to avoid |textlock|. +" NOTE: +" * This function uses |gv| only when using |CTRL-V| +" because |gv| is the only way to get selected text +" when using $ . +" Please see #192 for the details. +" * If you don't care about |textlock|, +" you can use simple version of this function. +" https://github.com/vim-jp/vital.vim/commit/39aae80f3839fdbeebd838ff14d87327a6b889a9 +function! s:get_last_selected() abort + if visualmode() ==# "\" + let save = getreg('"', 1) + let save_type = getregtype('"') + try + normal! gv""y + return @" + finally + call setreg('"', save, save_type) + endtry + else + let [begin, end] = [getpos("'<"), getpos("'>")] + let lastchar = matchstr(getline(end[1])[end[2]-1 :], '.') + if begin[1] ==# end[1] + let lines = [getline(begin[1])[begin[2]-1 : end[2]-2]] + else + let lines = [getline(begin[1])[begin[2]-1 :]] + \ + (end[1] - begin[1] <# 2 ? [] : getline(begin[1]+1, end[1]-1)) + \ + [getline(end[1])[: end[2]-2]] + endif + return join(lines, "\n") . lastchar . (visualmode() ==# "V" ? "\n" : "") + endif +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/autoload/vital/brightest.vital b/autoload/vital/brightest.vital index 3f655ad..cd2dde1 100644 --- a/autoload/vital/brightest.vital +++ b/autoload/vital/brightest.vital @@ -6,3 +6,4 @@ Prelude Coaster.Buffer Coaster.Highlight Coaster.Search +Coaster.Window