1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-17 11:30:28 +01:00

Add option to arrange Tagbar window vertically

This commit is contained in:
Jan Larres
2014-11-08 21:30:17 +13:00
parent 5283bc834a
commit f933907afa
3 changed files with 53 additions and 10 deletions

View File

@@ -1767,8 +1767,14 @@ function! s:OpenWindow(flags) abort
endif
let s:window_opening = 1
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
exe 'silent keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__'
if g:tagbar_vertical == 0
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
let width = g:tagbar_width
else
let openpos = g:tagbar_left ? 'leftabove ' : 'rightbelow '
let width = g:tagbar_vertical
endif
exe 'silent keepalt ' . openpos . width . 'split ' . '__Tagbar__'
unlet s:window_opening
call s:InitWindow(autoclose)
@@ -3050,12 +3056,6 @@ function! s:ShowInPreviewWin() abort
return
endif
call s:GotoFileWindow(taginfo.fileinfo, 1)
call s:mark_window()
" 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')
@@ -3064,14 +3064,32 @@ function! s:ShowInPreviewWin() abort
endif
endfor
" We want the preview window to be relative to the file window in normal
" (horizontal) mode, and relative to the Tagbar window in vertical mode,
" to make the best use of space.
if g:tagbar_vertical == 0
call s:GotoFileWindow(taginfo.fileinfo, 1)
call s:mark_window()
endif
" Open the preview window if it is not already open. This has to be done
" explicitly before the :psearch below to better control its positioning.
if !pwin_open
silent execute
\ g:tagbar_previewwin_pos . ' pedit ' . taginfo.fileinfo.fpath
if g:tagbar_vertical != 0
silent execute 'vertical resize ' . g:tagbar_width
endif
" Remember that the preview window was opened by Tagbar so we can
" safely close it by ourselves
let s:pwin_by_tagbar = 1
endif
if g:tagbar_vertical != 0
call s:GotoFileWindow(taginfo.fileinfo, 1)
call s:mark_window()
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

View File

@@ -388,11 +388,29 @@ Default: 0
By default the Tagbar window will be opened on the right-hand side of vim. Set
this option to open it on the left instead.
If |g:tagbar_vertical| is used then setting this variable will open the Tagbar
window at the top, otherwise it will open at the bottom.
Example:
>
let g:tagbar_left = 1
<
*g:tagbar_vertical*
g:tagbar_vertical~
Default: 0
If this is set to a positive value then the Tagbar window will be opened at
the top or bottom of the Vim window instead of at the side. This can be useful
for monitors that have been rotated into a vertical position. The value of
this variable will determine the number of lines to use for the Tagbar window.
See |g:tagbar_left| for configuring the position of the window.
Example:
>
let g:tagbar_vertical = 30
<
*g:tagbar_width*
g:tagbar_width~
Default: 40
@@ -604,7 +622,7 @@ Example:
*g:tagbar_previewwin_pos*
g:tagbar_previewwin_pos~
Default: topleft
Default: "topleft", or "rightbelow vertical" if |g:tagbar_vertical| is set
The position of the preview window. Valid values are the window splitting
commands that are described starting from |:vertical|. Set it to an empty

View File

@@ -48,6 +48,11 @@ function! s:init_var(var, value) abort
endif
endfunction
if !exists('g:tagbar_vertical') || g:tagbar_vertical == 0
let s:previewwin_pos = 'topleft'
else
let s:previewwin_pos = 'rightbelow vertical'
endif
let s:options = [
\ ['autoclose', 0],
\ ['autofocus', 0],
@@ -59,15 +64,17 @@ let s:options = [
\ ['hide_nonpublic', 0],
\ ['indent', 2],
\ ['left', 0],
\ ['previewwin_pos', 'topleft'],
\ ['previewwin_pos', s:previewwin_pos],
\ ['show_visibility', 1],
\ ['show_linenumbers', 0],
\ ['singleclick', 0],
\ ['sort', 1],
\ ['systemenc', &encoding],
\ ['vertical', 0],
\ ['width', 40],
\ ['zoomwidth', 1],
\ ]
unlet s:previewwin_pos
for [opt, val] in s:options
call s:init_var(opt, val)