1
0
Fork 0
mirror of synced 2024-11-17 14:35:34 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/ui.vim

123 lines
3.1 KiB
VimL
Raw Normal View History

2018-12-17 06:28:27 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2014-10-31 17:30:24 -04:00
let s:buf_nr = -1
"OpenWindow opens a new scratch window and put's the content into the window
2016-12-27 09:46:49 -05:00
function! go#ui#OpenWindow(title, content, filetype) abort
2016-06-26 07:12:36 -04:00
" Ensure there's only one return window in this session/tabpage
call go#util#Windo("unlet! w:vim_go_return_window")
" Mark the window we're leaving as such
let w:vim_go_return_window = 1
" reuse existing buffer window if it exists otherwise create a new one
if !bufexists(s:buf_nr)
execute 'botright new'
file `="[" . a:title . "]"`
let s:buf_nr = bufnr('%')
elseif bufwinnr(s:buf_nr) == -1
execute 'botright new'
execute s:buf_nr . 'buffer'
elseif bufwinnr(s:buf_nr) != bufwinnr('%')
execute bufwinnr(s:buf_nr) . 'wincmd w'
endif
" Resize window to content length
exe 'resize' . len(a:content)
execute "setlocal filetype=".a:filetype
" some sane default values for a readonly buffer
setlocal bufhidden=delete
setlocal buftype=nofile
setlocal noswapfile
setlocal nobuflisted
setlocal winfixheight
setlocal cursorline " make it easy to distinguish
setlocal nonumber
setlocal norelativenumber
setlocal showbreak=""
" we need this to purge the buffer content
setlocal modifiable
"delete everything first from the buffer
%delete _
" add the content
call append(0, a:content)
" delete last line that comes from the append call
$delete _
" set it back to non modifiable
setlocal nomodifiable
" Remove the '... [New File]' message line from the command line
echon
2014-10-31 17:30:24 -04:00
endfunction
2016-12-27 09:46:49 -05:00
function! go#ui#GetReturnWindow() abort
2016-06-26 07:12:36 -04:00
for l:wn in range(1, winnr("$"))
if !empty(getwinvar(l:wn, "vim_go_return_window"))
return l:wn
endif
endfor
2016-04-12 04:31:09 -04:00
endfunction
2014-10-31 17:30:24 -04:00
" CloseWindow closes the current window
2016-12-27 09:46:49 -05:00
function! go#ui#CloseWindow() abort
2016-06-26 07:12:36 -04:00
" Close any window associated with the ui buffer, if it's there
if bufexists(s:buf_nr)
let ui_window_number = bufwinnr(s:buf_nr)
if ui_window_number != -1
execute ui_window_number . 'close'
2016-04-12 04:31:09 -04:00
endif
2016-06-26 07:12:36 -04:00
endif
"return to original window, if it's there
let l:rw = go#ui#GetReturnWindow()
if !empty(l:rw)
execute l:rw . 'wincmd w'
unlet! w:vim_go_return_window
endif
2014-10-31 17:30:24 -04:00
endfunction
" OpenDefinition parses the current line and jumps to it by openening a new
" tab
2016-12-27 09:46:49 -05:00
function! go#ui#OpenDefinition(filter) abort
2016-06-26 07:12:36 -04:00
let curline = getline('.')
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" don't touch our first line or any blank line
if curline =~ a:filter || curline =~ "^$"
" suppress information about calling this function
echo ""
return
endif
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" format: 'interface file:lnum:coln'
let mx = '^\(^\S*\)\s*\(.\{-}\):\(\d\+\):\(\d\+\)'
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" parse it now into the list
let tokens = matchlist(curline, mx)
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" convert to: 'file:lnum:coln'
let expr = tokens[2] . ":" . tokens[3] . ":" . tokens[4]
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" jump to it in a new tab, we use explicit lgetexpr so we can later change
" the behaviour via settings (like opening in vsplit instead of tab)
lgetexpr expr
tab split
ll 1
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" center the word
norm! zz
2014-10-31 17:30:24 -04:00
endfunction
2018-12-17 06:28:27 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et