11" File: taglist.vim
22" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3- " Version: 4.0
4- " Last Modified: September 6, 2006
3+ " Version: 4.1
4+ " Last Modified: September 10, 2006
5+ " Copyright: Copyright (C) 2002-2006 Yegappan Lakshmanan
6+ " Permission is hereby granted to use and distribute this code,
7+ " with or without modifications, provided that this copyright
8+ " notice is copied with it. Like anything else that's free,
9+ " taglist.vim is provided *as is* and comes with no warranty of any
10+ " kind, either expressed or implied. In no event will the copyright
11+ " holder be liable for any damamges resulting from the use of this
12+ " software.
513"
614" The "Tag List" plugin is a source code browser plugin for Vim and provides
715" an overview of the structure of the programming language files and allows
@@ -274,8 +282,8 @@ if !exists('loaded_taglist')
274282 \ call s: Tlist_Session_Load (<q-args> )
275283 command ! -nargs =* -complete =file TlistSessionSave
276284 \ call s: Tlist_Session_Save (<q-args> )
277- command ! TlistLock - bar let Tlist_Auto_Update= 0
278- command ! TlistUnlock - bar let Tlist_Auto_Update= 1
285+ command ! - bar TlistLock let Tlist_Auto_Update= 0
286+ command ! - bar TlistUnlock let Tlist_Auto_Update= 1
279287
280288 " Commands for enabling/disabling debug and to display debug messages
281289 command ! -nargs =? -complete =file - bar TlistDebug
@@ -649,7 +657,7 @@ let s:tlist_file_name_idx_cache = -1
649657" Tlist_Get_File_Index()
650658" Return the index of the specified filename
651659function ! s: Tlist_Get_File_Index (fname)
652- if s: tlist_file_count == 0
660+ if s: tlist_file_count == 0 || a: fname == ' '
653661 return -1
654662 endif
655663
@@ -1587,8 +1595,8 @@ function! s:Tlist_Window_Init()
15871595 autocmd BufUnload __Tag_List__ call s: Tlist_Post_Close_Cleanup ()
15881596 " Close the fold for this buffer when leaving the buffer
15891597 if g: Tlist_File_Fold_Auto_Close
1590- autocmd BufWinLeave , BufLeave * silent
1591- \ call s: Tlist_Window_Close_File_Fold (expand (' <afile>:p' ))
1598+ autocmd BufEnter * silent
1599+ \ call s: Tlist_Window_Open_File_Fold (expand (' <afile>:p' ))
15921600 endif
15931601 " Exit Vim itself if only the taglist window is present (optional)
15941602 if g: Tlist_Exit_OnlyWindow
@@ -2252,7 +2260,7 @@ function! s:Tlist_Process_File(filename, ftype)
22522260 let ttype = s: Tlist_Extract_Tagtype (one_line)
22532261
22542262 " Make sure the tag type is a valid and supported one
2255- if ttype == ' ' || stridx (s: ctags_flags , ttype) == -1
2263+ if ttype == ' ' || stridx (ctags_flags, ttype) == -1
22562264 " Line is not in proper tags format or Tag type is not
22572265 " supported
22582266 continue
@@ -3829,14 +3837,11 @@ endfunction
38293837" When a buffer is deleted, remove the file from the taglist
38303838autocmd BufDelete * silent call s: Tlist_Buffer_Removed (expand (' <afile>:p' ))
38313839
3832- " Tlist_Window_Close_File_Fold
3833- " Close the fold for the specified file
3834- function ! s: Tlist_Window_Close_File_Fold (filename)
3835- call s: Tlist_Log_Msg (' Tlist_Window_Close_File_Fold (' . a: filename . ' )' )
3836- " Make sure a valid filename is supplied
3837- if a: filename == ' '
3838- return
3839- endif
3840+ " Tlist_Window_Open_File_Fold
3841+ " Open the fold for the specified file and close the fold for all the
3842+ " other files
3843+ function ! s: Tlist_Window_Open_File_Fold (filename)
3844+ call s: Tlist_Log_Msg (' Tlist_Window_Open_File_Fold (' . a: filename . ' )' )
38403845
38413846 " Make sure the taglist window is present
38423847 let winnum = bufwinnr (g: TagList_title )
@@ -3845,13 +3850,6 @@ function! s:Tlist_Window_Close_File_Fold(filename)
38453850 return
38463851 endif
38473852
3848- " Get tag list index of the specified file
3849- let fidx = s: Tlist_Get_File_Index (a: filename )
3850- if fidx == -1
3851- " File not present in the taglist window
3852- return
3853- endif
3854-
38553853 " Save the original window number
38563854 let org_winnr = winnr ()
38573855 if org_winnr == winnum
@@ -3860,21 +3858,26 @@ function! s:Tlist_Window_Close_File_Fold(filename)
38603858 let in_taglist_window = 0
38613859 endif
38623860
3861+ if in_taglist_window
3862+ " When entering the taglist window, no need to update the folds
3863+ return
3864+ endif
3865+
38633866 " Go to the taglist window
38643867 if ! in_taglist_window
38653868 call s: Tlist_Exe_Cmd_No_Acmds (winnum . ' wincmd w' )
38663869 endif
38673870
3868- " Save the cursor position
3869- let save_lnum = line ( ' . ' )
3871+ " Close all the folds
3872+ silent ! % foldclose
38703873
3871- " Perform the requested action on the file
3872- " Close the fold for the file
3873- exe " silent! " . s: tlist_ { fidx}_start . " , " .
3874- \ s: tlist_ {fidx}_end . " foldclose "
3875-
3876- " Move the cursor to the original location
3877- exe save_lnum
3874+ " Get tag list index of the specified file
3875+ let fidx = s: Tlist_Get_File_Index ( a: filename )
3876+ if fidx != -1
3877+ " Open the fold for the file
3878+ exe " silent! " . s: tlist_ {fidx}_start . " , " .
3879+ \ s: tlist_ {fidx}_end . " foldopen "
3880+ endif
38783881
38793882 " Go back to the original window
38803883 if ! in_taglist_window
0 commit comments