Browse files

Open previewwin relative to Tagbar win

  • Loading branch information...
1 parent b4a5800 commit 87bbb46e959e455bb5e488c4197b61a46927b20e @majutsushi committed Nov 30, 2013
Showing with 21 additions and 7 deletions.
  1. +21 −7 autoload/tagbar.vim
View
28 autoload/tagbar.vim
@@ -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
@@ -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
@@ -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

0 comments on commit 87bbb46

Please sign in to comment.