Skip to content

Commit 847d693

Browse files
committed
commit version 2.7 (released on August 10, 2003)
1 parent 4715071 commit 847d693

File tree

1 file changed

+144
-38
lines changed

1 file changed

+144
-38
lines changed

plugin/taglist.vim

Lines changed: 144 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" File: taglist.vim
22
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3-
" Version: 2.6
4-
" Last Modified: June 9, 2003
3+
" Version: 2.7
4+
" Last Modified: August 10, 2003
55
"
66
" Overview
77
" --------
@@ -38,10 +38,9 @@
3838
" 15. Can be easily extended to support new languages. Support for existing
3939
" languages can be modified easily.
4040
"
41-
" To see the screenshots of the taglist plugin in different environments,
42-
" visit the following page:
41+
" You can visit the taglist plugin home page for more information:
4342
"
44-
" http://www.geocities.com/yegappan/taglist/screenshots.html
43+
" http://www.geocities.com/yegappan/taglist
4544
"
4645
" This plugin relies on the exuberant ctags utility to dynamically generate
4746
" the tag listing. You can download the exuberant ctags utility from
@@ -119,10 +118,11 @@
119118
"
120119
" This plugin will automatically highlight the name of the current tag. The
121120
" tag name will be highlighted after 'updatetime' milliseconds. The default
122-
" value for this Vim option is 4 seconds. You can also use the ":TlistSync"
123-
" command to force the highlighting of the current tag. You can map a key to
124-
" invoke this command. For example, the following command creates a normal
125-
" mapping for the <F9> key to highlight the current tag name.
121+
" value for this Vim option is 4 seconds. You should not set the 'updatetime'
122+
" option to very low values to avoid unexpected problems. You can also use the
123+
" ":TlistSync" command to force the highlighting of the current tag. You can
124+
" map a key to invoke this command. For example, the following command creates
125+
" a normal mapping for the <F9> key to highlight the current tag name.
126126
"
127127
" nnoremap <silent> <F9> :TlistSync<CR>
128128
"
@@ -169,6 +169,16 @@
169169
" ? Display help
170170
"
171171
"
172+
" You can use the ":TlistUpdate" command to update the tags for the current
173+
" buffer after you made some changes to it. This is equivalent to pressing 'u'
174+
" in the taglist window. You should save the modified buffer before you update
175+
" the tag list for it. Otherwise the listed tags will not include the new tags
176+
" created in the buffer. You can map a key to invoke this command. For
177+
" example, the following command creates a normal mode mapping for the <F7>
178+
" key to update the taglist window.
179+
"
180+
" nnoremap <silent> <F7> :TlistUpdate<CR>
181+
"
172182
" You can use the ":TlistShowPrototype" command to display the prototype of
173183
" a function in the specified line number. For example,
174184
"
@@ -186,6 +196,34 @@
186196
"
187197
" let winManagerWindowLayout = 'FileExplorer|TagList'
188198
"
199+
" If you have more than one tag with the same name and prototype in a file,
200+
" then when you jump to one tag, the cursor may be positioned at the location
201+
" of the other tag. For example, in a C++ file if you have functions with the
202+
" same name and prototype in a file, then you will see this problem. This is
203+
" due to the fact that the taglist plugin uses the search pattern generated by
204+
" the exuberant ctags tool to position the cursor for a selected tag. The
205+
" exuberant ctags generates the same search pattern for tags with the same
206+
" prototype.
207+
"
208+
" The following highlight groups are defined and used to highlight the various
209+
" entities in the taglist window:
210+
"
211+
" TagListTagName - Used for tag names
212+
" TagListTagScope - Used for tag scope
213+
" TagListTitle - Used for tag titles
214+
" TagListComment - Used for comments in the taglist window
215+
" TagListSortBy - Used for "sort by" text
216+
" TagListCurDir - Used for current directory name
217+
"
218+
" By default, these highlight groups are linked to the standard Vim highlight
219+
" groups. If you want to change these highlight groups, you can prepend 'My'
220+
" to the above highlight group names and define them in your .vimrc file. The
221+
" taglist plugin will use the defined highlight groups instead of the default
222+
" groups. For example, to change the highlighting used for tag names, you can
223+
" use:
224+
"
225+
" highlight MyTagListTagName guifg=cyan
226+
"
189227
" Configuration
190228
" -------------
191229
" By changing the following variables you can configure the behavior of this
@@ -922,32 +960,57 @@ function! s:Tlist_Init_Window(bufnum)
922960
" Mark the buffer as not modifiable
923961
setlocal nomodifiable
924962

