Skip to content

Commit c8409bf

Browse files
majutsushivim-scripts
authored andcommitted
Version 1.1
- Don't lose syntax highlighting when ':syntax enable' is called - Allow expanding the Vim window when Tagbar is opened Thanks to Hansi for reporting.
1 parent 3dd93a5 commit c8409bf

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

doc/tagbar.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author: Jan Larres <jan@majutsushi.net>
44
Licence: Vim licence, see |license|
55
Homepage: http://majutsushi.github.com/tagbar/
6-
Version: 1.0
6+
Version: 1.1
77

88
==============================================================================
99
Contents *tagbar* *tagbar-contents*
@@ -304,6 +304,18 @@ Example:
304304
>
305305
let g:tagbar_compact = 1
306306
<
307+
308+
*g:tagbar_expand*
309+
g:tagbar_expand~
310+
If this option is set the Vim window will be expanded by the width of the
311+
Tagbar window if using a GUI version of Vim. The default is not to expand the
312+
window.
313+
314+
Example:
315+
>
316+
let g:tagbar_expand = 1
317+
<
318+
307319
==============================================================================
308320
6. Extending Tagbar *tagbar-extend*
309321

@@ -581,6 +593,10 @@ files.
581593
==============================================================================
582594
8. History *tagbar-history*
583595

596+
1.1 (2011-02-26)
597+
- Don't lose syntax highlighting when ':syntax enable' is called
598+
- Allow expanding the Vim window when Tagbar is opened
599+
584600
1.0 (2011-02-23)
585601
- Initial release
586602

@@ -607,3 +623,6 @@ anything else that's free, taglist.vim is provided *as is* and comes with no
607623
warranty of any kind, either expressed or implied. In no event will the
608624
copyright holder be liable for any damamges resulting from the use of this
609625
software.
626+
627+
==============================================================================
628+
vim: tw=78 ts=8 sw=8 sts=8 noet ft=help

plugin/tagbar.vim

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Author: Jan Larres <jan@majutsushi.net>
55
" Licence: Vim licence
66
" Website: http://majutsushi.github.com/tagbar/
7-
" Version: 1.0
7+
" Version: 1.1
88
" Note: This plugin was heavily inspired by the 'Taglist' plugin by
99
" Yegappan Lakshmanan and uses a small amount of code from it.
1010
"
@@ -62,9 +62,14 @@ if !exists('g:tagbar_compact')
6262
let g:tagbar_compact = 0
6363
endif
6464

65+
if !exists('g:tagbar_expand')
66+
let g:tagbar_expand = 0
67+
endif
68+
6569
let s:type_init_done = 0
6670
let s:key_mapping_done = 0
6771
let s:autocommands_done = 0
72+
let s:window_expanded = 0
6873

6974
" s:InitTypes() {{{2
7075
function! s:InitTypes()
@@ -837,6 +842,12 @@ function! s:OpenWindow(autoclose)
837842
return
838843
endif
839844

845+
" Expand the Vim window to accomodate for the Tagbar window if requested
846+
if g:tagbar_expand && !s:window_expanded && has('gui_running')
847+
let &columns += g:tagbar_width + 1
848+
let s:window_expanded = 1
849+
endif
850+
840851
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
841852
exe 'silent! keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__'
842853

@@ -880,21 +891,6 @@ function! s:OpenWindow(autoclose)
880891

881892
let w:autoclose = a:autoclose
882893

883-
syntax match Comment '^" .*' " Comments
884-
syntax match Identifier '^ [^: ]\+[^:]\+$' " Non-scoped kinds
885-
syntax match Title '[^(* ]\+\ze\*\? :' " Scope names
886-
syntax match Type ' : \zs.*' " Scope types
887-
syntax match SpecialKey '(.*)' " Signatures
888-
syntax match NonText '\*\ze :' " Pseudo-tag identifiers
889-
890-
highlight default TagbarAccessPublic guifg=Green ctermfg=Green
891-
highlight default TagbarAccessProtected guifg=Blue ctermfg=Blue
892-
highlight default TagbarAccessPrivate guifg=Red ctermfg=Red
893-
894-
syntax match TagbarAccessPublic '^\s*+\ze[^ ]'
895-
syntax match TagbarAccessProtected '^\s*#\ze[^ ]'
896-
syntax match TagbarAccessPrivate '^\s*-\ze[^ ]'
897-
898894
if has('balloon_eval')
899895
setlocal balloonexpr=TagbarBalloonExpr()
900896
set ballooneval
@@ -930,6 +926,8 @@ function! s:CloseWindow()
930926
return
931927
endif
932928

929+
let tagbarbufnr = winbufnr(tagbarwinnr)
930+
933931
if winnr() == tagbarwinnr
934932
if winbufnr(2) != -1
935933
" Other windows are open, only close the tagbar one
@@ -948,6 +946,20 @@ function! s:CloseWindow()
948946
exe winnum . 'wincmd w'
949947
endif
950948
endif
949+
950+
" If the Vim window has been expanded, and Tagbar is not open in any other
951+
" tabpages, shrink the window again
952+
if s:window_expanded
953+
let tablist = []
954+
for i in range(tabpagenr('$'))
955+
call extend(tablist, tabpagebuflist(i + 1))
956+
endfor
957+
958+
if index(tablist, tagbarbufnr) == -1
959+
let &columns -= g:tagbar_width + 1
960+
let s:window_expanded = 0
961+
endif
962+
endif
951963
endfunction
952964

953965
" s:ZoomWindow() {{{2
@@ -1676,6 +1688,7 @@ endfunction
16761688
" s:CleanUp() {{{2
16771689
function! s:CleanUp()
16781690
silent! autocmd! TagbarAutoCmds
1691+
16791692
unlet s:current_file
16801693
unlet s:is_maximized
16811694
unlet s:compare_typeinfo

syntax/tagbar.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
" File: tagbar.vim
2+
" Description: Tagbar syntax settings
3+
" Author: Jan Larres <jan@majutsushi.net>
4+
" Licence: Vim licence
5+
" Website: http://majutsushi.github.com/tagbar/
6+
" Version: 1.1
7+
8+
if exists("b:current_syntax")
9+
finish
10+
endif
11+
12+
syntax match Comment '^" .*' " Comments
13+
syntax match Identifier '^ [^: ]\+[^:]\+$' " Non-scoped kinds
14+
syntax match Title '[^(* ]\+\ze\*\? :' " Scope names
15+
syntax match Type ' : \zs.*' " Scope types
16+
syntax match SpecialKey '(.*)' " Signatures
17+
syntax match NonText '\*\ze :' " Pseudo-tag identifiers
18+
19+
highlight default TagbarAccessPublic guifg=Green ctermfg=Green
20+
highlight default TagbarAccessProtected guifg=Blue ctermfg=Blue
21+
highlight default TagbarAccessPrivate guifg=Red ctermfg=Red
22+
23+
syntax match TagbarAccessPublic '^\s*+\ze[^ ]'
24+
syntax match TagbarAccessProtected '^\s*#\ze[^ ]'
25+
syntax match TagbarAccessPrivate '^\s*-\ze[^ ]'
26+
27+
let b:current_syntax = "tagbar"

0 commit comments

Comments
 (0)