1
0
mirror of https://github.com/gryf/tagbar.git synced 2026-05-10 16:32:58 +02:00

18 Commits

Author SHA1 Message Date
Jan Larres 518b07de12 Version 1.5 2011-03-06 23:47:27 +13:00
Jan Larres a9c352c134 Ensure that as much content as possible is shown in the Tagbar window 2011-03-06 23:00:13 +13:00
Jan Larres b176c930d0 Get rid of unneeded type def field 'scopes' 2011-03-06 19:52:54 +13:00
Jan Larres e84bffb6df Allow for extra ctags definition files in type definitions 2011-03-06 19:12:21 +13:00
Taybin Rutkin 07997460d1 update documentation for tagbar_autofocus 2011-03-05 19:29:52 +13:00
Taybin Rutkin eb1ccae17e Add g:tagbar_autofocus option to always move cursor to tagbar window when it opens 2011-03-05 19:29:26 +13:00
Taybin Rutkin d86d93dbf1 remove redundant code 2011-03-05 19:25:47 +13:00
Jan Larres a532d7c445 Make sure the whole Tagbar content is shown if it is shorter than the window height 2011-03-04 02:59:40 +13:00
Jan Larres 38a6c9f6a1 Make sure jumps to the Tagbar window don't end up at the bottom after file loading 2011-03-04 02:58:48 +13:00
Jan Larres 82eebf945e Don't do any highlighting if there's no tag above the cursor 2011-03-02 23:31:58 +13:00
Jan Larres f847c4631b Add 'redraw' in some places since auto-redraw doesn't always work 2011-03-02 23:29:36 +13:00
Jan Larres 84121aac7d Version 1.2 2011-02-28 18:12:36 +13:00
Jan Larres be86180c88 Small optimization 2011-02-28 18:08:47 +13:00
Jan Larres 9eb5ff5e1f Fix typo in Ruby definition 2011-02-28 18:08:31 +13:00
Jan Larres c67610eba3 Add history entry for 1.1 2011-02-26 22:48:39 +13:00
Jan Larres 91deffb04d Version 1.1 2011-02-26 20:52:40 +13:00
Jan Larres 9ae8cfedd8 Allow expanding the vim window when opening Tagbar 2011-02-26 20:51:15 +13:00
Jan Larres a18be73b63 Fix syntax highlighting when :syntax enable is called 2011-02-26 19:59:28 +13:00
3 changed files with 182 additions and 97 deletions
+78 -24
View File
@@ -3,7 +3,7 @@
Author: Jan Larres <jan@majutsushi.net>
Licence: Vim licence, see |license|
Homepage: http://majutsushi.github.com/tagbar/
Version: 1.0
Version: 1.5
==============================================================================
Contents *tagbar* *tagbar-contents*
@@ -283,6 +283,16 @@ Example:
let g:tagbar_autoclose = 1
<
*g:tagbar_autofocus*
g:tagbar_autofocus~
If you set this option the cursor will move to the Tagbar window when it is
opened. The default is to not move the cursor to the window.
Example:
>
let g:tagbar_autofocus = 1
<
*g:tagbar_sort*
g:tagbar_sort~
If this option is set the tags are sorted according to their name. If it is
@@ -304,6 +314,18 @@ Example:
>
let g:tagbar_compact = 1
<
*g:tagbar_expand*
g:tagbar_expand~
If this option is set the Vim window will be expanded by the width of the
Tagbar window if using a GUI version of Vim. The default is not to expand the
window.
Example:
>
let g:tagbar_expand = 1
<
==============================================================================
6. Extending Tagbar *tagbar-extend*
@@ -330,11 +352,16 @@ kinds: A list of the "language kinds" that should be listed in Tagbar,
"f:functions"
< would list all the function definitions in a file under the header
"functions".
scopes: A list of the scopes that ctags supports for a given language, for
example classes, structs etc. Unfortunately there is no ctags
option to list the scopes, you have to look at the tags ctags
generates manually. For example, let's say we have a C++ file
"test.cpp" with the following contents: >
sro: The scope resolution operator. For example, in C++ it is "::" and
in Java it is ".". When in doubt run ctags as shown above and look
at the output.
kind2scope: A dictionary describing the mapping of tag kinds (in their
one-character representation) to the scopes their children will
appear in, for example classes, structs etc.
Unfortunately there is no ctags option to list the scopes, you
have to look at the tags ctags generates manually. For example,
let's say we have a C++ file "test.cpp" with the following
contents: >
class Foo
{
public:
@@ -348,15 +375,8 @@ scopes: A list of the scopes that ctags supports for a given language, for
< Then the output for the variable "var" would look like this: >
var tmp.cpp /^ int var;$/;" kind:m line:11 class:Foo access:private
< This shows that the scope name for an entry in a C++ class is
simply "class". So you would need to put this exact word into the
"scopes" list. The order again determines the order in which the
tags will be displayed in Tagbar.
sro: The scope resolution operator. For example, in C++ it is "::" and
in Java it is ".". When in doubt run ctags as shown above and look
at the output.
kind2scope: A dictionary describing the mapping of tag kinds (in their
one-character representation) to the scopes their children will
appear in.
simply "class". So this would be the word that the "kind"
character of a class has to be mapped to.
scope2kind: The opposite of the above, mapping scopes to the kinds of their
parents. Most of the time it is the exact inverse of the above,
but in some cases it can be different, for example when more than
@@ -371,6 +391,20 @@ sort: This entry can be used to override the global sort setting for
with the global setting, that is if you want to sort tags by name
set it to 1 and if you want to sort them according to their order
in the file set it to 0.
deffile: The path to a file with additional ctags definitions (see the
{optional} section below on adding a new definition for what exactly that
means). This is especially useful for ftplugins since they can
provide a complete type definition with ctags and Tagbar
configurations without requiring user intervention.
Let's say you have an ftplugin that adds support for the language
"mylang", and your directory structure looks like this: >
ctags/mylang.cnf
ftplugin/mylang.vim
< Then the "deffile" entry would look like this to allow for the
plugin to be installed in an arbitray location (for example
with pathogen): >
'deffile' : expand('<sfile>:p:h:h') . '/ctags/mylang.cnf'
<
You then have to assign this dictionary to a variable with the name
>
@@ -403,13 +437,6 @@ used in Tagbar.
\ 'm:members',
\ 'v:variables'
\ ],
\ 'scopes' : [
\ 'namespace',
\ 'class',
\ 'struct',
\ 'enum',
\ 'union'
\ ],
\ 'sro' : '::',
\ 'kind2scope' : {
\ 'g' : 'enum',
@@ -475,7 +502,8 @@ those two and in addition "scopes", "sro" and at least one of "kind2scope" and
"scope2kind".
Let's assume we want to add support for LaTeX to Tagbar using the regex
approach. First we put the following text into ~/.ctags:
approach. First we put the following text into ~/.ctags or a file pointed to
by the "deffile" definition entry:
>
--langdef=latex
--langmap=latex:.tex
@@ -517,9 +545,13 @@ Now we have to create the Tagbar language definition in our vimrc:
\ 'r:refs',
\ 'p:pagerefs'
\ ],
\ 'sort' : 0
\ 'sort' : 0,
\ 'deffile' : expand('<sfile>:p:h:h') . '/ctags/latex.cnf'
\ }
<
The "deffile" field is of course only needed if the ctags definition actually
is in that file and not in ~/.ctags.
Sort has been disabled for LaTeX so that the sections appear in their correct
order. They unfortunately can't be shown nested with their correct scopes
since as already mentioned the regular expression approach doesn't support
@@ -581,6 +613,25 @@ files.
==============================================================================
8. History *tagbar-history*
1.5 (2011-03-06)
- Type definitions can now include a path to a file with the ctags
definition. This is especially useful for ftplugins that can now ship
with a complete ctags and Tagbar configuration without requiring user
intervention. Thanks to Jan Christoph Ebersbach for the suggestion.
- Added autofocus setting by Taybin Rutkin. This will put the cursor in
the Tagbar window when it is opened.
- The "scopes" field is no longer needed in type definitions, the
information is already there in "scope2kind". Existing definitions will
be ignored.
- Some fixes and improvements related to redrawing and window switching.
1.2 (2011-02-28)
- Fix typo in Ruby definition
1.1 (2011-02-26)
- Don't lose syntax highlighting when ':syntax enable' is called
- Allow expanding the Vim window when Tagbar is opened
1.0 (2011-02-23)
- Initial release
@@ -607,3 +658,6 @@ anything else that's free, taglist.vim is provided *as is* and comes with no
warranty of any kind, either expressed or implied. In no event will the
copyright holder be liable for any damamges resulting from the use of this
software.
==============================================================================
vim: tw=78 ts=8 sw=8 sts=8 noet ft=help
+77 -73
View File
@@ -4,7 +4,7 @@
" Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/
" Version: 1.0
" Version: 1.5
" Note: This plugin was heavily inspired by the 'Taglist' plugin by
" Yegappan Lakshmanan and uses a small amount of code from it.
"
@@ -54,6 +54,10 @@ if !exists('g:tagbar_autoclose')
let g:tagbar_autoclose = 0
endif
if !exists('g:tagbar_autofocus')
let g:tagbar_autofocus = 0
endif
if !exists('g:tagbar_sort')
let g:tagbar_sort = 1
endif
@@ -62,9 +66,14 @@ if !exists('g:tagbar_compact')
let g:tagbar_compact = 0
endif
if !exists('g:tagbar_expand')
let g:tagbar_expand = 0
endif
let s:type_init_done = 0
let s:key_mapping_done = 0
let s:autocommands_done = 0
let s:window_expanded = 0
" s:InitTypes() {{{2
function! s:InitTypes()
@@ -141,8 +150,6 @@ function! s:InitTypes()
" C {{{3
let type_c = {}
let type_c.ctagstype = 'c'
let type_c.scopes = ['enum', 'struct', 'union']
let type_c.sro = '::'
let type_c.kinds = [
\ 'd:macros',
\ 'p:prototypes',
@@ -155,6 +162,7 @@ function! s:InitTypes()
\ 'v:variables',
\ 'f:functions'
\ ]
let type_c.sro = '::'
let type_c.kind2scope = {
\ 'g' : 'enum',
\ 's' : 'struct',
@@ -169,14 +177,6 @@ function! s:InitTypes()
" C++ {{{3
let type_cpp = {}
let type_cpp.ctagstype = 'c++'
let type_cpp.scopes = [
\ 'namespace',
\ 'class',
\ 'struct',
\ 'enum',
\ 'union'
\ ]
let type_cpp.sro = '::'
let type_cpp.kinds = [
\ 'd:macros',
\ 'p:prototypes',
@@ -191,6 +191,7 @@ function! s:InitTypes()
\ 'm:members',
\ 'v:variables'
\ ]
let type_cpp.sro = '::'
let type_cpp.kind2scope = {
\ 'g' : 'enum',
\ 'n' : 'namespace',
@@ -209,14 +210,6 @@ function! s:InitTypes()
" C# {{{3
let type_cs = {}
let type_cs.ctagstype = 'c#'
let type_cs.scopes = [
\ 'namespace',
\ 'interface',
\ 'class',
\ 'struct',
\ 'enum'
\ ]
let type_cs.sro = '.'
let type_cs.kinds = [
\ 'd:macros',
\ 'f:fields',
@@ -231,6 +224,7 @@ function! s:InitTypes()
\ 'm:methods',
\ 'p:properties'
\ ]
let type_cs.sro = '.'
let type_cs.kind2scope = {
\ 'n' : 'namespace',
\ 'i' : 'interface',
@@ -269,12 +263,11 @@ function! s:InitTypes()
" Eiffel {{{3
let type_eiffel = {}
let type_eiffel.ctagstype = 'eiffel'
let type_eiffel.scopes = ['class', 'feature']
let type_eiffel.sro = '.' " Not sure, is nesting even possible?
let type_eiffel.kinds = [
\ 'c:classes',
\ 'f:features'
\ ]
let type_eiffel.sro = '.' " Not sure, is nesting even possible?
let type_eiffel.kind2scope = {
\ 'c' : 'class',
\ 'f' : 'feature'
@@ -287,14 +280,13 @@ function! s:InitTypes()
" Erlang {{{3
let type_erlang = {}
let type_erlang.ctagstype = 'erlang'
let type_erlang.scopes = ['module']
let type_erlang.sro = '.' " Not sure, is nesting even possible?
let type_erlang.kinds = [
\ 'm:modules',
\ 'd:macro definitions',
\ 'f:functions',
\ 'r:record definitions'
\ ]
let type_erlang.sro = '.' " Not sure, is nesting even possible?
let type_erlang.kind2scope = {
\ 'm' : 'module'
\ }
@@ -309,8 +301,6 @@ function! s:InitTypes()
" Improvements welcome!
let type_mxml = {}
let type_mxml.ctagstype = 'flex'
let type_mxml.scopes = ['class']
let type_mxml.sro = '.'
let type_mxml.kinds = [
\ 'v:global variables',
\ 'c:classes',
@@ -319,6 +309,7 @@ function! s:InitTypes()
\ 'f:functions',
\ 'x:mxtags'
\ ]
let type_mxml.sro = '.'
let type_mxml.kind2scope = {
\ 'c' : 'class'
\ }
@@ -329,8 +320,6 @@ function! s:InitTypes()
" Fortran {{{3
let type_fortran = {}
let type_fortran.ctagstype = 'fortran'
let type_fortran.scopes = ['module', 'program', 'function', 'subroutine']
let type_fortran.sro = '.' " Not sure, is nesting even possible?
let type_fortran.kinds = [
\ 'm:modules',
\ 'p:programs',
@@ -345,6 +334,7 @@ function! s:InitTypes()
\ 'n:namelists',
\ 'v:variables'
\ ]
let type_fortran.sro = '.' " Not sure, is nesting even possible?
let type_fortran.kind2scope = {
\ 'm' : 'module',
\ 'p' : 'program',
@@ -369,8 +359,6 @@ function! s:InitTypes()
" Java {{{3
let type_java = {}
let type_java.ctagstype = 'java'
let type_java.scopes = ['enum', 'interface', 'class']
let type_java.sro = '.'
let type_java.kinds = [
\ 'p:packages',
\ 'f:fields',
@@ -380,6 +368,7 @@ function! s:InitTypes()
\ 'c:classes',
\ 'm:methods'
\ ]
let type_java.sro = '.'
let type_java.kind2scope = {
\ 'g' : 'enum',
\ 'i' : 'interface',
@@ -436,8 +425,6 @@ function! s:InitTypes()
" Ocaml {{{3
let type_ocaml = {}
let type_ocaml.ctagstype = 'ocaml'
let type_ocaml.scopes = ['Module', 'class', 'type']
let type_ocaml.sro = '.' " Not sure, is nesting even possible?
let type_ocaml.kinds = [
\ 'M:modules or functors',
\ 'v:global variables',
@@ -449,6 +436,7 @@ function! s:InitTypes()
\ 'f:functions',
\ 'r:structure fields'
\ ]
let type_ocaml.sro = '.' " Not sure, is nesting even possible?
let type_ocaml.kind2scope = {
\ 'M' : 'Module',
\ 'c' : 'class',
@@ -494,8 +482,6 @@ function! s:InitTypes()
" Python {{{3
let type_python = {}
let type_python.ctagstype = 'python'
let type_python.scopes = ['class', 'function']
let type_python.sro = '.'
let type_python.kinds = [
\ 'i:imports',
\ 'c:classes',
@@ -508,6 +494,7 @@ function! s:InitTypes()
\ 'f' : 'function',
\ 'm' : 'function'
\ }
let type_python.sro = '.'
let type_python.scope2kind = {
\ 'class' : 'c',
\ 'function' : 'f'
@@ -523,16 +510,16 @@ function! s:InitTypes()
" Ruby {{{3
let type_ruby = {}
let type_ruby.ctagstype = 'ruby'
let type_ruby.scopes = ['class']
let type_ruby.sro = '.'
let type_ruby.kinds = [
\ 'm:modules',
\ 'c:classes',
\ 'f:methods',
\ 'F:singleton methods'
\ ]
let type_ruby.kinds2scope = {
\ 'c' : 'class'
let type_ruby.sro = '.'
let type_ruby.kind2scope = {
\ 'c' : 'class',
\ 'm' : 'class'
\ }
let type_ruby.scope2kind = {
\ 'class' : 'c'
@@ -630,8 +617,6 @@ function! s:InitTypes()
" Why are variables 'virtual'?
let type_vera = {}
let type_vera.ctagstype = 'vera'
let type_vera.scopes = ['enum', 'class', 'virtual']
let type_vera.sro = '.' " Nesting doesn't seem to be possible
let type_vera.kinds = [
\ 'd:macros',
\ 'g:enums',
@@ -644,6 +629,7 @@ function! s:InitTypes()
\ 'v:variables',
\ 'p:programs'
\ ]
let type_vera.sro = '.' " Nesting doesn't seem to be possible
let type_vera.kind2scope = {
\ 'g' : 'enum',
\ 'c' : 'class',
@@ -827,14 +813,17 @@ function! s:OpenWindow(autoclose)
" If the tagbar window is already open jump to it
let tagbarwinnr = bufwinnr('__Tagbar__')
if tagbarwinnr != -1 && winnr() != tagbarwinnr
execute tagbarwinnr . 'wincmd w'
if tagbarwinnr != -1
if winnr() != tagbarwinnr
execute tagbarwinnr . 'wincmd w'
endif
return
endif
" If we're in the tagbar window don't do anything
if winnr() == tagbarwinnr
return
" Expand the Vim window to accomodate for the Tagbar window if requested
if g:tagbar_expand && !s:window_expanded && has('gui_running')
let &columns += g:tagbar_width + 1
let s:window_expanded = 1
endif
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
@@ -880,21 +869,6 @@ function! s:OpenWindow(autoclose)
let w:autoclose = a:autoclose
syntax match Comment '^" .*' " Comments
syntax match Identifier '^ [^: ]\+[^:]\+$' " Non-scoped kinds
syntax match Title '[^(* ]\+\ze\*\? :' " Scope names
syntax match Type ' : \zs.*' " Scope types
syntax match SpecialKey '(.*)' " Signatures
syntax match NonText '\*\ze :' " Pseudo-tag identifiers
highlight default TagbarAccessPublic guifg=Green ctermfg=Green
highlight default TagbarAccessProtected guifg=Blue ctermfg=Blue
highlight default TagbarAccessPrivate guifg=Red ctermfg=Red
syntax match TagbarAccessPublic '^\s*+\ze[^ ]'
syntax match TagbarAccessProtected '^\s*#\ze[^ ]'
syntax match TagbarAccessPrivate '^\s*-\ze[^ ]'
if has('balloon_eval')
setlocal balloonexpr=TagbarBalloonExpr()
set ballooneval
@@ -915,9 +889,9 @@ function! s:OpenWindow(autoclose)
execute 'wincmd p'
" Jump back to the tagbar window if autoclose is set. Can't just stay in
" it since it wouldn't trigger the update event
if g:tagbar_autoclose || a:autoclose
" Jump back to the tagbar window if autoclose or autofocus is set. Can't
" just stay in it since it wouldn't trigger the update event
if g:tagbar_autoclose || a:autoclose || g:tagbar_autofocus
let tagbarwinnr = bufwinnr('__Tagbar__')
execute tagbarwinnr . 'wincmd w'
endif
@@ -930,6 +904,8 @@ function! s:CloseWindow()
return
endif
let tagbarbufnr = winbufnr(tagbarwinnr)
if winnr() == tagbarwinnr
if winbufnr(2) != -1
" Other windows are open, only close the tagbar one
@@ -948,6 +924,20 @@ function! s:CloseWindow()
exe winnum . 'wincmd w'
endif
endif
" If the Vim window has been expanded, and Tagbar is not open in any other
" tabpages, shrink the window again
if s:window_expanded
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
if index(tablist, tagbarbufnr) == -1
let &columns -= g:tagbar_width + 1
let s:window_expanded = 0
endif
endif
endfunction
" s:ZoomWindow() {{{2
@@ -977,6 +967,11 @@ function! s:ProcessFile(fname, ftype)
let ctags_args .= ' --extra= '
let ctags_args .= ' --sort=yes '
" Include extra type definitions
if has_key(typeinfo, 'deffile')
let ctags_args .= ' --options=' . typeinfo.deffile . ' '
endif
let ctags_type = typeinfo.ctagstype
let ctags_kinds = ""
@@ -1019,14 +1014,12 @@ function! s:ProcessFile(fname, ftype)
endif
endfor
if has_key(typeinfo, 'scopes') && !empty(typeinfo.scopes)
if has_key(typeinfo, 'kind2scope')
let scopedtags = []
for scope in typeinfo.scopes
let is_scoped = 'has_key(typeinfo.kind2scope, v:val.fields.kind) ||
\ has_key(v:val.fields, scope)'
let scopedtags += filter(copy(fileinfo.tags), is_scoped)
call filter(fileinfo.tags, '!(' . is_scoped . ')')
endfor
let is_scoped = 'has_key(typeinfo.kind2scope, v:val.fields.kind) ||
\ has_key(v:val, "scope")'
let scopedtags += filter(copy(fileinfo.tags), is_scoped)
call filter(fileinfo.tags, '!(' . is_scoped . ')')
let processedtags = []
call s:AddScopedTags(scopedtags, processedtags, '', '', 0, typeinfo)
@@ -1098,8 +1091,8 @@ function! s:ParseTagline(part1, part2, typeinfo)
" Make some information easier accessible
let taginfo.path = ''
let taginfo.fullpath = taginfo.name
if has_key(a:typeinfo, 'scopes')
for scope in a:typeinfo.scopes
if has_key(a:typeinfo, 'scope2kind')
for scope in keys(a:typeinfo.scope2kind)
if has_key(taginfo.fields, scope)
let taginfo.scope = scope
let taginfo.path = taginfo.fields[scope]
@@ -1483,6 +1476,11 @@ function! s:RenderContent(fname, ftype)
setlocal nomodifiable
" Make sure as much of the Tagbar content as possible is shown in the
" window by jumping to the top after drawing
execute 1
call winline()
let &lazyredraw = lazyredraw_save
if !in_tagbar
@@ -1568,6 +1566,7 @@ function! s:ToggleHelp()
endif
execute 1
redraw
endfunction
" User actions {{{1
@@ -1601,11 +1600,11 @@ function! s:HighlightTag(fname)
match none
" No tag above cursor position so don't do anything
if tagline == 0
execute 1
call winline()
execute prevwinnr . 'wincmd w'
let &eventignore = eventignore_save
redraw
return
endif
@@ -1625,6 +1624,8 @@ function! s:HighlightTag(fname)
execute prevwinnr . 'wincmd w'
let &eventignore = eventignore_save
redraw
endfunction
" s:JumpToTag() {{{2
@@ -1654,6 +1655,8 @@ function! s:JumpToTag()
.foldopen!
endif
redraw
if g:tagbar_autoclose || autoclose
call s:CloseWindow()
else
@@ -1676,6 +1679,7 @@ endfunction
" s:CleanUp() {{{2
function! s:CleanUp()
silent! autocmd! TagbarAutoCmds
unlet s:current_file
unlet s:is_maximized
unlet s:compare_typeinfo
+27
View File
@@ -0,0 +1,27 @@
" File: tagbar.vim
" Description: Tagbar syntax settings
" Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/
" Version: 1.5
if exists("b:current_syntax")
finish
endif
syntax match Comment '^" .*' " Comments
syntax match Identifier '^ [^: ]\+[^:]\+$' " Non-scoped kinds
syntax match Title '[^(* ]\+\ze\*\? :' " Scope names
syntax match Type ' : \zs.*' " Scope types
syntax match SpecialKey '(.*)' " Signatures
syntax match NonText '\*\ze :' " Pseudo-tag identifiers
highlight default TagbarAccessPublic guifg=Green ctermfg=Green
highlight default TagbarAccessProtected guifg=Blue ctermfg=Blue
highlight default TagbarAccessPrivate guifg=Red ctermfg=Red
syntax match TagbarAccessPublic '^\s*+\ze[^ ]'
syntax match TagbarAccessProtected '^\s*#\ze[^ ]'
syntax match TagbarAccessPrivate '^\s*-\ze[^ ]'
let b:current_syntax = "tagbar"