925-
" Highlight the comments
963+
" Define taglist window element highlighting
926964
if has('syntax')
927965
syntax match TagListComment '^" .*'
928966
syntax match TagListSortBy '^" Sorted by .*'
929967
syntax match TagListCurDir '^"= .*'
930-
syntax match TagScope '\s\[.\{-\}\]$'
968+
syntax match TagListTagScope '\s\[.\{-\}\]$'
931969

932-
" Colors used to highlight the selected tag name
933-
highlight clear TagName
970+
" Define the highlighting only if the colors are supported
934971
if has('gui_running') || &t_Co > 2
935-
highlight link TagName Search
972+
" Colors to highlight various taglist window elements
973+
" If user defined highlighting group exists, then use them.
974+
" Otherwise, use default highlight groups.
975+
if hlexists('MyTagListTagName')
976+
highlight link TagListTagName MyTagListTagName
977+
else
978+
highlight link TagListTagName Search
979+
endif
980+
" Colors to highlight comments and titles
981+
if hlexists('MyTagListComment')
982+
highlight link TagListComment MyTagListComment
983+
else
984+
highlight clear TagListComment
985+
highlight link TagListComment Comment
986+
endif
987+
if hlexists('MyTagListTitle')
988+
highlight link TagListTitle MyTagListTitle
989+
else
990+
highlight clear TagListTitle
991+
highlight link TagListTitle Title
992+
endif
993+
if hlexists('MyTagListSortBy')
994+
highlight link TagListSortBy MyTagListSortBy
995+
else
996+
highlight clear TagListSortBy
997+
highlight link TagListSortBy String
998+
endif
999+
if hlexists('MyTagListCurDir')
1000+
highlight link TagListCurDir MyTagListCurDir
1001+
else
1002+
highlight clear TagListCurDir
1003+
highlight link TagListCurDir Statement
1004+
endif
1005+
if hlexists('MyTagListTagScope')
1006+
highlight link TagListTagScope MyTagListTagScope
1007+
else
1008+
highlight clear TagListTagScope
1009+
highlight link TagListTagScope Identifier
1010+
endif
9361011
else
937-
highlight TagName term=reverse cterm=reverse
1012+
highlight TagListTagName term=reverse cterm=reverse
9381013
endif
939-
940-
" Colors to highlight comments and titles
941-
highlight clear TagListComment
942-
highlight link TagListComment Comment
943-
highlight clear TagListTitle
944-
highlight link TagListTitle Title
945-
highlight clear TagListSortBy
946-
highlight link TagListSortBy String
947-
highlight clear TagListCurDir
948-
highlight link TagListCurDir Statement
949-
highlight clear TagScope
950-
highlight link TagScope Identifier
9511014
endif
9521015

9531016
" Folding related settings
@@ -1052,7 +1115,7 @@ function! s:Tlist_Post_Close_Cleanup()
10521115
match none
10531116

10541117
if has('syntax')
1055-
silent! syntax clear TagListTitle
1118+
silent! syntax clear
10561119
endif
10571120

10581121
" Remove the left mouse click mapping if it was setup initially
@@ -1374,13 +1437,15 @@ endfunction
13741437
function! s:Tlist_Close_Window()
13751438
" Make sure the taglist window exists
13761439
let winnum = bufwinnr(g:TagList_title)
1377-
if winnum != -1
1378-
" Jump to the window if not already there
1379-
if winnr() != winnum
1380-
exe winnum . 'wincmd w'
1381-
endif
1382-
close
1440+
if winnum == -1
1441+
call s:Tlist_Warning_Msg('Error: Taglist window is not open')
1442+
return
1443+
endif
1444+
" Jump to the window if not already there
1445+
if winnr() != winnum
1446+
exe winnum . 'wincmd w'
13831447
endif
1448+
close
13841449
endfunction
13851450

