Skip to content

Commit

Permalink
Open previewwin relative to Tagbar win
Browse files Browse the repository at this point in the history
  • Loading branch information
majutsushi committed Nov 30, 2013
1 parent b4a5800 commit 87bbb46
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions autoload/tagbar.vim
Expand Up @@ -972,7 +972,7 @@ function! s:CreateAutocommands() abort
autocmd CursorMoved __Tagbar__ nested call s:ShowInPreviewWin()
endif

autocmd BufEnter * nested call s:QuitIfOnlyWindow()
autocmd WinEnter * nested call s:QuitIfOnlyWindow()
autocmd WinEnter * if bufwinnr('__Tagbar__') == -1 |
\ call s:ShrinkIfExpanded() |
\ endif
Expand Down Expand Up @@ -3021,6 +3021,25 @@ function! s:ShowInPreviewWin() abort
return
endif

" Check whether the preview window is already open and open it if not.
" This has to be done before the :psearch below so the window is relative
" to the Tagbar window.
let pwin_open = 0
for win in range(1, winnr('$'))
if getwinvar(win, '&previewwindow')
let pwin_open = 1
break
endif
endfor

if !pwin_open
silent! execute
\ g:tagbar_previewwin_pos . ' pedit ' . taginfo.fileinfo.fpath
" Remember that the preview window was opened by Tagbar so we can
" safely close it by ourselves
let s:pwin_by_tagbar = 1
endif

" Use psearch instead of pedit since pedit essentially reloads the file
" and creates an empty undo entry. psearch has to be called from the file
" window, and since we only want matches in the current file we disable
Expand All @@ -3031,15 +3050,10 @@ function! s:ShowInPreviewWin() abort
call s:GotoFileWindow(taginfo.fileinfo, 1)
let include_save = &include
set include=
silent! execute g:tagbar_previewwin_pos . ' ' .
\ taginfo.fields.line . ',$psearch! /' . taginfo.pattern . '/'
silent! execute taginfo.fields.line . ',$psearch! /' . taginfo.pattern . '/'
let &include = include_save
call s:goto_tagbar(1)

" Remember that the preview window was opened by Tagbar so we can safely
" close it by ourselves
let s:pwin_by_tagbar = 1

call s:goto_win('P', 1)
normal! zv
normal! zz
Expand Down

0 comments on commit 87bbb46

Please sign in to comment.