11" File: taglist.vim
22" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3- " Version: 4.0 Beta 4
4- " Last Modified: April 12 , 2006
3+ " Version: 4.0
4+ " Last Modified: September 6 , 2006
55"
66" The "Tag List" plugin is a source code browser plugin for Vim and provides
77" an overview of the structure of the programming language files and allows
@@ -252,20 +252,20 @@ if !exists('loaded_taglist')
252252 autocmd BufFilePost __Tag_List__ call s: Tlist_Vim_Session_Load ()
253253
254254 " Define the user commands to manage the taglist window
255- command ! -nargs =0 TlistToggle call s: Tlist_Window_Toggle ()
256- command ! -nargs =0 TlistOpen call s: Tlist_Window_Open ()
255+ command ! -nargs =0 - bar TlistToggle call s: Tlist_Window_Toggle ()
256+ command ! -nargs =0 - bar TlistOpen call s: Tlist_Window_Open ()
257257 " For backwards compatiblity define the Tlist command
258- command ! -nargs =0 Tlist TlistToggle
258+ command ! -nargs =0 - bar Tlist TlistToggle
259259 command ! -nargs =+ -complete =file TlistAddFiles
260260 \ call s: Tlist_Add_Files (<f-args> )
261261 command ! -nargs =+ -complete =dir TlistAddFilesRecursive
262262 \ call s: Tlist_Add_Files_Recursive (<f-args> )
263- command ! -nargs =0 TlistClose call s: Tlist_Window_Close ()
264- command ! -nargs =0 TlistUpdate call s: Tlist_Update_Current_File ()
265- command ! -nargs =0 TlistHighlightTag call s: Tlist_Window_Highlight_Tag (
263+ command ! -nargs =0 - bar TlistClose call s: Tlist_Window_Close ()
264+ command ! -nargs =0 - bar TlistUpdate call s: Tlist_Update_Current_File ()
265+ command ! -nargs =0 - bar TlistHighlightTag call s: Tlist_Window_Highlight_Tag (
266266 \ fnamemodify (bufname (' %' ), ' :p' ), line (' .' ), 2 , 1 )
267267 " For backwards compatiblity define the TlistSync command
268- command ! -nargs =0 TlistSync TlistHighlightTag
268+ command ! -nargs =0 - bar TlistSync TlistHighlightTag
269269 command ! -nargs =* -complete =buffer TlistShowPrototype
270270 \ echo Tlist_Get_Tag_Prototype_By_Line (<f-args> )
271271 command ! -nargs =* -complete =buffer TlistShowTag
@@ -274,14 +274,14 @@ if !exists('loaded_taglist')
274274 \ call s: Tlist_Session_Load (<q-args> )
275275 command ! -nargs =* -complete =file TlistSessionSave
276276 \ call s: Tlist_Session_Save (<q-args> )
277- command ! TlistLock let Tlist_Auto_Update= 0
278- command ! TlistUnlock let Tlist_Auto_Update= 1
277+ command ! TlistLock - bar let Tlist_Auto_Update= 0
278+ command ! TlistUnlock - bar let Tlist_Auto_Update= 1
279279
280280 " Commands for enabling/disabling debug and to display debug messages
281- command ! -nargs =? -complete =file TlistDebug
281+ command ! -nargs =? -complete =file - bar TlistDebug
282282 \ call s: Tlist_Debug_Enable (<q-args> )
283- command ! -nargs =0 TlistUndebug call s: Tlist_Debug_Disable ()
284- command ! -nargs =0 TlistMessages echo s: tlist_msg
283+ command ! -nargs =0 - bar TlistUndebug call s: Tlist_Debug_Disable ()
284+ command ! -nargs =0 - bar TlistMessages echo s: tlist_msg
285285
286286 " Define autocommands to autoload the taglist plugin when needed.
287287
@@ -468,7 +468,7 @@ let s:tlist_def_yacc_settings = 'yacc;l:label'
468468" ------------------- end of language specific options --------------------
469469
470470" Vim window size is changed by the taglist plugin or not
471- let s: tlist_winsize_chgd = 0
471+ let s: tlist_winsize_chgd = -1
472472" Taglist window is maximized or not
473473let s: tlist_win_maximized = 0
474474" Name of files in the taglist
@@ -1244,20 +1244,22 @@ function! s:Tlist_Window_Create()
12441244 " Horizontal window height
12451245 let win_size = g: Tlist_WinHeight
12461246 else
1247- " Open a vertically split window. Increase the window size, if
1248- " needed, to accomodate the new window
1249- if g: Tlist_Inc_Winwidth &&
1250- \ &columns < (80 + g: Tlist_WinWidth )
1251- " Save the original window position
1252- let s: tlist_pre_winx = getwinposx ()
1253- let s: tlist_pre_winy = getwinposy ()
1254-
1255- " one extra column is needed to include the vertical split
1256- let &columns = &columns + g: Tlist_WinWidth + 1
1257-
1258- let s: tlist_winsize_chgd = 1
1259- else
1260- let s: tlist_winsize_chgd = 0
1247+ if s: tlist_winsize_chgd == -1
1248+ " Open a vertically split window. Increase the window size, if
1249+ " needed, to accomodate the new window
1250+ if g: Tlist_Inc_Winwidth &&
1251+ \ &columns < (80 + g: Tlist_WinWidth )
1252+ " Save the original window position
1253+ let s: tlist_pre_winx = getwinposx ()
1254+ let s: tlist_pre_winy = getwinposy ()
1255+
1256+ " one extra column is needed to include the vertical split
1257+ let &columns = &columns + g: Tlist_WinWidth + 1
1258+
1259+ let s: tlist_winsize_chgd = 1
1260+ else
1261+ let s: tlist_winsize_chgd = 0
1262+ endif
12611263 endif
12621264
12631265 if g: Tlist_Use_Right_Window
@@ -1315,6 +1317,26 @@ function! s:Tlist_Window_Zoom()
13151317 endif
13161318endfunction
13171319
1320+ " Tlist_Ballon_Expr
1321+ " When the mouse cursor is over a tag in the taglist window, display the
1322+ " tag prototype (balloon)
1323+ function ! Tlist_Ballon_Expr ()
1324+ " Get the file index
1325+ let fidx = s: Tlist_Window_Get_File_Index_By_Linenum (v: beval_lnum )
1326+ if fidx == -1
1327+ return ' '
1328+ endif
1329+
1330+ " Get the tag output line for the current tag
1331+ let tidx = s: Tlist_Window_Get_Tag_Index (fidx, v: beval_lnum )
1332+ if tidx == 0
1333+ return ' '
1334+ endif
1335+
1336+ " Get the tag search pattern and display it
1337+ return s: Tlist_Get_Tag_Prototype (fidx, tidx)
1338+ endfunction
1339+
13181340" Tlist_Window_Check_Width
13191341" Check the width of the taglist window. For horizontally split windows, the
13201342" 'winfixheight' option is used to fix the height of the window. For
@@ -1341,6 +1363,32 @@ function! s:Tlist_Window_Check_Width()
13411363 endif
13421364endfunction
13431365
1366+ " Tlist_Window_Exit_Only_Window
1367+ " If the 'Tlist_Exit_OnlyWindow' option is set, then exit Vim if only the
1368+ " taglist window is present.
1369+ function ! s: Tlist_Window_Exit_Only_Window ()
1370+ " Before quitting Vim, delete the taglist buffer so that
1371+ " the '0 mark is correctly set to the previous buffer.
1372+ if v: version < 700
1373+ if winbufnr (2 ) == -1
1374+ bdelete
1375+ quit
1376+ endif
1377+ else
1378+ if winbufnr (2 ) == -1
1379+ if tabpagenr (' $' ) == 1
1380+ " Only one tag page is present
1381+ bdelete
1382+ quit
1383+ else
1384+ " More than one tab page is present. Close only the current
1385+ " tab page
1386+ close
1387+ endif
1388+ endif
1389+ endif
1390+ endfunction
1391+
13441392" Tlist_Window_Init
13451393" Set the default options for the taglist window
13461394function ! s: Tlist_Window_Init ()
@@ -1439,6 +1487,12 @@ function! s:Tlist_Window_Init()
14391487 set winfixwidth
14401488 endif
14411489
1490+ " Setup balloon evaluation to display tag prototype
1491+ if v: version >= 700 && has (' balloon_eval' )
1492+ setlocal balloonexpr = Tlist_Ballon_Expr ()
1493+ set ballooneval
1494+ endif
1495+
14421496 " Setup the cpoptions properly for the maps to work
14431497 let old_cpoptions = &cpoptions
14441498 set cpoptions &vim
@@ -1531,17 +1585,15 @@ function! s:Tlist_Window_Init()
15311585
15321586 " Adjust the Vim window width when taglist window is closed
15331587 autocmd BufUnload __Tag_List__ call s: Tlist_Post_Close_Cleanup ()
1534- " Close the fold for this buffer when it's not visible in any window
1588+ " Close the fold for this buffer when leaving the buffer
15351589 if g: Tlist_File_Fold_Auto_Close
1536- autocmd BufWinLeave * silent
1590+ autocmd BufWinLeave , BufLeave * silent
15371591 \ call s: Tlist_Window_Close_File_Fold (expand (' <afile>:p' ))
15381592 endif
15391593 " Exit Vim itself if only the taglist window is present (optional)
15401594 if g: Tlist_Exit_OnlyWindow
1541- " Before quitting Vim, delete the taglist buffer so that
1542- " the '0 mark is correctly set to the previous buffer.
1543- autocmd BufEnter __Tag_List__ nested if winbufnr (2 ) == -1 |
1544- \ bdelete | quit | endif
1595+ autocmd BufEnter __Tag_List__ nested
1596+ \ call s: Tlist_Window_Exit_Only_Window ()
15451597 endif
15461598 if s: tlist_app_name != " winmanager" &&
15471599 \ ! g: Tlist_Process_File_Always &&
@@ -1670,7 +1722,7 @@ function! s:Tlist_Post_Close_Cleanup()
16701722
16711723 if s: tlist_app_name != " winmanager"
16721724 if g: Tlist_Use_Horiz_Window || g: Tlist_Inc_Winwidth == 0 ||
1673- \ s: tlist_winsize_chgd == 0 ||
1725+ \ s: tlist_winsize_chgd != 1 ||
16741726 \ &columns < (80 + g: Tlist_WinWidth )
16751727 " No need to adjust window width if using horizontally split taglist
16761728 " window or if columns is less than 101 or if the user chose not to
@@ -1689,6 +1741,8 @@ function! s:Tlist_Post_Close_Cleanup()
16891741 endif
16901742 endif
16911743
1744+ let s: tlist_winsize_chgd = -1
1745+
16921746 " Reset taglist state variables
16931747 if s: tlist_app_name == " winmanager"
16941748 let s: tlist_app_name = " none"
@@ -3006,6 +3060,15 @@ function! s:Tlist_Window_Open_File(win_ctrl, filename, tagpat)
30063060 " Mark the window, so that it can be reused.
30073061 let w: tlist_file_window = " yes"
30083062 else
3063+ if v: version >= 700
3064+ " If the file is opened in more than one window, then check
3065+ " whether the last accessed window has the selected file.
3066+ " If it does, then use that window.
3067+ let lastwin_bufnum = winbufnr (winnr (' #' ))
3068+ if bufnr (a: filename ) == lastwin_bufnum
3069+ let winnum = winnr (' #' )
3070+ endif
3071+ endif
30093072 exe winnum . ' wincmd w'
30103073
30113074 " If the user asked to jump to the tag in a new window, then split the
@@ -3824,21 +3887,21 @@ endfunction
38243887" Open the window only when files present in any of the Vim windows support
38253888" tags.
38263889function ! s: Tlist_Window_Check_Auto_Open ()
3827- let open = 0
3890+ let open_window = 0
38283891
38293892 let i = 1
38303893 let buf_num = winbufnr (i )
38313894 while buf_num != -1
38323895 let filename = fnamemodify (bufname (buf_num), ' :p' )
38333896 if ! s: Tlist_Skip_File (filename, getbufvar (buf_num, ' &filetype' ))
3834- let open = 1
3897+ let open_window = 1
38353898 break
38363899 endif
38373900 let i = i + 1
38383901 let buf_num = winbufnr (i )
38393902 endwhile
38403903
3841- if open
3904+ if open_window
38423905 call s: Tlist_Window_Toggle ()
38433906 endif
38443907endfunction
0 commit comments