13861451
" Tlist_Toggle_Window()
@@ -1548,6 +1613,45 @@ function! s:Tlist_Change_Sort()
15481613
call search(curline, 'w')
15491614
endfunction
15501615

1616+
" Tlist_Update_Tags()
1617+
" Update taglist for the current buffer by regenerating the tag list
1618+
" Contributed by WEN Guopeng.
1619+
function! s:Tlist_Update_Tags()
1620+
" If taglist window is not open, show an error message:
1621+
let winnum = bufwinnr(g:TagList_title)
1622+
if winnum == -1
1623+
call s:Tlist_Warning_Msg('Error: Taglist window is not open')
1624+
return 0
1625+
endif
1626+
1627+
" Update the tag list window only if it's open
1628+
if winnr() == winnum
1629+
" Already in the taglist window, simply update the window content
1630+
call s:Tlist_Update_Window()
1631+
else
1632+
" First check the current buffer is modified or not:
1633+
if &modified
1634+
let msg = "No write since last change, tag list may be inaccurate"
1635+
call s:Tlist_Warning_Msg(msg)
1636+
endif
1637+
1638+
" Goto the taglist window, update it and get back to the original
1639+
" window:
1640+
let curbufnr = bufnr('%')
1641+
exe winnum . 'wincmd w'
1642+
call s:Tlist_Update_Window()
1643+
1644+
" Need to jump back to the original window only if we are not
1645+
" already in that window
1646+
let winnum = bufwinnr(curbufnr)
1647+
if winnr() != winnum
1648+
exe winnum . 'wincmd w'
1649+
endif
1650+
endif
1651+
1652+
return 1
1653+
endfunction
1654+
15511655
" Tlist_Update_Window()
15521656
" Update the window by regenerating the tag list
15531657
function! s:Tlist_Update_Window()
@@ -1615,9 +1719,9 @@ function! s:Tlist_Highlight_Tagline()
16151719

16161720
" Highlight the current selected name
16171721
if g:Tlist_Display_Prototype == 0
1618-
exe 'match TagName /\%' . line('.') . 'l\s\+\zs.*/'
1722+
exe 'match TagListTagName /\%' . line('.') . 'l\s\+\zs.*/'
16191723
else
1620-
exe 'match TagName /\%' . line('.') . 'l.*/'
1724+
exe 'match TagListTagName /\%' . line('.') . 'l.*/'
16211725
endif
16221726
endfunction
16231727

@@ -1629,7 +1733,7 @@ endfunction
16291733
function! s:Tlist_Jump_To_Tag(win_ctrl)
16301734
" Do not process comment lines and empty lines
16311735
let curline = getline('.')
1632-
if curline == '' || curline[0] == '"'
1736+
if curline =~ '^\s*$' || curline[0] == '"'
16331737
return
16341738
endif
16351739

@@ -1732,7 +1836,7 @@ function! s:Tlist_Show_Tag_Prototype()
17321836

17331837
" Do not process comment lines and empty lines
17341838
let curline = getline('.')
1735-
if curline == '' || curline[0] == '"'
1839+
if curline =~ '^\s*$' || curline[0] == '"'
17361840
return
17371841
endif
17381842

@@ -1851,6 +1955,7 @@ function! s:Tlist_Highlight_Tag(bufnum, curline)
18511955
" Make sure the taglist window is present
18521956
let winnum = bufwinnr(g:TagList_title)
18531957
if winnum == -1
1958+
call s:Tlist_Warning_Msg('Error: Taglist window is not open')
18541959
return
18551960
endif
18561961

@@ -1979,6 +2084,7 @@ endif
19792084
" Define the user commands to manage the taglist window
19802085
command! -nargs=0 Tlist call s:Tlist_Toggle_Window(bufnr('%'))
19812086
command! -nargs=0 TlistClose call s:Tlist_Close_Window()
2087+
command! -nargs=0 TlistUpdate call s:Tlist_Update_Tags()
19822088
command! -nargs=0 TlistSync call s:Tlist_Highlight_Tag(bufnr('%'), line('.'))
19832089
command! -nargs=? TlistShowPrototype echo s:Tlist_Get_Tag_Prototype_By_Line(<q-args>)
19842090

0 commit comments

Comments
 (0)