Version 3.2

Added support for closing the tags tree for inactive files, removing the tags tree for deleted buffers, processing the tags when the taglist window is not opened, disabling the automatic highlighting of the current tag, displaying name of the current tag.
This commit is contained in:
Yegappan Lakshmanan 2004-04-25 00:00:00 +00:00 committed by Able Scraper
parent e5c42caaf2
commit b77977c318
2 changed files with 382 additions and 98 deletions

View File

@ -2,7 +2,7 @@
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 6.0 and above For Vim version 6.0 and above
Last change: 2003 Oct 29 Last change: 2004 April 24
1. Overview |taglist-intro| 1. Overview |taglist-intro|
2. Taglist on the internet |taglist-internet| 2. Taglist on the internet |taglist-internet|
@ -10,7 +10,7 @@ Last change: 2003 Oct 29
4. Installation |taglist-install| 4. Installation |taglist-install|
5. Usage |taglist-using| 5. Usage |taglist-using|
6. Configuration |taglist-configure| 6. Configuration |taglist-configure|
6. Commands |taglist-commands| 7. Commands |taglist-commands|
8. Extending |taglist-extend| 8. Extending |taglist-extend|
9. FAQ |taglist-faq| 9. FAQ |taglist-faq|
10. Todo |taglist-todo| 10. Todo |taglist-todo|
@ -99,7 +99,8 @@ by adding the following line to your .vimrc file: >
This plugin will not work in |compatible| mode. Make sure the |compatible| This plugin will not work in |compatible| mode. Make sure the |compatible|
option is not set. This plugin will not work if you run Vim in the option is not set. This plugin will not work if you run Vim in the
restricted mode (using the -Z command-line argument). This plugin also restricted mode (using the -Z command-line argument). This plugin also
assumes that the system() Vim function is supported. assumes that the system() Vim function is supported. Make sure that the
'C' flag is not set in the 'cpoptions' Vim option.
============================================================================== ==============================================================================
*taglist-install* *taglist-install*
@ -236,10 +237,14 @@ normal mode mapping for the <F7> key to update the taglist window. >
nnoremap <silent> <F7> :TlistUpdate<CR> nnoremap <silent> <F7> :TlistUpdate<CR>
< <
Taglist Session~ Taglist Session~
A taglist session refers to the group of files and their tags displayed in the
taglist window in a Vim session.
You can save and restore taglist sessions (and all the displayed tags) You can save and restore taglist sessions (and all the displayed tags)
using the TlistSessionSave and TlistSessionLoad commands. To save all using the TlistSessionSave and TlistSessionLoad commands.
the tags displayed in the taglist window in a file, use the TlistSessionSave
command and specify the filename: > To save all the tags displayed in the taglist window in a file, use the
TlistSessionSave command and specify the filename: >
:TlistSessionSave <file name> :TlistSessionSave <file name>
< <
@ -249,7 +254,14 @@ To load the saved taglist session, use the TlistSessionLoad command: >
< <
Information about the tags displayed for the files in the taglist window will Information about the tags displayed for the files in the taglist window will
be stored in the taglist session file. This will be used to restore the be stored in the taglist session file. This will be used to restore the
taglist window state later. taglist window state later. When you load a taglist session file, the tags
stored in the file will be added to the tags already displayed in the taglist
window.
The taglist session feature can be used to save the tags for large files or a
group of frequently used files (like a project). By using the taglist session
file, you can minimize the amount to time it takes to load/refresh the taglist
window for those files.
Changing the taglist window highlighting~ Changing the taglist window highlighting~
The following highlight groups are defined and used to highlight the various The following highlight groups are defined and used to highlight the various
@ -300,6 +312,8 @@ in the taglist window.
q Close the taglist window q Close the taglist window
? Display help ? Display help
The above keys will work in both the normal mode and the insert mode.
Using the taglist plugin with the winmanager plugin~ Using the taglist plugin with the winmanager plugin~
You can use the taglist plugin with the winmanager plugin. This will allow you You can use the taglist plugin with the winmanager plugin. This will allow you
to use the file explorer, buffer explorer and the taglist plugin at the same to use the file explorer, buffer explorer and the taglist plugin at the same
@ -442,6 +456,37 @@ window is open. >
let Tlist_Exit_OnlyWindow = 1 let Tlist_Exit_OnlyWindow = 1
< <
Tlist_File_Fold_Auto_Close~
By default, the tags tree displayed in the taglist window for all the buffers
will be opened. You can close/fold the tags tree for the files manually. To
automatically close the tags tree for inactive files, you can set the
Tlist_File_Fold_Auto_Close variable to 1. When this variable is set to 1, if
a Vim buffer is no longer displayed in a Vim window, the corresponding tags
tree in the taglist window will be collapsed/folded. When a buffer is loaded
in a Vim window, the corresponding tags tree will be opened.
>
let Tlist_File_Fold_Auto_Close = 1
<
Tlist_Auto_Highlight_Tag~
By default, the taglist plugin will highlight the current tag in the taglist
window. If you want to disable the highlighting of the current tag, then you
can set the Tlist_Auto_Highlight_Tag variable to zero. Note that even though
the current tag highlighting is disabled, the tags for a new file will still
be added to the taglist window.
>
let Tlist_Auto_Highlight_Tag = 0
<
Tlist_Process_File_Always~
By default, the taglist plugin will generate and process tags for new files
only when the taglist window is opened. When the taglist window is closed, the
taglist plugin will stop processing the tags for new files. You can set the
Tlist_Process_File_Always variable to 1 to generate the list of tags for new
files even when the taglist window is closed. When you open the taglist
window, the tags for all the files opened so far will be displayed.
>
let Tlist_Process_File_Always = 1
<
============================================================================== ==============================================================================
*taglist-commands* *taglist-commands*
7. Commands~ 7. Commands~
@ -449,33 +494,49 @@ window is open. >
The taglist plugin provides the following ex-mode commands: The taglist plugin provides the following ex-mode commands:
Tlist~ Tlist~
You can use the ":Tlist" command to open or close (toggle) the taglist window. Open or close (toggle) the taglist window. Opens the taglist window, if the
Invoking the ":Tlist" command when the taglist window is opened, will close window is not opened currently. Closes the taglist window, if the taglist
the taglist window. window is already opened.
TlistClose~ TlistClose~
You can use the ":TlistClose" command to close the taglist window. Close the taglist window. Can be used from any one of the Vim windows.
TlistUpdate~ TlistUpdate~
You can use the ":TlistUpdate" command to update the tags for the current Update the tags for the current buffer. When a file is changed and saved to
buffer after you made some changes to the buffer. You should save the disk, the taglist window will not be automatically updated to display the new
modified buffer before you update the taglist window. Otherwise the listed tags in the file. The ":TlistUpdate" command can be used to force an update of
tags will not include the new tags created in the buffer. the tags for the current file/buffer. As the taglist plugin uses the file
saved in the disk (instead of the file displayed in a Vim buffer), you should
save the modified buffer before you update the taglist window. Otherwise the
listed tags will not include the new tags created in the buffer.
TlistSync~ TlistSync~
You can use the ":TlistSync" command to highlight the current tag. Highlight the current tag in the taglist window. By default, the taglist
plugin periodically updates the taglist window to highlight the current tag.
The ":TlistSync" command can be used to force the taglist plugin to highlight
the current tag.
TlistShowPrototype~ TlistShowPrototype~
You can use the ":TlistShowPrototype" command to display the prototype Display the prototype of the tag near the specified line number. If the line
of a function in the specified line number. number is not specified, the current line number is used. A tag spans multiple
lines starting from the line where it is defined to the line before the next
tag. The ":TlistShowPrototype" command displays the prototype for the tag for
any line number in this range.
TlistShowTag~
Display the name of the tag defined near the specified line number. If the
line number is not specified, the current line number is used. A tag spans
multiple lines starting from the line where it is defined to the line before
the next tag. The ":TlistShowTag" command displays the tag name for any line
number in this range.
TlistSessionSave~ TlistSessionSave~
You can save the tags displayed in the taglist window to a file using Save the information about files and tags displayed in the taglist window to
the ":TlistSessionSave" command. the specified session file.
TlistSessionLoad~ TlistSessionLoad~
You can load a taglist session from a file using the ":TlistSessionLoad" Load information about files and tags stored from the specified session file
command. and update the taglist window with those files.
============================================================================== ==============================================================================
*taglist-extend* *taglist-extend*
@ -487,6 +548,9 @@ C#, Cobol, Eiffel, Erlang, Fortran, HTML, Java, Javascript, Lisp, Lua, Make,
Pascal, Perl, PHP, Python, Rexx, Ruby, Scheme, Shell, Slang, SML, Sql, TCL, Pascal, Perl, PHP, Python, Rexx, Ruby, Scheme, Shell, Slang, SML, Sql, TCL,
Verilog, Vim and Yacc. Verilog, Vim and Yacc.
You can modify the taglist plugin support for the above listed languages. You
can also extend the taglist plugin to add support for new languages.
If you want to add support for a new language to the taglist plugin, you need If you want to add support for a new language to the taglist plugin, you need
to first extend the exuberant ctags tool. For more information about extending to first extend the exuberant ctags tool. For more information about extending
exuberant ctags, visit http://ctags.sourceforge.net/EXTENDING.html exuberant ctags, visit http://ctags.sourceforge.net/EXTENDING.html
@ -502,6 +566,9 @@ in the buffer containing the desired file: >
:set filetype :set filetype
< <
For example, to modify the support for the perl language files, you have to
set the tlist_perl_settings variable.
The format of the value set in the tlist_xxx_settings variable is > The format of the value set in the tlist_xxx_settings variable is >
<language_name>;flag1:name1;flag2:name2;flag3:name3 <language_name>;flag1:name1;flag2:name2;flag3:name3
@ -517,7 +584,8 @@ functions, the 'f' flag should be used. For more information about the flags
supported by exuberant ctags for a particular language, read the help text supported by exuberant ctags for a particular language, read the help text
from the 'ctags --help' comand. The sub-field 'name' specifies the title from the 'ctags --help' comand. The sub-field 'name' specifies the title
text to use for displaying the tags of a particular type. For example, text to use for displaying the tags of a particular type. For example,
'name' can be set to 'functions'. 'name' can be set to 'functions'. This field can be set to any text
string name.
For example, to list only the classes and functions defined in a C++ For example, to list only the classes and functions defined in a C++
language file, add the following lines to your .vimrc file > language file, add the following lines to your .vimrc file >
@ -534,8 +602,22 @@ Functions" as the title for the function group, use >
let tlist_c_settings = 'c;f:My Functions' let tlist_c_settings = 'c;f:My Functions'
< <
When you set the tlist_xxx_settings variable, you will override the default
setting used by the taglist plugin for the 'xxx' language. You cannot add to
the options used by the taglist plugin for a particular file type.
To add support for a new language, set the tlist_xxx_settings variable To add support for a new language, set the tlist_xxx_settings variable
appropriately as described above. appropriately as described above. For example, to extend the taglist plugin
to support the latex language, you can use the following line (assuming, you
have already extended exuberant ctags to support the latex language): >
let tlist_tex_settings='latex;b:bibitem;c:command;l:label'
<
With the above line, when you edit files of filetype "tex" in Vim, the taglist
plugin will invoke the exuberant ctags tool with the "latex" filetype and with
the flags b, c and l to generate the tags. The text heading 'bibitem',
'command' and 'label' will be used for the tags which are generated for the
flags b, c and l respectively.
============================================================================== ==============================================================================
*taglist-faq* *taglist-faq*

View File

@ -1,7 +1,7 @@
" File: taglist.vim " File: taglist.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 3.1 " Version: 3.2
" Last Modified: Nov 1, 2003 " Last Modified: April 25, 2004
" "
" The "Tag List" plugin is a source code browser plugin for Vim and " The "Tag List" plugin is a source code browser plugin for Vim and
" provides an overview of the structure of source code files and allows " provides an overview of the structure of source code files and allows
@ -127,6 +127,21 @@ if !exists('Tlist_Exit_OnlyWindow')
let Tlist_Exit_OnlyWindow = 0 let Tlist_Exit_OnlyWindow = 0
endif endif
" Automatically close the folds for the non-active files in the taglist window
if !exists('Tlist_File_Fold_Auto_Close')
let Tlist_File_Fold_Auto_Close = 0
endif
" Automatically highlight the current tag
if !exists('Tlist_Auto_Highlight_Tag')
let Tlist_Auto_Highlight_Tag = 1
endif
" Process files even when the taglist window is not open
if !exists('Tlist_Process_File_Always')
let Tlist_Process_File_Always = 0
endif
"------------------- end of user configurable options -------------------- "------------------- end of user configurable options --------------------
" Initialize the taglist plugin local variables for the supported file types " Initialize the taglist plugin local variables for the supported file types
@ -145,7 +160,7 @@ let s:tlist_def_aspvbs_settings = 'asp;f:function;s:sub;v:variable'
let s:tlist_def_awk_settings = 'awk;f:function' let s:tlist_def_awk_settings = 'awk;f:function'
" beta language " beta language
let s:tlist_def_beta_settings = 'beta;f:fragment;s:pattern;v:virtual' let s:tlist_def_beta_settings = 'beta;f:fragment;s:slot;v:pattern'
" c language " c language
let s:tlist_def_c_settings = 'c;d:macro;g:enum;s:struct;u:union;t:typedef;' . let s:tlist_def_c_settings = 'c;d:macro;g:enum;s:struct;u:union;t:typedef;' .
@ -555,7 +570,7 @@ function! s:Tlist_Discard_TagInfo(fidx)
" Discard information about the tags defined in the file " Discard information about the tags defined in the file
let i = 1 let i = 1
while i <= s:tlist_{a:fidx}_tag_count while i <= s:tlist_{a:fidx}_tag_count
unlet s:tlist_{a:fidx}_tag_{i} unlet! s:tlist_{a:fidx}_tag_{i}
let i = i + 1 let i = i + 1
endwhile endwhile
@ -572,7 +587,7 @@ function! s:Tlist_Discard_TagInfo(fidx)
let s:tlist_{a:fidx}_{ttype}_count = 0 let s:tlist_{a:fidx}_{ttype}_count = 0
let j = 1 let j = 1
while j <= cnt while j <= cnt
unlet s:tlist_{a:fidx}_{ttype}_{j} unlet! s:tlist_{a:fidx}_{ttype}_{j}
let j = j + 1 let j = j + 1
endwhile endwhile
endif endif
@ -611,20 +626,20 @@ function! s:Tlist_Discard_FileInfo(fidx)
let i = 1 let i = 1
while i <= s:tlist_{ftype}_count while i <= s:tlist_{ftype}_count
let ttype = s:tlist_{ftype}_{i}_name let ttype = s:tlist_{ftype}_{i}_name
unlet s:tlist_{a:fidx}_{ttype} unlet! s:tlist_{a:fidx}_{ttype}
unlet s:tlist_{a:fidx}_{ttype}_start unlet! s:tlist_{a:fidx}_{ttype}_start
unlet s:tlist_{a:fidx}_{ttype}_count unlet! s:tlist_{a:fidx}_{ttype}_count
let i = i + 1 let i = i + 1
endwhile endwhile
unlet s:tlist_{a:fidx}_filename unlet! s:tlist_{a:fidx}_filename
unlet s:tlist_{a:fidx}_sort_type unlet! s:tlist_{a:fidx}_sort_type
unlet s:tlist_{a:fidx}_filetype unlet! s:tlist_{a:fidx}_filetype
unlet s:tlist_{a:fidx}_start unlet! s:tlist_{a:fidx}_start
unlet s:tlist_{a:fidx}_end unlet! s:tlist_{a:fidx}_end
unlet s:tlist_{a:fidx}_valid unlet! s:tlist_{a:fidx}_valid
unlet s:tlist_{a:fidx}_visible unlet! s:tlist_{a:fidx}_visible
unlet s:tlist_{a:fidx}_tag_count unlet! s:tlist_{a:fidx}_tag_count
endfunction endfunction
" Tlist_Remove_File_From_Display " Tlist_Remove_File_From_Display
@ -817,15 +832,6 @@ function! s:Tlist_Init_Window()
" Delete the contents of the buffer to the black-hole register " Delete the contents of the buffer to the black-hole register
silent! %delete _ silent! %delete _
" Mark the buffer as not modifiable
setlocal nomodifiable
" Restore the report option
let &report = old_report
" Mark the buffer as modifiable
setlocal modifiable
if g:Tlist_Compact_Format == 0 if g:Tlist_Compact_Format == 0
" Display help in non-compact mode " Display help in non-compact mode
call s:Tlist_Display_Help() call s:Tlist_Display_Help()
@ -834,6 +840,9 @@ function! s:Tlist_Init_Window()
" Mark the buffer as not modifiable " Mark the buffer as not modifiable
setlocal nomodifiable setlocal nomodifiable
" Restore the report option
let &report = old_report
" Define taglist window element highlighting " Define taglist window element highlighting
if has('syntax') if has('syntax')
syntax match TagListComment '^" .*' syntax match TagListComment '^" .*'
@ -884,6 +893,7 @@ function! s:Tlist_Init_Window()
" Folding related settings " Folding related settings
if has('folding') if has('folding')
setlocal foldenable setlocal foldenable
setlocal foldminlines=0
setlocal foldmethod=manual setlocal foldmethod=manual
setlocal foldcolumn=3 setlocal foldcolumn=3
setlocal foldtext=v:folddashes.getline(v:foldstart) setlocal foldtext=v:folddashes.getline(v:foldstart)
@ -918,7 +928,7 @@ function! s:Tlist_Init_Window()
nnoremap <buffer> <silent> + :silent! foldopen<CR> nnoremap <buffer> <silent> + :silent! foldopen<CR>
nnoremap <buffer> <silent> - :silent! foldclose<CR> nnoremap <buffer> <silent> - :silent! foldclose<CR>
nnoremap <buffer> <silent> * :silent! %foldopen!<CR> nnoremap <buffer> <silent> * :silent! %foldopen!<CR>
nnoremap <buffer> <silent> = :silent! %foldclose!<CR> nnoremap <buffer> <silent> = :silent! %foldclose<CR>
nnoremap <buffer> <silent> <kPlus> :silent! foldopen<CR> nnoremap <buffer> <silent> <kPlus> :silent! foldopen<CR>
nnoremap <buffer> <silent> <kMinus> :silent! foldclose<CR> nnoremap <buffer> <silent> <kMinus> :silent! foldclose<CR>
nnoremap <buffer> <silent> <kMultiply> :silent! %foldopen!<CR> nnoremap <buffer> <silent> <kMultiply> :silent! %foldopen!<CR>
@ -941,7 +951,7 @@ function! s:Tlist_Init_Window()
inoremap <buffer> <silent> + <C-o>:silent! foldopen<CR> inoremap <buffer> <silent> + <C-o>:silent! foldopen<CR>
inoremap <buffer> <silent> - <C-o>:silent! foldclose<CR> inoremap <buffer> <silent> - <C-o>:silent! foldclose<CR>
inoremap <buffer> <silent> * <C-o>:silent! %foldopen!<CR> inoremap <buffer> <silent> * <C-o>:silent! %foldopen!<CR>
inoremap <buffer> <silent> = <C-o>:silent! %foldclose!<CR> inoremap <buffer> <silent> = <C-o>:silent! %foldclose<CR>
inoremap <buffer> <silent> <kPlus> <C-o>:silent! foldopen<CR> inoremap <buffer> <silent> <kPlus> <C-o>:silent! foldopen<CR>
inoremap <buffer> <silent> <kMinus> <C-o>:silent! foldclose<CR> inoremap <buffer> <silent> <kMinus> <C-o>:silent! foldclose<CR>
inoremap <buffer> <silent> <kMultiply> <C-o>:silent! %foldopen!<CR> inoremap <buffer> <silent> <kMultiply> <C-o>:silent! %foldopen!<CR>
@ -966,14 +976,20 @@ function! s:Tlist_Init_Window()
autocmd CursorHold __Tag_List__ call s:Tlist_Show_Tag_Prototype() autocmd CursorHold __Tag_List__ call s:Tlist_Show_Tag_Prototype()
" Highlight the current tag " Highlight the current tag
autocmd CursorHold * silent call <SID>Tlist_Highlight_Tag( autocmd CursorHold * silent call <SID>Tlist_Highlight_Tag(
\ fnamemodify(bufname('%'), ':p'), line('.')) \ fnamemodify(bufname('%'), ':p'), line('.'), 1)
" Adjust the Vim window width when taglist window is closed " Adjust the Vim window width when taglist window is closed
autocmd BufUnload __Tag_List__ call <SID>Tlist_Post_Close_Cleanup() autocmd BufUnload __Tag_List__ call <SID>Tlist_Post_Close_Cleanup()
" Close the fold for this buffer when it's not visible in any window
autocmd BufWinLeave * silent call <SID>Tlist_Update_File_Display(
\ fnamemodify(expand('<afile>'), ':p'), 1)
" Remove the file from the list when it's buffer is deleted
autocmd BufDelete * silent call <SID>Tlist_Update_File_Display(
\ fnamemodify(expand('<afile>'), ':p'), 2)
" Exit Vim itself if only the taglist window is present (optional) " Exit Vim itself if only the taglist window is present (optional)
autocmd BufEnter __Tag_List__ call <SID>Tlist_Check_Only_Window() autocmd BufEnter __Tag_List__ call <SID>Tlist_Check_Only_Window()
if !s:tlist_part_of_winmanager if !s:tlist_part_of_winmanager && !g:Tlist_Process_File_Always
" Auto refresh the taglist window " Auto refresh the taglist window
autocmd BufEnter * call <SID>Tlist_Refresh_Window() autocmd BufEnter * call <SID>Tlist_Refresh()
endif endif
augroup end augroup end
@ -986,6 +1002,16 @@ function! s:Tlist_Init_Window()
call s:Tlist_Explore_File(s:tlist_{i}_filename, s:tlist_{i}_filetype) call s:Tlist_Explore_File(s:tlist_{i}_filename, s:tlist_{i}_filetype)
let i = i + 1 let i = i + 1
endwhile endwhile
" If Tlist_File_Fold_Auto_Close option is set, then close all the
" folds
if g:Tlist_File_Fold_Auto_Close
if has('folding')
" Close all the folds
silent! %foldclose
endif
endif
endfunction endfunction
" Tlist_Post_Close_Cleanup() " Tlist_Post_Close_Cleanup()
@ -1070,6 +1096,12 @@ function! s:Tlist_Explore_File(filename, ftype)
" Goto the first line in the file " Goto the first line in the file
exe s:tlist_{fidx}_start exe s:tlist_{fidx}_start
" If the line is inside a fold, open the fold
if has('folding')
exe "silent! " . s:tlist_{fidx}_start . "," .
\ s:tlist_{fidx}_end . "foldopen!"
endif
return return
endif endif
@ -1082,12 +1114,6 @@ function! s:Tlist_Explore_File(filename, ftype)
if !file_exists || !s:tlist_{fidx}_valid if !file_exists || !s:tlist_{fidx}_valid
let ret_fidx = s:Tlist_Process_File(a:filename, a:ftype) let ret_fidx = s:Tlist_Process_File(a:filename, a:ftype)
if ret_fidx == -1 if ret_fidx == -1
if file_exists
" If the tags for the file were previously displayed and now
" we are not able to get the tag information then discard the
" file information
call s:Tlist_Remove_File(fidx, 0)
endif
return return
endif endif
let fidx = ret_fidx let fidx = ret_fidx
@ -1306,13 +1332,13 @@ function! s:Tlist_Process_File(filename, ftype)
" Handle errors " Handle errors
if v:shell_error && cmd_output != '' if v:shell_error && cmd_output != ''
call s:Tlist_Warning_Msg(cmd_output) call s:Tlist_Warning_Msg(cmd_output)
return -1 return fidx
endif endif
" No tags for current file " No tags for current file
if cmd_output == '' if cmd_output == ''
call s:Tlist_Warning_Msg('No tags found for ' . a:filename) call s:Tlist_Warning_Msg('No tags found for ' . a:filename)
return -1 return fidx
endif endif
" Process the ctags output one line at a time. Separate the tag output " Process the ctags output one line at a time. Separate the tag output
@ -1392,6 +1418,21 @@ function! s:Tlist_Process_File(filename, ftype)
return fidx return fidx
endfunction endfunction
" Tlist_Update_File_Tags
" Update the tags for a file (if needed)
function s:Tlist_Update_File_Tags(filename, ftype)
" First check whether the file already exists
let fidx = s:Tlist_Get_File_Index(a:filename)
" File exists and the tags are valid
if fidx != -1 && s:tlist_{fidx}_valid
return
endif
" Process and generate a list of tags defined in the file
call s:Tlist_Process_File(a:filename, a:ftype)
endfunction
" Tlist_Close_Window " Tlist_Close_Window
" Close the taglist window " Close the taglist window
function! s:Tlist_Close_Window() function! s:Tlist_Close_Window()
@ -1404,7 +1445,11 @@ function! s:Tlist_Close_Window()
if winnr() == winnum if winnr() == winnum
" Already in the taglist window. Close it and return " Already in the taglist window. Close it and return
if winbufnr(2) != -1
" If a window other than the taglist window is open,
" then only close the taglist window.
close close
endif
else else
" Goto the taglist window, close it and then come back to the " Goto the taglist window, close it and then come back to the
" original window " original window
@ -1453,12 +1498,13 @@ function! s:Tlist_Toggle_Window(bufnum)
call s:Tlist_Explore_File(filename, ftype) call s:Tlist_Explore_File(filename, ftype)
" Highlight the current tag " Highlight the current tag
call s:Tlist_Highlight_Tag(filename, curline) call s:Tlist_Highlight_Tag(filename, curline, 1)
" Go back to the original window " Go back to the original window
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1 let s:Tlist_Skip_Refresh = 1
wincmd p wincmd p
let s:Tlist_Skip_Refresh = 0 let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endfunction endfunction
" Tlist_Extract_Tagtype " Tlist_Extract_Tagtype
@ -1500,17 +1546,18 @@ function! s:Tlist_Add_File(filename, ftype)
call s:Tlist_Explore_File(a:filename, a:ftype) call s:Tlist_Explore_File(a:filename, a:ftype)
endfunction endfunction
" Tlist_Refresh_Window() " Tlist_Refresh()
" Refresh the taglist window " Refresh the taglist
function! s:Tlist_Refresh_Window() function! s:Tlist_Refresh()
" If we are entering the buffer from one of the taglist functions, then " If we are entering the buffer from one of the taglist functions, then
" no need to refresh the taglist window again. " no need to refresh the taglist window again.
if s:Tlist_Skip_Refresh if s:Tlist_Skip_Refresh || s:tlist_part_of_winmanager
return return
endif endif
" Skip buffers with 'buftype' set to nofile, nowrite, quickfix or help " Skip buffers with 'buftype' set to nofile, nowrite, quickfix or help
if &buftype != '' if &buftype != ''
let s:tlist_cur_fidx = -1
return return
endif endif
@ -1519,6 +1566,7 @@ function! s:Tlist_Refresh_Window()
" If the file doesn't support tag listing, skip it " If the file doesn't support tag listing, skip it
if s:Tlist_Skip_File(filename, ftype) if s:Tlist_Skip_File(filename, ftype)
let s:tlist_cur_fidx = -1
return return
endif endif
@ -1527,27 +1575,50 @@ function! s:Tlist_Refresh_Window()
" Make sure the taglist window is open. Otherwise, no need to refresh " Make sure the taglist window is open. Otherwise, no need to refresh
let winnum = bufwinnr(g:TagList_title) let winnum = bufwinnr(g:TagList_title)
if winnum == -1 if winnum == -1
if g:Tlist_Process_File_Always
call s:Tlist_Update_File_Tags(filename, ftype)
endif
return return
endif endif
let fidx = s:Tlist_Get_File_Index(filename) let fidx = s:Tlist_Get_File_Index(filename)
if fidx != -1 && s:tlist_cur_fidx == fidx if fidx != -1
" If the tag listing for the current window is already present, no " If the tag listing for the current window is already present, no
" need to refresh it " need to refresh it
if !g:Tlist_Auto_Highlight_Tag
return return
endif endif
if s:tlist_cur_fidx == fidx
" Highlight the current tag
call s:Tlist_Highlight_Tag(filename, curline, 1)
return
endif
endif
" Save the current window number " Save the current window number
let cur_winnr = winnr() let cur_winnr = winnr()
" Goto the taglist window " Goto the taglist window
call s:Tlist_Open_Window() call s:Tlist_Open_Window()
if !g:Tlist_Auto_Highlight_Tag
" Save the cursor position
let save_line = line('.')
let save_col = col('.')
endif
" Update the taglist window " Update the taglist window
call s:Tlist_Explore_File(filename, ftype) call s:Tlist_Explore_File(filename, ftype)
" Highlight the current tag " Highlight the current tag
call s:Tlist_Highlight_Tag(filename, curline) call s:Tlist_Highlight_Tag(filename, curline, 1)
if !g:Tlist_Auto_Highlight_Tag
" Restore the cursor position
call cursor(save_line, save_col)
endif
" Refresh the taglist window " Refresh the taglist window
redraw redraw
@ -1755,6 +1826,7 @@ endfunction
" Open the specified file in either a new window or an existing window " Open the specified file in either a new window or an existing window
" and place the cursor at the specified tag pattern " and place the cursor at the specified tag pattern
function! s:Tlist_Open_File(win_ctrl, filename, tagpat) function! s:Tlist_Open_File(win_ctrl, filename, tagpat)
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1 let s:Tlist_Skip_Refresh = 1
if s:tlist_part_of_winmanager if s:tlist_part_of_winmanager
@ -1844,7 +1916,7 @@ function! s:Tlist_Open_File(win_ctrl, filename, tagpat)
exe winnum . 'wincmd w' exe winnum . 'wincmd w'
endif endif
let s:Tlist_Skip_Refresh = 0 let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endfunction endfunction
" Tlist_Show_Tag_Prototype() " Tlist_Show_Tag_Prototype()
@ -1979,7 +2051,16 @@ endfunction
" Tlist_Highlight_Tag() " Tlist_Highlight_Tag()
" Highlight the current tag " Highlight the current tag
function! s:Tlist_Highlight_Tag(filename, curline) " cntx == 1, Called by the taglist plugin itself
" cntx == 2, Forced by the user through the TlistSync command
function! s:Tlist_Highlight_Tag(filename, curline, cntx)
" Highlight the current tag only if the user configured the
" taglist plugin to do so or if the user explictly invoked the
" command to highlight the current tag.
if !g:Tlist_Auto_Highlight_Tag && a:cntx == 1
return
endif
if a:filename == '' if a:filename == ''
return return
endif endif
@ -2023,18 +2104,29 @@ function! s:Tlist_Highlight_Tag(filename, curline)
" Clear previously selected name " Clear previously selected name
match none match none
let bno = bufnr(g:TagList_title)
let tag_txt = s:Tlist_Find_Tag_text(fidx, a:curline) let tag_txt = s:Tlist_Find_Tag_text(fidx, a:curline)
if tag_txt == "" if tag_txt == ""
" Make sure the current tag line is visible in the taglist window. " Make sure the current tag line is visible in the taglist window.
" Calling the winline() function makes the line visible. Don't know " Calling the winline() function makes the line visible. Don't know
" of a better way to achieve this. " of a better way to achieve this.
let cur_lnum = line('.')
if cur_lnum < s:tlist_{fidx}_start || cur_lnum > s:tlist_{fidx}_end
" Move the cursor to the beginning of the file
exe s:tlist_{fidx}_start
endif
if has('folding')
normal! zv
endif
call winline() call winline()
if !in_taglist_window if !in_taglist_window
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1 let s:Tlist_Skip_Refresh = 1
exe org_winnr . 'wincmd w' exe org_winnr . 'wincmd w'
let s:Tlist_Skip_Refresh = 0 let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endif endif
if s:tlist_part_of_winmanager if s:tlist_part_of_winmanager
call WinManagerResumeAUs() call WinManagerResumeAUs()
@ -2069,9 +2161,10 @@ function! s:Tlist_Highlight_Tag(filename, curline)
" Go back to the original window " Go back to the original window
if !in_taglist_window if !in_taglist_window
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1 let s:Tlist_Skip_Refresh = 1
exe org_winnr . 'wincmd w' exe org_winnr . 'wincmd w'
let s:Tlist_Skip_Refresh = 0 let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endif endif
if s:tlist_part_of_winmanager if s:tlist_part_of_winmanager
@ -2084,7 +2177,7 @@ endfunction
" Tlist_Get_Tag_Prototype_By_Line " Tlist_Get_Tag_Prototype_By_Line
" Get the prototype for the tag on or before the specified line number in the " Get the prototype for the tag on or before the specified line number in the
" current buffer " current buffer
function! s:Tlist_Get_Tag_Prototype_By_Line(linenum) function! Tlist_Get_Tag_Prototype_By_Line(linenum)
" Make sure the current file has a name " Make sure the current file has a name
let filename = fnamemodify(bufname("%"), ':p') let filename = fnamemodify(bufname("%"), ':p')
if filename == '' if filename == ''
@ -2117,6 +2210,45 @@ function! s:Tlist_Get_Tag_Prototype_By_Line(linenum)
return s:Tlist_Extract_Tag_Prototype(tag_txt) return s:Tlist_Extract_Tag_Prototype(tag_txt)
endfunction endfunction
" Tlist_Get_Tagname_By_Line
" Get the tag name on or before the specified line number in the
" current buffer
function! Tlist_Get_Tagname_By_Line(linenum)
" Make sure the current file has a name
let filename = fnamemodify(bufname("%"), ':p')
if filename == ''
return ""
endif
let fidx = s:Tlist_Get_File_Index(filename)
if fidx == -1
return
endif
" If there are no tags for this file, then no need to proceed further
if s:tlist_{fidx}_tag_count == 0
return
endif
let linenr = a:linenum
if linenr == ""
" Default is the current line
let linenr = line('.')
endif
" Get the tag name using the line number
let tag_txt = s:Tlist_Find_Tag_text(fidx, linenr)
if tag_txt == ""
return ""
endif
" Remove the line number at the beginning
let start = stridx(tag_txt, ':') + 1
" Extract the tag name and return it
return strpart(tag_txt, start, stridx(tag_txt, "\t") - start)
endfunction
" Tlist_Session_Load " Tlist_Session_Load
" Load a taglist session (information about all the displayed files " Load a taglist session (information about all the displayed files
" and the tags) from the specified file " and the tags) from the specified file
@ -2145,12 +2277,12 @@ function! s:Tlist_Session_Load(...)
exe 'source ' . sessionfile exe 'source ' . sessionfile
let new_file_count = g:tlist_file_count let new_file_count = g:tlist_file_count
unlet g:tlist_file_count unlet! g:tlist_file_count
let i = 0 let i = 0
while i < new_file_count while i < new_file_count
let ftype = g:tlist_{i}_filetype let ftype = g:tlist_{i}_filetype
unlet g:tlist_{i}_filetype unlet! g:tlist_{i}_filetype
if !exists("s:tlist_" . ftype . "_count") if !exists("s:tlist_" . ftype . "_count")
if s:Tlist_FileType_Init(ftype) == 0 if s:Tlist_FileType_Init(ftype) == 0
@ -2160,7 +2292,7 @@ function! s:Tlist_Session_Load(...)
endif endif
let fname = g:tlist_{i}_filename let fname = g:tlist_{i}_filename
unlet g:tlist_{i}_filename unlet! g:tlist_{i}_filename
let fidx = s:Tlist_Get_File_Index(fname) let fidx = s:Tlist_Get_File_Index(fname)
if fidx != -1 if fidx != -1
@ -2174,7 +2306,7 @@ function! s:Tlist_Session_Load(...)
let s:tlist_{fidx}_filename = fname let s:tlist_{fidx}_filename = fname
let s:tlist_{fidx}_sort_type = g:tlist_{i}_sort_type let s:tlist_{fidx}_sort_type = g:tlist_{i}_sort_type
unlet g:tlist_{i}_sort_type unlet! g:tlist_{i}_sort_type
let s:tlist_{fidx}_filetype = ftype let s:tlist_{fidx}_filetype = ftype
@ -2187,12 +2319,12 @@ function! s:Tlist_Session_Load(...)
let s:tlist_{fidx}_visible = 0 let s:tlist_{fidx}_visible = 0
let s:tlist_{fidx}_tag_count = g:tlist_{i}_tag_count let s:tlist_{fidx}_tag_count = g:tlist_{i}_tag_count
unlet g:tlist_{i}_tag_count unlet! g:tlist_{i}_tag_count
let j = 1 let j = 1
while j <= s:tlist_{fidx}_tag_count while j <= s:tlist_{fidx}_tag_count
let s:tlist_{fidx}_tag_{j} = g:tlist_{i}_tag_{j} let s:tlist_{fidx}_tag_{j} = g:tlist_{i}_tag_{j}
unlet g:tlist_{i}_tag_{j} unlet! g:tlist_{i}_tag_{j}
let j = j + 1 let j = j + 1
endwhile endwhile
@ -2202,15 +2334,15 @@ function! s:Tlist_Session_Load(...)
if exists('g:tlist_' . i . '_' . ttype) if exists('g:tlist_' . i . '_' . ttype)
let s:tlist_{fidx}_{ttype} = g:tlist_{i}_{ttype} let s:tlist_{fidx}_{ttype} = g:tlist_{i}_{ttype}
unlet g:tlist_{i}_{ttype} unlet! g:tlist_{i}_{ttype}
let s:tlist_{fidx}_{ttype}_start = 0 let s:tlist_{fidx}_{ttype}_start = 0
let s:tlist_{fidx}_{ttype}_count = g:tlist_{i}_{ttype}_count let s:tlist_{fidx}_{ttype}_count = g:tlist_{i}_{ttype}_count
unlet g:tlist_{i}_{ttype}_count unlet! g:tlist_{i}_{ttype}_count
let k = 1 let k = 1
while k <= s:tlist_{fidx}_{ttype}_count while k <= s:tlist_{fidx}_{ttype}_count
let s:tlist_{fidx}_{ttype}_{k} = g:tlist_{i}_{ttype}_{k} let s:tlist_{fidx}_{ttype}_{k} = g:tlist_{i}_{ttype}_{k}
unlet g:tlist_{i}_{ttype}_{k} unlet! g:tlist_{i}_{ttype}_{k}
let k = k + 1 let k = k + 1
endwhile endwhile
else else
@ -2264,25 +2396,25 @@ function! s:Tlist_Session_Save(...)
silent! echo '" Taglist session file. This file is auto-generated.' silent! echo '" Taglist session file. This file is auto-generated.'
silent! echo '" File information' silent! echo '" File information'
silent! echo 'let g:tlist_file_count = ' . s:tlist_file_count silent! echo 'let tlist_file_count = ' . s:tlist_file_count
let i = 0 let i = 0
while i < s:tlist_file_count while i < s:tlist_file_count
" Store information about the file " Store information about the file
silent! echo 'let g:tlist_' . i . "_filename = '" . silent! echo 'let tlist_' . i . "_filename = '" .
\ s:tlist_{i}_filename . "'" \ s:tlist_{i}_filename . "'"
silent! echo 'let g:tlist_' . i . '_sort_type = "' . silent! echo 'let tlist_' . i . '_sort_type = "' .
\ s:tlist_{i}_sort_type . '"' \ s:tlist_{i}_sort_type . '"'
silent! echo 'let g:tlist_' . i . '_filetype = "' . silent! echo 'let tlist_' . i . '_filetype = "' .
\ s:tlist_{i}_filetype . '"' \ s:tlist_{i}_filetype . '"'
silent! echo 'let g:tlist_' . i . '_tag_count = ' . silent! echo 'let tlist_' . i . '_tag_count = ' .
\ s:tlist_{i}_tag_count \ s:tlist_{i}_tag_count
" Store information about all the tags " Store information about all the tags
let j = 1 let j = 1
while j <= s:tlist_{i}_tag_count while j <= s:tlist_{i}_tag_count
let txt = escape(s:tlist_{i}_tag_{j}, '"\\') let txt = escape(s:tlist_{i}_tag_{j}, '"\\')
silent! echo 'let g:tlist_' . i . '_tag_' . j . ' = "' . txt . '"' silent! echo 'let tlist_' . i . '_tag_' . j . ' = "' . txt . '"'
let j = j + 1 let j = j + 1
endwhile endwhile
@ -2293,13 +2425,13 @@ function! s:Tlist_Session_Save(...)
let ttype = s:tlist_{ftype}_{j}_name let ttype = s:tlist_{ftype}_{j}_name
if s:tlist_{i}_{ttype}_count != 0 if s:tlist_{i}_{ttype}_count != 0
let txt = substitute(s:tlist_{i}_{ttype}, "\n", "\\\\n", "g") let txt = substitute(s:tlist_{i}_{ttype}, "\n", "\\\\n", "g")
silent! echo 'let g:tlist_' . i . '_' . ttype . ' = "' . silent! echo 'let tlist_' . i . '_' . ttype . ' = "' .
\ txt . '"' \ txt . '"'
silent! echo 'let g:tlist_' . i . '_' . ttype . '_count = ' . silent! echo 'let tlist_' . i . '_' . ttype . '_count = ' .
\ s:tlist_{i}_{ttype}_count \ s:tlist_{i}_{ttype}_count
let k = 1 let k = 1
while k <= s:tlist_{i}_{ttype}_count while k <= s:tlist_{i}_{ttype}_count
silent! echo 'let g:tlist_' . i . '_' . ttype . '_' . k . silent! echo 'let tlist_' . i . '_' . ttype . '_' . k .
\ ' = ' . s:tlist_{i}_{ttype}_{k} \ ' = ' . s:tlist_{i}_{ttype}_{k}
let k = k + 1 let k = k + 1
endwhile endwhile
@ -2315,6 +2447,70 @@ function! s:Tlist_Session_Save(...)
redir END redir END
endfunction endfunction
" Tlist_Update_File_Display
" Update a file displayed in the taglist window.
" action == 1, Close the fold for the file
" action == 2, Remove the file from the taglist window
function! s:Tlist_Update_File_Display(filename, action)
" Make sure a valid filename is supplied
if a:filename == ''
return
endif
" Make sure the taglist window is present
let winnum = bufwinnr(g:TagList_title)
if winnum == -1
call s:Tlist_Warning_Msg('Error: Taglist window is not open')
return
endif
" Save the original window number
let org_winnr = winnr()
if org_winnr == winnum
let in_taglist_window = 1
else
let in_taglist_window = 0
endif
" Go to the taglist window
if !in_taglist_window
exe winnum . 'wincmd w'
endif
" Get tag list index of the specified file
let idx = s:Tlist_Get_File_Index(a:filename)
if idx != -1
" Save the cursor position
let save_lnum = line('.')
" Perform the requested action on the file
if a:action == 1
" Close the fold for the file
if g:Tlist_File_Fold_Auto_Close
" Close the fold for the file
if has('folding')
exe "silent! " . s:tlist_{idx}_start . "," .
\ s:tlist_{idx}_end . "foldclose"
endif
endif
elseif a:action == 2
" Remove the file from the list
call s:Tlist_Remove_File(idx, 1)
endif
" Move the cursor to the original location
exe save_lnum
endif
" Go back to the original window
if !in_taglist_window
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1
exe org_winnr . 'wincmd w'
let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endif
endfunction
" Define the taglist autocommand to automatically open the taglist window on " Define the taglist autocommand to automatically open the taglist window on
" Vim startup " Vim startup
@ -2322,13 +2518,19 @@ if g:Tlist_Auto_Open
autocmd VimEnter * nested Tlist autocmd VimEnter * nested Tlist
endif endif
" Refresh the taglist
if g:Tlist_Process_File_Always
autocmd BufEnter * call <SID>Tlist_Refresh()
endif
" Define the user commands to manage the taglist window " Define the user commands to manage the taglist window
command! -nargs=0 Tlist call s:Tlist_Toggle_Window(bufnr('%')) command! -nargs=0 Tlist call s:Tlist_Toggle_Window(bufnr('%'))
command! -nargs=0 TlistClose call s:Tlist_Close_Window() command! -nargs=0 TlistClose call s:Tlist_Close_Window()
command! -nargs=0 TlistUpdate call s:Tlist_Update_Tags() command! -nargs=0 TlistUpdate call s:Tlist_Update_Tags()
command! -nargs=0 TlistSync call s:Tlist_Highlight_Tag( command! -nargs=0 TlistSync call s:Tlist_Highlight_Tag(
\ fnamemodify(bufname('%'), ':p'), line('.')) \ fnamemodify(bufname('%'), ':p'), line('.'), 2)
command! -nargs=? TlistShowPrototype echo s:Tlist_Get_Tag_Prototype_By_Line(<q-args>) command! -nargs=? TlistShowPrototype echo Tlist_Get_Tag_Prototype_By_Line(<q-args>)
command! -nargs=? TlistShowTag echo Tlist_Get_Tagname_By_Line(<q-args>)
command! -nargs=* -complete=file TlistSessionLoad call s:Tlist_Session_Load(<q-args>) command! -nargs=* -complete=file TlistSessionLoad call s:Tlist_Session_Load(<q-args>)
command! -nargs=* -complete=file TlistSessionSave call s:Tlist_Session_Save(<q-args>) command! -nargs=* -complete=file TlistSessionSave call s:Tlist_Session_Save(<q-args>)