Version 4.0b4

Fixes:
1. When 'Tlist_Show_One_File' is set, after few files are opened,
   unable to select tags from the taglist window.
2. When the taglist plugin is stored in a directory with space characters
   in the name, the autoloading of taglist plugin fails.
New features:
1. Support for moving cursor to the taglist window when using the
   ":TlistToggle" command.
2. When all the tags in a file are of the same type, in the taglist
   menu, don't display the tag type.
3. Changed the '?' help key to 'F1' in the taglist window.
4. Set the filetype for the taglist buffer to 'taglist'
5. In Vim7, set the 'winfixwidth' option for the taglist window.
6. When jumping between files using the ]] or <Tab> and [[ or <Backspace>
   keys, wrap around at the first and last file.
This commit is contained in:
Yegappan Lakshmanan 2006-04-12 00:00:00 +00:00 committed by Able Scraper
parent 4d4da98fae
commit fb0331463a
2 changed files with 309 additions and 224 deletions

View File

@ -2,14 +2,14 @@
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: 2005 December 28 Last change: 2006 April 12
1. Overview |taglist-intro| 1. Overview |taglist-intro|
2. Taglist on the internet |taglist-internet| 2. Taglist on the internet |taglist-internet|
3. Requirements |taglist-requirements| 3. Requirements |taglist-requirements|
4. Installation |taglist-install| 4. Installation |taglist-install|
5. Usage |taglist-using| 5. Usage |taglist-using|
6. Configuration |taglist-configure| 6. Options |taglist-options|
7. Commands |taglist-commands| 7. Commands |taglist-commands|
8. Global functions |taglist-functions| 8. Global functions |taglist-functions|
9. Extending |taglist-extend| 9. Extending |taglist-extend|
@ -143,7 +143,9 @@ Opening the taglist window~
You can open the taglist window using the ":TlistOpen" or the ":TlistToggle" You can open the taglist window using the ":TlistOpen" or the ":TlistToggle"
commands. The ":TlistOpen" command opens the taglist window and jumps to it. commands. The ":TlistOpen" command opens the taglist window and jumps to it.
The ":TlistToggle" command opens or closes (toggle) the taglist window and the The ":TlistToggle" command opens or closes (toggle) the taglist window and the
cursor remains in the current window. cursor remains in the current window. If the 'Tlist_GainFocus_On_ToggleOpen'
variable is set to 1, then the ":TlistToggle" command opens the taglist window
and moves the cursor to the taglist window.
You can map a key to invoke these commands. For example, the following command You can map a key to invoke these commands. For example, the following command
creates a normal mode mapping for the <F8> key to toggle the taglist window. creates a normal mode mapping for the <F8> key to toggle the taglist window.
@ -181,7 +183,8 @@ name using the mouse.
In the taglist window, you can use the [[ or <Backspace> key to jump to the In the taglist window, you can use the [[ or <Backspace> key to jump to the
beginning of the previous file. You can use the ]] or <Tab> key to jump to the beginning of the previous file. You can use the ]] or <Tab> key to jump to the
beginning of the next file. beginning of the next file. When you reach the first or last file, the search
wraps around and the jumps to the next/previous file.
Highlighting the current tag~ Highlighting the current tag~
The taglist plugin automatically highlights the name of the current tag in the The taglist plugin automatically highlights the name of the current tag in the
@ -236,6 +239,11 @@ from which to recursively add the files. The second optional argument
specifies the wildcard matching pattern for selecting the files to add. The specifies the wildcard matching pattern for selecting the files to add. The
default pattern is * and all the files are added. default pattern is * and all the files are added.
Displaying tags for only one file~
The taglist window displays the tags for all the files in the Vim buffer list
and all the manually added files. To display the tags for only the current
active buffer, set the 'Tlist_Show_One_File' variable to 1.
Removing files from the taglist~ Removing files from the taglist~
You can remove a file from the taglist window, by pressing the 'd' key when the You can remove a file from the taglist window, by pressing the 'd' key when the
cursor is on one of the tags listed for the file in the taglist window. The cursor is on one of the tags listed for the file in the taglist window. The
@ -312,22 +320,19 @@ prototype of the current tag. For example,
:TlistShowPrototype myfile.c 50 :TlistShowPrototype myfile.c 50
< <
Taglist window contents~ Taglist window contents~
The taglist window displays the tags for all the files in the Vim buffer list
and all the manually added files. To display the tags for only the current
active buffer, set the 'Tlist_Show_One_File' variable to 1.
The tag names are grouped by their type (variable, function, class, etc.). For The tag names are grouped by their type (variable, function, class, etc.). For
tags with scope information (like class members, structures inside structures, tags with scope information (like class members, structures inside structures,
etc.), the scope information is displayed in square brackets "[]" after the tag etc.), the scope information is displayed in square brackets "[]" after the tag
name. name.
The contents of the taglist buffer/window are managed by the taglist plugin. The contents of the taglist buffer/window are managed by the taglist plugin.
The Vim |'modifiable'| option is turned off for the taglist buffer. You should The |'filetype'| for the taglist buffer is set to 'taglist'. The Vim
not manually edit the taglist buffer, by setting the |'modifiable'| flag. If |'modifiable'| option is turned off for the taglist buffer. You should not
you manually edit the taglist buffer contents, then the taglist plugin will be manually edit the taglist buffer, by setting the |'modifiable'| flag. If you
out of sync with the taglist buffer contents and the plugin will no longer manually edit the taglist buffer contents, then the taglist plugin will be out
work correctly. To redisplay the taglist buffer contents again, close the of sync with the taglist buffer contents and the plugin will no longer work
taglist window and reopen it. correctly. To redisplay the taglist buffer contents again, close the taglist
window and reopen it.
Opening and closing the tag and file tree~ Opening and closing the tag and file tree~
In the taglist window, the tag names are displayed as a foldable tree using In the taglist window, the tag names are displayed as a foldable tree using
@ -483,7 +488,7 @@ in the taglist window.
]] Jump to the beginning of the next file ]] Jump to the beginning of the next file
<Tab> Jump to the beginning of the next file <Tab> Jump to the beginning of the next file
q Close the taglist window q Close the taglist window
? Display help <F1> Display help
The above keys will work in both the normal mode and the insert mode. The above keys will work in both the normal mode and the insert mode.
@ -537,8 +542,8 @@ If you have installed the taglist help file (this file), then you can use the
Vim ":help taglist-<keyword>" command to get help on the various taglist Vim ":help taglist-<keyword>" command to get help on the various taglist
topics. topics.
You can press the "?" key in the taglist window to display the help You can press the <F1> key in the taglist window to display the help
information about using the taglist window. If you again press the '?' key, information about using the taglist window. If you again press the <F1> key,
the help information is removed from the taglist window. the help information is removed from the taglist window.
*taglist-debug* *taglist-debug*
@ -554,8 +559,8 @@ variable. In the later case, to minimize memory usage, only the last 3000
characters from the debug messages are stored. characters from the debug messages are stored.
============================================================================== ==============================================================================
*taglist-configure* *taglist-options*
6. Configuration~ 6. Options~
A number of Vim variables control the behavior of the taglist plugin. These A number of Vim variables control the behavior of the taglist plugin. These
variables are initialized to a default value. By changing these variables you variables are initialized to a default value. By changing these variables you
@ -584,6 +589,8 @@ description of these variables refer to the text below this table.
window. window.
|'Tlist_Exit_OnlyWindow'| Close Vim if the taglist is the only window. |'Tlist_Exit_OnlyWindow'| Close Vim if the taglist is the only window.
|'Tlist_File_Fold_Auto_Close'| Close tag folds for inactive buffers. |'Tlist_File_Fold_Auto_Close'| Close tag folds for inactive buffers.
|'Tlist_GainFocus_On_ToggleOpen'|
Jump to taglist window on open.
|'Tlist_Highlight_Tag_On_BufEnter'| |'Tlist_Highlight_Tag_On_BufEnter'|
On entering a buffer, automatically highlight On entering a buffer, automatically highlight
the current tag. the current tag.
@ -725,6 +732,16 @@ in the taglist window will be collapsed/folded. When a buffer is loaded in a
Vim window, the corresponding tags tree will be opened. Vim window, the corresponding tags tree will be opened.
> >
let Tlist_File_Fold_Auto_Close = 1 let Tlist_File_Fold_Auto_Close = 1
<
*'Tlist_GainFocus_On_ToggleOpen'*
Tlist_GainFocus_On_ToggleOpen~
When the taglist window is opened using the ':TlistToggle' command, this
option controls whether the cursor is moved to the taglist window or remains
in the current window. By default, this option is set to 0 and the cursor
remains in the current window. When this variable is set to 1, the cursor
moves to the taglist window after opening the taglist window.
>
let Tlist_GainFocus_On_ToggleOpen = 1
< <
*'Tlist_Highlight_Tag_On_BufEnter'* *'Tlist_Highlight_Tag_On_BufEnter'*
Tlist_Highlight_Tag_On_BufEnter~ Tlist_Highlight_Tag_On_BufEnter~

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: 4.0 Beta 3 " Version: 4.0 Beta 4
" Last Modified: Dec 28, 2005 " Last Modified: April 12, 2006
" "
" The "Tag List" plugin is a source code browser plugin for Vim and provides " The "Tag List" plugin is a source code browser plugin for Vim and provides
" an overview of the structure of the programming language files and allows " an overview of the structure of the programming language files and allows
@ -96,6 +96,12 @@ if !exists('loaded_taglist')
let Tlist_Auto_Open = 0 let Tlist_Auto_Open = 0
endif endif
" When the taglist window is toggle opened, move the cursor to the
" taglist window
if !exists('Tlist_GainFocus_On_ToggleOpen')
let Tlist_GainFocus_On_ToggleOpen = 0
endif
" Process files even when the taglist window is not open " Process files even when the taglist window is not open
if !exists('Tlist_Process_File_Always') if !exists('Tlist_Process_File_Always')
let Tlist_Process_File_Always = 0 let Tlist_Process_File_Always = 0
@ -228,7 +234,7 @@ if !exists('loaded_taglist')
" Define the taglist autocommand to automatically open the taglist window " Define the taglist autocommand to automatically open the taglist window
" on Vim startup " on Vim startup
if g:Tlist_Auto_Open if g:Tlist_Auto_Open
autocmd VimEnter * nested call s:Tlist_Check_Auto_Open() autocmd VimEnter * nested call s:Tlist_Window_Check_Auto_Open()
endif endif
" Refresh the taglist " Refresh the taglist
@ -256,7 +262,7 @@ if !exists('loaded_taglist')
\ call s:Tlist_Add_Files_Recursive(<f-args>) \ call s:Tlist_Add_Files_Recursive(<f-args>)
command! -nargs=0 TlistClose call s:Tlist_Window_Close() command! -nargs=0 TlistClose call s:Tlist_Window_Close()
command! -nargs=0 TlistUpdate call s:Tlist_Update_Current_File() command! -nargs=0 TlistUpdate call s:Tlist_Update_Current_File()
command! -nargs=0 TlistHighlightTag call s:Tlist_Highlight_Tag( command! -nargs=0 TlistHighlightTag call s:Tlist_Window_Highlight_Tag(
\ fnamemodify(bufname('%'), ':p'), line('.'), 2, 1) \ fnamemodify(bufname('%'), ':p'), line('.'), 2, 1)
" For backwards compatiblity define the TlistSync command " For backwards compatiblity define the TlistSync command
command! -nargs=0 TlistSync TlistHighlightTag command! -nargs=0 TlistSync TlistHighlightTag
@ -285,9 +291,15 @@ if !exists('loaded_taglist')
unmap <SID>xx unmap <SID>xx
exe 'autocmd FuncUndefined *' . s:sid . 'Tlist_* source ' . exe 'autocmd FuncUndefined *' . s:sid . 'Tlist_* source ' .
\ expand('<sfile>') \ escape(expand('<sfile>'), ' ')
exe 'autocmd FuncUndefined Tlist_* source ' . expand('<sfile>') exe 'autocmd FuncUndefined *' . s:sid . 'Tlist_Window_* source ' .
exe 'autocmd FuncUndefined TagList_* source ' . expand('<sfile>') \ escape(expand('<sfile>'), ' ')
exe 'autocmd FuncUndefined *' . s:sid . 'Tlist_Menu_* source ' .
\ escape(expand('<sfile>'), ' ')
exe 'autocmd FuncUndefined Tlist_* source ' .
\ escape(expand('<sfile>'), ' ')
exe 'autocmd FuncUndefined TagList_* source ' .
\ escape(expand('<sfile>'), ' ')
unlet! s:sid unlet! s:sid
@ -483,8 +495,8 @@ let s:tlist_menu_empty = 1
" and cleared appropriately. " and cleared appropriately.
let s:Tlist_Skip_Refresh = 0 let s:Tlist_Skip_Refresh = 0
" Tlist_Display_Help() " Tlist_Window_Display_Help()
function! s:Tlist_Display_Help() function! s:Tlist_Window_Display_Help()
if s:tlist_app_name == "winmanager" if s:tlist_app_name == "winmanager"
" To handle a bug in the winmanager plugin, add a space at the " To handle a bug in the winmanager plugin, add a space at the
" last line " last line
@ -493,7 +505,7 @@ function! s:Tlist_Display_Help()
if s:tlist_brief_help if s:tlist_brief_help
" Add the brief help " Add the brief help
call append(0, '" Press ? to display help text') call append(0, '" Press <F1> to display help text')
else else
" Add the extensive help " Add the extensive help
call append(0, '" <enter> : Jump to tag definition') call append(0, '" <enter> : Jump to tag definition')
@ -511,14 +523,14 @@ function! s:Tlist_Display_Help()
call append(12, '" [[ : Move to the start of previous file') call append(12, '" [[ : Move to the start of previous file')
call append(13, '" ]] : Move to the start of next file') call append(13, '" ]] : Move to the start of next file')
call append(14, '" q : Close the taglist window') call append(14, '" q : Close the taglist window')
call append(15, '" ? : Remove help text') call append(15, '" <F1> : Remove help text')
endif endif
endfunction endfunction
" Tlist_Toggle_Help_Text() " Tlist_Window_Toggle_Help_Text()
" Toggle taglist plugin help text between the full version and the brief " Toggle taglist plugin help text between the full version and the brief
" version " version
function! s:Tlist_Toggle_Help_Text() function! s:Tlist_Window_Toggle_Help_Text()
if g:Tlist_Compact_Format if g:Tlist_Compact_Format
" In compact display mode, do not display help " In compact display mode, do not display help
return return
@ -547,7 +559,7 @@ function! s:Tlist_Toggle_Help_Text()
exe '1,' . brief_help_size . ' delete _' exe '1,' . brief_help_size . ' delete _'
" Adjust the start/end line numbers for the files " Adjust the start/end line numbers for the files
call s:Tlist_Update_Line_Offsets(0, 1, full_help_size - brief_help_size) call s:Tlist_Window_Update_Line_Offsets(0, 1, full_help_size - brief_help_size)
else else
let s:tlist_brief_help = 1 let s:tlist_brief_help = 1
@ -555,10 +567,10 @@ function! s:Tlist_Toggle_Help_Text()
exe '1,' . full_help_size . ' delete _' exe '1,' . full_help_size . ' delete _'
" Adjust the start/end line numbers for the files " Adjust the start/end line numbers for the files
call s:Tlist_Update_Line_Offsets(0, 0, full_help_size - brief_help_size) call s:Tlist_Window_Update_Line_Offsets(0, 0, full_help_size - brief_help_size)
endif endif
call s:Tlist_Display_Help() call s:Tlist_Window_Display_Help()
" Restore the report option " Restore the report option
let &report = old_report let &report = old_report
@ -669,11 +681,11 @@ endfunction
" Used to speed up file lookup " Used to speed up file lookup
let s:tlist_file_lnum_idx_cache = -1 let s:tlist_file_lnum_idx_cache = -1
" Tlist_Get_File_Index_By_Linenum() " Tlist_Window_Get_File_Index_By_Linenum()
" Return the index of the filename present in the specified line number " Return the index of the filename present in the specified line number
" Line number refers to the line number in the taglist window " Line number refers to the line number in the taglist window
function! s:Tlist_Get_File_Index_By_Linenum(lnum) function! s:Tlist_Window_Get_File_Index_By_Linenum(lnum)
call s:Tlist_Log_Msg('Tlist_Get_File_Index_By_Linenum (' . a:lnum . ')') call s:Tlist_Log_Msg('Tlist_Window_Get_File_Index_By_Linenum (' . a:lnum . ')')
" First try to see whether the new line number is within the range " First try to see whether the new line number is within the range
" of the last returned file " of the last returned file
@ -685,30 +697,43 @@ function! s:Tlist_Get_File_Index_By_Linenum(lnum)
endif endif
endif endif
" Do a binary search in the taglist let fidx = -1
let left = 0
let right = s:tlist_file_count - 1
while left < right if g:Tlist_Show_One_File
let mid = (left + right) / 2 " Displaying only one file in the taglist window. Check whether
" the line is within the tags displayed for that file
if s:tlist_cur_file_idx != -1
if a:lnum >= s:tlist_{s:tlist_cur_file_idx}_start
\ && a:lnum <= s:tlist_{s:tlist_cur_file_idx}_end
let fidx = s:tlist_cur_file_idx
endif
if a:lnum >= s:tlist_{mid}_start && a:lnum <= s:tlist_{mid}_end
let s:tlist_file_lnum_idx_cache = mid
return mid
endif endif
if a:lnum < s:tlist_{mid}_start
let right = mid - 1
else
let left = mid + 1
endif
endwhile
if left < 0 || left >= s:tlist_file_count ||
\ a:lnum < s:tlist_{left}_start || a:lnum > s:tlist_{left}_end
let fidx = -1
else else
let fidx = left " Do a binary search in the taglist
let left = 0
let right = s:tlist_file_count - 1
while left < right
let mid = (left + right) / 2
if a:lnum >= s:tlist_{mid}_start && a:lnum <= s:tlist_{mid}_end
let s:tlist_file_lnum_idx_cache = mid
return mid
endif
if a:lnum < s:tlist_{mid}_start
let right = mid - 1
else
let left = mid + 1
endif
endwhile
if left >= 0 && left < s:tlist_file_count
\ && a:lnum >= s:tlist_{left}_start
\ && a:lnum <= s:tlist_{left}_end
let fidx = left
endif
endif endif
let s:tlist_file_lnum_idx_cache = fidx let s:tlist_file_lnum_idx_cache = fidx
@ -982,10 +1007,10 @@ function! s:Tlist_Discard_TagInfo(fidx)
let s:tlist_{a:fidx}_menu_cmd = '' let s:tlist_{a:fidx}_menu_cmd = ''
endfunction endfunction
" Tlist_Update_Line_Offsets " Tlist_Window_Update_Line_Offsets
" Update the line offsets for tags for files starting from start_idx " Update the line offsets for tags for files starting from start_idx
" and displayed in the taglist window by the specified offset " and displayed in the taglist window by the specified offset
function! s:Tlist_Update_Line_Offsets(start_idx, increment, offset) function! s:Tlist_Window_Update_Line_Offsets(start_idx, increment, offset)
let i = a:start_idx let i = a:start_idx
while i < s:tlist_file_count while i < s:tlist_file_count
@ -1033,10 +1058,10 @@ function! s:Tlist_Discard_FileInfo(fidx)
unlet! s:tlist_{a:fidx}_menu_cmd unlet! s:tlist_{a:fidx}_menu_cmd
endfunction endfunction
" Tlist_Remove_File_From_Display " Tlist_Window_Remove_File_From_Display
" Remove the specified file from display " Remove the specified file from display
function! s:Tlist_Remove_File_From_Display(fidx) function! s:Tlist_Window_Remove_File_From_Display(fidx)
call s:Tlist_Log_Msg('Tlist_Remove_File_From_Display (' . call s:Tlist_Log_Msg('Tlist_Window_Remove_File_From_Display (' .
\ s:tlist_{a:fidx}_filename . ')') \ s:tlist_{a:fidx}_filename . ')')
" If the file is not visible then no need to remove it " If the file is not visible then no need to remove it
if !s:tlist_{a:fidx}_visible if !s:tlist_{a:fidx}_visible
@ -1058,7 +1083,7 @@ function! s:Tlist_Remove_File_From_Display(fidx)
" Correct the start and end line offsets for all the files following " Correct the start and end line offsets for all the files following
" this file, as the tags for this file are removed " this file, as the tags for this file are removed
call s:Tlist_Update_Line_Offsets(a:fidx + 1, 0, end - start + 1) call s:Tlist_Window_Update_Line_Offsets(a:fidx + 1, 0, end - start + 1)
endfunction endfunction
" Tlist_Remove_File " Tlist_Remove_File
@ -1068,7 +1093,7 @@ function! s:Tlist_Remove_File(file_idx, user_request)
let fidx = a:file_idx let fidx = a:file_idx
if fidx == -1 if fidx == -1
let fidx = s:Tlist_Get_File_Index_By_Linenum(line('.')) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(line('.'))
if fidx == -1 if fidx == -1
return return
endif endif
@ -1087,7 +1112,7 @@ function! s:Tlist_Remove_File(file_idx, user_request)
exe winnum . 'wincmd w' exe winnum . 'wincmd w'
endif endif
call s:Tlist_Remove_File_From_Display(fidx) call s:Tlist_Window_Remove_File_From_Display(fidx)
if save_winnr != winnum if save_winnr != winnum
exe save_winnr . 'wincmd w' exe save_winnr . 'wincmd w'
@ -1179,9 +1204,9 @@ function! s:Tlist_Remove_File(file_idx, user_request)
endif endif
endfunction endfunction
" Tlist_Goto_Window " Tlist_Window_Goto_Window
" Goto the taglist window " Goto the taglist window
function! s:Tlist_Goto_Window() function! s:Tlist_Window_Goto_Window()
let winnum = bufwinnr(g:TagList_title) let winnum = bufwinnr(g:TagList_title)
if winnum != -1 if winnum != -1
if winnr() != winnum if winnr() != winnum
@ -1320,6 +1345,10 @@ endfunction
" Set the default options for the taglist window " Set the default options for the taglist window
function! s:Tlist_Window_Init() function! s:Tlist_Window_Init()
call s:Tlist_Log_Msg('Tlist_Window_Init()') call s:Tlist_Log_Msg('Tlist_Window_Init()')
" Set the taglist buffer filetype to taglist
setlocal filetype=taglist
" Define taglist window element highlighting " Define taglist window element highlighting
syntax match TagListComment '^" .*' syntax match TagListComment '^" .*'
syntax match TagListFileName '^[^" ].*$' syntax match TagListFileName '^[^" ].*$'
@ -1353,7 +1382,7 @@ function! s:Tlist_Window_Init()
highlight link TagListFileName MyTagListFileName highlight link TagListFileName MyTagListFileName
else else
highlight clear TagListFileName highlight clear TagListFileName
highlight default TagListFileName guibg=darkgray ctermbg=darkgray highlight default TagListFileName guibg=Grey ctermbg=darkgray
\ guifg=white ctermfg=white \ guifg=white ctermfg=white
endif endif
if hlexists('MyTagListTagScope') if hlexists('MyTagListTagScope')
@ -1406,16 +1435,19 @@ function! s:Tlist_Window_Init()
set winfixheight set winfixheight
endif endif
endif endif
if !g:Tlist_Use_Horiz_Window && v:version >= 700
set winfixwidth
endif
" Setup the cpoptions properly for the maps to work " Setup the cpoptions properly for the maps to work
let old_cpoptions = &cpoptions let old_cpoptions = &cpoptions
set cpoptions&vim set cpoptions&vim
" Create buffer local mappings for jumping to the tags and sorting the list " Create buffer local mappings for jumping to the tags and sorting the list
nnoremap <buffer> <silent> <CR> :call <SID>Tlist_Jump_To_Tag(0)<CR> nnoremap <buffer> <silent> <CR> :call <SID>Tlist_Window_Jump_To_Tag(0)<CR>
nnoremap <buffer> <silent> o :call <SID>Tlist_Jump_To_Tag(1)<CR> nnoremap <buffer> <silent> o :call <SID>Tlist_Window_Jump_To_Tag(1)<CR>
nnoremap <buffer> <silent> p :call <SID>Tlist_Jump_To_Tag(2)<CR> nnoremap <buffer> <silent> p :call <SID>Tlist_Window_Jump_To_Tag(2)<CR>
nnoremap <buffer> <silent> <2-LeftMouse> :call <SID>Tlist_Jump_To_Tag(0)<CR> nnoremap <buffer> <silent> <2-LeftMouse> :call <SID>Tlist_Window_Jump_To_Tag(0)<CR>
nnoremap <buffer> <silent> s :call <SID>Tlist_Change_Sort(1, 1, '')<CR> nnoremap <buffer> <silent> s :call <SID>Tlist_Change_Sort(1, 1, '')<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>
@ -1424,25 +1456,25 @@ function! s:Tlist_Window_Init()
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>
nnoremap <buffer> <silent> <Space> :call <SID>Tlist_Show_Info()<CR> nnoremap <buffer> <silent> <Space> :call <SID>Tlist_Window_Show_Info()<CR>
nnoremap <buffer> <silent> u :call <SID>Tlist_Window_Update_File()<CR> nnoremap <buffer> <silent> u :call <SID>Tlist_Window_Update_File()<CR>
nnoremap <buffer> <silent> d :call <SID>Tlist_Remove_File(-1, 1)<CR> nnoremap <buffer> <silent> d :call <SID>Tlist_Remove_File(-1, 1)<CR>
nnoremap <buffer> <silent> x :call <SID>Tlist_Window_Zoom()<CR> nnoremap <buffer> <silent> x :call <SID>Tlist_Window_Zoom()<CR>
nnoremap <buffer> <silent> [[ :call <SID>Tlist_Move_To_File(-1)<CR> nnoremap <buffer> <silent> [[ :call <SID>Tlist_Window_Move_To_File(-1)<CR>
nnoremap <buffer> <silent> <BS> :call <SID>Tlist_Move_To_File(-1)<CR> nnoremap <buffer> <silent> <BS> :call <SID>Tlist_Window_Move_To_File(-1)<CR>
nnoremap <buffer> <silent> ]] :call <SID>Tlist_Move_To_File(1)<CR> nnoremap <buffer> <silent> ]] :call <SID>Tlist_Window_Move_To_File(1)<CR>
nnoremap <buffer> <silent> <Tab> :call <SID>Tlist_Move_To_File(1)<CR> nnoremap <buffer> <silent> <Tab> :call <SID>Tlist_Window_Move_To_File(1)<CR>
nnoremap <buffer> <silent> ? :call <SID>Tlist_Toggle_Help_Text()<CR> nnoremap <buffer> <silent> <F1> :call <SID>Tlist_Window_Toggle_Help_Text()<CR>
nnoremap <buffer> <silent> q :close<CR> nnoremap <buffer> <silent> q :close<CR>
" Insert mode mappings " Insert mode mappings
inoremap <buffer> <silent> <CR> <C-o>:call <SID>Tlist_Jump_To_Tag(0)<CR> inoremap <buffer> <silent> <CR> <C-o>:call <SID>Tlist_Window_Jump_To_Tag(0)<CR>
" Windows needs return " Windows needs return
inoremap <buffer> <silent> <Return> <C-o>:call <SID>Tlist_Jump_To_Tag(0)<CR> inoremap <buffer> <silent> <Return> <C-o>:call <SID>Tlist_Window_Jump_To_Tag(0)<CR>
inoremap <buffer> <silent> o <C-o>:call <SID>Tlist_Jump_To_Tag(1)<CR> inoremap <buffer> <silent> o <C-o>:call <SID>Tlist_Window_Jump_To_Tag(1)<CR>
inoremap <buffer> <silent> p <C-o>:call <SID>Tlist_Jump_To_Tag(2)<CR> inoremap <buffer> <silent> p <C-o>:call <SID>Tlist_Window_Jump_To_Tag(2)<CR>
inoremap <buffer> <silent> <2-LeftMouse> <C-o>:call inoremap <buffer> <silent> <2-LeftMouse> <C-o>:call
\ <SID>Tlist_Jump_To_Tag(0)<CR> \ <SID>Tlist_Window_Jump_To_Tag(0)<CR>
inoremap <buffer> <silent> s inoremap <buffer> <silent> s
\ <C-o>:call <SID>Tlist_Change_Sort(1, 1, '')<CR> \ <C-o>:call <SID>Tlist_Change_Sort(1, 1, '')<CR>
inoremap <buffer> <silent> + <C-o>:silent! foldopen<CR> inoremap <buffer> <silent> + <C-o>:silent! foldopen<CR>
@ -1453,16 +1485,16 @@ function! s:Tlist_Window_Init()
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>
inoremap <buffer> <silent> <Space> <C-o>:call inoremap <buffer> <silent> <Space> <C-o>:call
\ <SID>Tlist_Show_Info()<CR> \ <SID>Tlist_Window_Show_Info()<CR>
inoremap <buffer> <silent> u inoremap <buffer> <silent> u
\ <C-o>:call <SID>Tlist_Window_Update_File()<CR> \ <C-o>:call <SID>Tlist_Window_Update_File()<CR>
inoremap <buffer> <silent> d <C-o>:call <SID>Tlist_Remove_File(-1, 1)<CR> inoremap <buffer> <silent> d <C-o>:call <SID>Tlist_Remove_File(-1, 1)<CR>
inoremap <buffer> <silent> x <C-o>:call <SID>Tlist_Window_Zoom()<CR> inoremap <buffer> <silent> x <C-o>:call <SID>Tlist_Window_Zoom()<CR>
inoremap <buffer> <silent> [[ <C-o>:call <SID>Tlist_Move_To_File(-1)<CR> inoremap <buffer> <silent> [[ <C-o>:call <SID>Tlist_Window_Move_To_File(-1)<CR>
inoremap <buffer> <silent> <BS> <C-o>:call <SID>Tlist_Move_To_File(-1)<CR> inoremap <buffer> <silent> <BS> <C-o>:call <SID>Tlist_Window_Move_To_File(-1)<CR>
inoremap <buffer> <silent> ]] <C-o>:call <SID>Tlist_Move_To_File(1)<CR> inoremap <buffer> <silent> ]] <C-o>:call <SID>Tlist_Window_Move_To_File(1)<CR>
inoremap <buffer> <silent> <Tab> <C-o>:call <SID>Tlist_Move_To_File(1)<CR> inoremap <buffer> <silent> <Tab> <C-o>:call <SID>Tlist_Window_Move_To_File(1)<CR>
inoremap <buffer> <silent> ? <C-o>:call <SID>Tlist_Toggle_Help_Text()<CR> inoremap <buffer> <silent> <F1> <C-o>:call <SID>Tlist_Window_Toggle_Help_Text()<CR>
inoremap <buffer> <silent> q <C-o>:close<CR> inoremap <buffer> <silent> q <C-o>:close<CR>
" Map single left mouse click if the user wants this functionality " Map single left mouse click if the user wants this functionality
@ -1473,7 +1505,7 @@ function! s:Tlist_Window_Init()
" not fire the <buffer> <leftmouse> when you use the mouse " not fire the <buffer> <leftmouse> when you use the mouse
" to enter a buffer. " to enter a buffer.
let clickmap = ':if bufname("%") =~ "__Tag_List__" <bar> ' . let clickmap = ':if bufname("%") =~ "__Tag_List__" <bar> ' .
\ 'call <SID>Tlist_Jump_To_Tag(0) <bar> endif <CR>' \ 'call <SID>Tlist_Window_Jump_To_Tag(0) <bar> endif <CR>'
if maparg('<leftmouse>', 'n') == '' if maparg('<leftmouse>', 'n') == ''
" no mapping for leftmouse " no mapping for leftmouse
exe ':nnoremap <silent> <leftmouse> <leftmouse>' . clickmap exe ':nnoremap <silent> <leftmouse> <leftmouse>' . clickmap
@ -1492,9 +1524,9 @@ function! s:Tlist_Window_Init()
augroup TagListAutoCmds augroup TagListAutoCmds
autocmd! autocmd!
" Display the tag prototype for the tag under the cursor. " Display the tag prototype for the tag under the cursor.
autocmd CursorHold __Tag_List__ call s:Tlist_Show_Info() autocmd CursorHold __Tag_List__ call s:Tlist_Window_Show_Info()
" Highlight the current tag periodically " Highlight the current tag periodically
autocmd CursorHold * silent call s:Tlist_Highlight_Tag( autocmd CursorHold * silent call s:Tlist_Window_Highlight_Tag(
\ fnamemodify(bufname('%'), ':p'), line('.'), 1, 0) \ fnamemodify(bufname('%'), ':p'), line('.'), 1, 0)
" Adjust the Vim window width when taglist window is closed " Adjust the Vim window width when taglist window is closed
@ -1502,7 +1534,7 @@ function! s:Tlist_Window_Init()
" Close the fold for this buffer when it's not visible in any window " Close the fold for this buffer when it's not visible in any window
if g:Tlist_File_Fold_Auto_Close if g:Tlist_File_Fold_Auto_Close
autocmd BufWinLeave * silent autocmd BufWinLeave * silent
\ call s:Tlist_Close_File_Fold(expand('<afile>:p')) \ call s:Tlist_Window_Close_File_Fold(expand('<afile>:p'))
endif endif
" Exit Vim itself if only the taglist window is present (optional) " Exit Vim itself if only the taglist window is present (optional)
if g:Tlist_Exit_OnlyWindow if g:Tlist_Exit_OnlyWindow
@ -1519,7 +1551,9 @@ function! s:Tlist_Window_Init()
endif endif
if !g:Tlist_Use_Horiz_Window if !g:Tlist_Use_Horiz_Window
autocmd WinEnter * call s:Tlist_Window_Check_Width() if v:version < 700
autocmd WinEnter * call s:Tlist_Window_Check_Width()
endif
endif endif
augroup end augroup end
@ -1552,7 +1586,7 @@ function! s:Tlist_Window_Refresh()
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_Window_Display_Help()
endif endif
" Mark the buffer as not modifiable " Mark the buffer as not modifiable
@ -1698,7 +1732,7 @@ function! s:Tlist_Window_Refresh_File(filename, ftype)
" Discard and remove the tags for this file from display " Discard and remove the tags for this file from display
call s:Tlist_Discard_TagInfo(fidx) call s:Tlist_Discard_TagInfo(fidx)
call s:Tlist_Remove_File_From_Display(fidx) call s:Tlist_Window_Remove_File_From_Display(fidx)
endif endif
" Process and generate a list of tags defined in the file " Process and generate a list of tags defined in the file
@ -1718,7 +1752,7 @@ function! s:Tlist_Window_Refresh_File(filename, ftype)
if g:Tlist_Show_One_File if g:Tlist_Show_One_File
" Remove the previous file " Remove the previous file
if s:tlist_cur_file_idx != -1 if s:tlist_cur_file_idx != -1
call s:Tlist_Remove_File_From_Display(s:tlist_cur_file_idx) call s:Tlist_Window_Remove_File_From_Display(s:tlist_cur_file_idx)
let s:tlist_{s:tlist_cur_file_idx}_visible = 0 let s:tlist_{s:tlist_cur_file_idx}_visible = 0
let s:tlist_{s:tlist_cur_file_idx}_start = 0 let s:tlist_{s:tlist_cur_file_idx}_start = 0
let s:tlist_{s:tlist_cur_file_idx}_end = 0 let s:tlist_{s:tlist_cur_file_idx}_end = 0
@ -1838,7 +1872,7 @@ function! s:Tlist_Window_Refresh_File(filename, ftype)
else else
let end = s:tlist_{fidx}_end + 1 let end = s:tlist_{fidx}_end + 1
endif endif
call s:Tlist_Update_Line_Offsets(fidx + 1, 1, end - start + 1) call s:Tlist_Window_Update_Line_Offsets(fidx + 1, 1, end - start + 1)
" Now that we have updated the taglist window, update the tags " Now that we have updated the taglist window, update the tags
" menu (if present) " menu (if present)
@ -1981,14 +2015,9 @@ function! s:Tlist_Parse_Tagline(tag_line)
" Extract the tag type " Extract the tag type
let ttype = s:Tlist_Extract_Tagtype(a:tag_line) let ttype = s:Tlist_Extract_Tagtype(a:tag_line)
if ttype == '' " Make sure the tag type is a valid and supported one
" Line is not in proper tags format if ttype == '' || stridx(s:ctags_flags, ttype) == -1
return " Line is not in proper tags format or Tag type is not supported
endif
" make sure the tag type is supported
if stridx(s:ctags_flags, ttype) == -1
" Tag type is not supported
return return
endif endif
@ -2117,7 +2146,7 @@ function! s:Tlist_Process_File(filename, ftype)
" No tags for current file " No tags for current file
if cmd_output == '' if cmd_output == ''
call s:Tlist_Warning_Msg('Taglist: No tags defined in ' . a:filename) call s:Tlist_Log_Msg('No tags defined in ' . a:filename)
return fidx return fidx
endif endif
@ -2168,14 +2197,10 @@ function! s:Tlist_Process_File(filename, ftype)
" Extract the tag type " Extract the tag type
let ttype = s:Tlist_Extract_Tagtype(one_line) let ttype = s:Tlist_Extract_Tagtype(one_line)
if ttype == '' " Make sure the tag type is a valid and supported one
" Line is not in proper tags format if ttype == '' || stridx(s:ctags_flags, ttype) == -1
continue " Line is not in proper tags format or Tag type is not
endif " supported
" make sure the tag type is supported
if stridx(ctags_flags, ttype) == -1
" Tag type is not supported
continue continue
endif endif
@ -2287,7 +2312,7 @@ function! Tlist_Update_File(filename, ftype)
let save_winnr = winnr() let save_winnr = winnr()
" Goto the taglist window " Goto the taglist window
call s:Tlist_Goto_Window() call s:Tlist_Window_Goto_Window()
" Save the cursor position " Save the cursor position
let save_line = line('.') let save_line = line('.')
@ -2402,7 +2427,7 @@ function! s:Tlist_Window_Open()
endif endif
" Highlight the current tag " Highlight the current tag
call s:Tlist_Highlight_Tag(curbuf_name, cur_lnum, 1, 1) call s:Tlist_Window_Highlight_Tag(curbuf_name, cur_lnum, 1, 1)
endfunction endfunction
" Tlist_Window_Toggle() " Tlist_Window_Toggle()
@ -2418,8 +2443,11 @@ function! s:Tlist_Window_Toggle()
call s:Tlist_Window_Open() call s:Tlist_Window_Open()
" Go back to the original window " Go back to the original window, if Tlist_GainFocus_On_ToggleOpen is not
call s:Tlist_Exe_Cmd_No_Acmds('wincmd p') " set
if !g:Tlist_GainFocus_On_ToggleOpen
call s:Tlist_Exe_Cmd_No_Acmds('wincmd p')
endif
" Update the taglist menu " Update the taglist menu
if g:Tlist_Show_Menu if g:Tlist_Show_Menu
@ -2427,33 +2455,70 @@ function! s:Tlist_Window_Toggle()
endif endif
endfunction endfunction
" Tlist_Process_Dir " Tlist_Process_Filelist
" Process the files in a directory matching the specified pattern " Process multiple files. Each filename is separated by "\n"
function! s:Tlist_Process_Dir(dir_name, pat) " Returns the number of processed files
let flist = glob(a:dir_name . '/' . a:pat) . "\n" function! s:Tlist_Process_Filelist(file_names)
let flist = a:file_names
" Enable lazy screen updates
let old_lazyredraw = &lazyredraw
set lazyredraw
" Keep track of the number of processed files
let fcnt = 0
" Process one file at a time " Process one file at a time
while flist != '' while flist != ''
let nl_idx = stridx(flist, "\n") let nl_idx = stridx(flist, "\n")
let one_file = strpart(flist, 0, nl_idx) let one_file = strpart(flist, 0, nl_idx)
" Remove the filename from the list
let flist = strpart(flist, nl_idx + 1) let flist = strpart(flist, nl_idx + 1)
if one_file == '' if one_file == ''
continue continue
endif endif
if !isdirectory(one_file) " Skip directories
let ftype = s:Tlist_Get_Filetype(one_file) if isdirectory(one_file)
continue
echon "\r "
echon "\rProcessing tags for " . fnamemodify(one_file, ':p:t')
silent call Tlist_Update_File(one_file, ftype)
endif endif
let ftype = s:Tlist_Get_Filetype(one_file)
echon "\r "
echon "\rProcessing tags for " . fnamemodify(one_file, ':p:t')
let fcnt = fcnt + 1
call Tlist_Update_File(one_file, ftype)
endwhile endwhile
let all_files = glob(a:dir_name . '/*') . "\n" " Clear the displayed informational messages
echon "\r "
" Restore the previous state
let &lazyredraw = old_lazyredraw
return fcnt
endfunction
" Tlist_Process_Dir
" Process the files in a directory matching the specified pattern
function! s:Tlist_Process_Dir(dir_name, pat)
let flist = glob(a:dir_name . '/' . a:pat) . "\n"
let fcnt = s:Tlist_Process_Filelist(flist)
let len = strlen(a:dir_name)
if a:dir_name[len - 1] == '\' || a:dir_name[len - 1] == '/'
let glob_expr = a:dir_name . '*'
else
let glob_expr = a:dir_name . '/*'
endif
let all_files = glob(glob_expr) . "\n"
while all_files != '' while all_files != ''
let nl_idx = stridx(all_files, "\n") let nl_idx = stridx(all_files, "\n")
let one_file = strpart(all_files, 0, nl_idx) let one_file = strpart(all_files, 0, nl_idx)
@ -2463,12 +2528,17 @@ function! s:Tlist_Process_Dir(dir_name, pat)
continue continue
endif endif
" Skip non-directory names
if !isdirectory(one_file) if !isdirectory(one_file)
continue continue
endif endif
call s:Tlist_Process_Dir(one_file, a:pat) echon "\r "
echon "\rProcessing files in directory " . fnamemodify(one_file, ':t')
let fcnt = fcnt + s:Tlist_Process_Dir(one_file, a:pat)
endwhile endwhile
return fcnt
endfunction endfunction
" Tlist_Add_Files_Recursive " Tlist_Add_Files_Recursive
@ -2489,12 +2559,10 @@ function! s:Tlist_Add_Files_Recursive(dir, ...)
endif endif
echon "\r " echon "\r "
echon "\rProcessing files in directory " . fnamemodify(dir_name, ':p') echon "\rProcessing files in directory " . fnamemodify(dir_name, ':t')
let fcnt = s:Tlist_Process_Dir(dir_name, pat)
call s:Tlist_Process_Dir(dir_name, pat) echon "\rAdded " . fcnt . " files to the taglist"
" Clear the displayed informational messages
echon "\r "
endfunction endfunction
" Tlist_Add_Files " Tlist_Add_Files
@ -2514,33 +2582,8 @@ function! s:Tlist_Add_Files(...)
return return
endif endif
" Enable lazy screen updates let fcnt = s:Tlist_Process_Filelist(flist)
let old_lazyredraw = &lazyredraw echon "\rAdded " . fcnt . " files to the taglist"
set lazyredraw
" Process one file at a time
while flist != ''
let one_file = strpart(flist, 0, stridx(flist, "\n"))
let flist = strpart(flist, stridx(flist, "\n") + 1)
if one_file == ''
continue
endif
let ftype = s:Tlist_Get_Filetype(one_file)
echon "\r "
echon "\rProcessing tags for " . fnamemodify(one_file, ':p:t')
silent call Tlist_Update_File(one_file, ftype)
endwhile
" Clear the displayed informational messages
echon "\r "
" Restore the previous state
let &lazyredraw = old_lazyredraw
endfunction endfunction
" Tlist_Extract_Tagtype " Tlist_Extract_Tagtype
@ -2657,7 +2700,7 @@ function! s:Tlist_Refresh()
let save_winnr = winnr() let save_winnr = winnr()
" Goto the taglist window " Goto the taglist window
call s:Tlist_Goto_Window() call s:Tlist_Window_Goto_Window()
if !g:Tlist_Auto_Highlight_Tag || !g:Tlist_Highlight_Tag_On_BufEnter if !g:Tlist_Auto_Highlight_Tag || !g:Tlist_Highlight_Tag_On_BufEnter
" Save the cursor position " Save the cursor position
@ -2683,7 +2726,7 @@ function! s:Tlist_Refresh()
endif endif
" Highlight the current tag " Highlight the current tag
call s:Tlist_Highlight_Tag(filename, cur_lnum, 1, center_tag_line) call s:Tlist_Window_Highlight_Tag(filename, cur_lnum, 1, center_tag_line)
else else
" Restore the cursor position " Restore the cursor position
if v:version >= 601 if v:version >= 601
@ -2719,7 +2762,7 @@ function! s:Tlist_Change_Sort(caller, action, sort_type)
call s:Tlist_Log_Msg('Tlist_Change_Sort (caller = ' . a:caller . call s:Tlist_Log_Msg('Tlist_Change_Sort (caller = ' . a:caller .
\ ', action = ' . a:action . ', sort_type = ' . a:sort_type . ')') \ ', action = ' . a:action . ', sort_type = ' . a:sort_type . ')')
if a:caller == 1 if a:caller == 1
let fidx = s:Tlist_Get_File_Index_By_Linenum(line('.')) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(line('.'))
if fidx == -1 if fidx == -1
return return
endif endif
@ -2790,7 +2833,7 @@ endfunction
" Update the tags displayed in the taglist window " Update the tags displayed in the taglist window
function! s:Tlist_Window_Update_File() function! s:Tlist_Window_Update_File()
call s:Tlist_Log_Msg('Tlist_Window_Update_File()') call s:Tlist_Log_Msg('Tlist_Window_Update_File()')
let fidx = s:Tlist_Get_File_Index_By_Linenum(line('.')) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(line('.'))
if fidx == -1 if fidx == -1
return return
endif endif
@ -2811,9 +2854,9 @@ function! s:Tlist_Window_Update_File()
call search(curline, 'w') call search(curline, 'w')
endfunction endfunction
" Tlist_Get_Tag_Type_By_Linenum() " Tlist_Window_Get_Tag_Type_By_Linenum()
" Return the tag type index for the specified line in the taglist window " Return the tag type index for the specified line in the taglist window
function! s:Tlist_Get_Tag_Type_By_Linenum(fidx, lnum) function! s:Tlist_Window_Get_Tag_Type_By_Linenum(fidx, lnum)
let ftype = s:tlist_{a:fidx}_filetype let ftype = s:tlist_{a:fidx}_filetype
" Determine to which tag type the current line number belongs to using the " Determine to which tag type the current line number belongs to using the
@ -2838,10 +2881,10 @@ function! s:Tlist_Get_Tag_Type_By_Linenum(fidx, lnum)
return ttype return ttype
endfunction endfunction
" Tlist_Get_Tag_Index() " Tlist_Window_Get_Tag_Index()
" Return the tag index for the specified line " Return the tag index for the specified line in the taglist window
function! s:Tlist_Get_Tag_Index(fidx, lnum) function! s:Tlist_Window_Get_Tag_Index(fidx, lnum)
let ttype = s:Tlist_Get_Tag_Type_By_Linenum(a:fidx, a:lnum) let ttype = s:Tlist_Window_Get_Tag_Type_By_Linenum(a:fidx, a:lnum)
" Current line doesn't belong to any of the displayed tag types " Current line doesn't belong to any of the displayed tag types
if ttype == '' if ttype == ''
@ -2875,11 +2918,11 @@ function! s:Tlist_Window_Highlight_Line()
exe 'match TagListTagName ' . pat exe 'match TagListTagName ' . pat
endfunction endfunction
" Tlist_Open_File " Tlist_Window_Open_File
" 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_Window_Open_File(win_ctrl, filename, tagpat)
call s:Tlist_Log_Msg('Tlist_Open_File (' . a:filename . ')') call s:Tlist_Log_Msg('Tlist_Window_Open_File (' . a:filename . ')')
let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh let prev_Tlist_Skip_Refresh = s:Tlist_Skip_Refresh
let s:Tlist_Skip_Refresh = 1 let s:Tlist_Skip_Refresh = 1
@ -2999,7 +3042,7 @@ function! s:Tlist_Open_File(win_ctrl, filename, tagpat)
" If the user has selected to close the taglist window, when a " If the user has selected to close the taglist window, when a
" tag is selected, close the taglist window " tag is selected, close the taglist window
if g:Tlist_Close_On_Select if g:Tlist_Close_On_Select
call s:Tlist_Goto_Window() call s:Tlist_Window_Goto_Window()
close close
" Go back to the window displaying the selected file " Go back to the window displaying the selected file
@ -3013,13 +3056,13 @@ function! s:Tlist_Open_File(win_ctrl, filename, tagpat)
let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh let s:Tlist_Skip_Refresh = prev_Tlist_Skip_Refresh
endfunction endfunction
" Tlist_Jump_To_Tag() " Tlist_Window_Jump_To_Tag()
" Jump to the location of the current tag " Jump to the location of the current tag
" win_ctrl == 0 - Reuse the existing file window " win_ctrl == 0 - Reuse the existing file window
" win_ctrl == 1 - Open a new window " win_ctrl == 1 - Open a new window
" win_ctrl == 2 - Preview the tag " win_ctrl == 2 - Preview the tag
function! s:Tlist_Jump_To_Tag(win_ctrl) function! s:Tlist_Window_Jump_To_Tag(win_ctrl)
call s:Tlist_Log_Msg('Tlist_Jump_To_Tag()') call s:Tlist_Log_Msg('Tlist_Window_Jump_To_Tag()')
" Do not process comment lines and empty lines " Do not process comment lines and empty lines
let curline = getline('.') let curline = getline('.')
if curline =~ '^\s*$' || curline[0] == '"' if curline =~ '^\s*$' || curline[0] == '"'
@ -3037,13 +3080,13 @@ function! s:Tlist_Jump_To_Tag(win_ctrl)
.foldopen! .foldopen!
endif endif
let fidx = s:Tlist_Get_File_Index_By_Linenum(lnum) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(lnum)
if fidx == -1 if fidx == -1
return return
endif endif
" Get the tag output for the current tag " Get the tag output for the current tag
let tidx = s:Tlist_Get_Tag_Index(fidx, lnum) let tidx = s:Tlist_Window_Get_Tag_Index(fidx, lnum)
if tidx != 0 if tidx != 0
let tagpat = s:Tlist_Get_Tag_SearchPat(fidx, tidx) let tagpat = s:Tlist_Get_Tag_SearchPat(fidx, tidx)
@ -3054,13 +3097,13 @@ function! s:Tlist_Jump_To_Tag(win_ctrl)
let tagpat = '' let tagpat = ''
endif endif
call s:Tlist_Open_File(a:win_ctrl, s:tlist_{fidx}_filename, tagpat) call s:Tlist_Window_Open_File(a:win_ctrl, s:tlist_{fidx}_filename, tagpat)
endfunction endfunction
" Tlist_Show_Info() " Tlist_Window_Show_Info()
" Display information about the entry under the cursor " Display information about the entry under the cursor
function! s:Tlist_Show_Info() function! s:Tlist_Window_Show_Info()
call s:Tlist_Log_Msg('Tlist_Show_Info()') call s:Tlist_Log_Msg('Tlist_Window_Show_Info()')
" Clear the previously displayed line " Clear the previously displayed line
echo echo
@ -3079,7 +3122,7 @@ function! s:Tlist_Show_Info()
let lnum = line('.') let lnum = line('.')
" Get the file index " Get the file index
let fidx = s:Tlist_Get_File_Index_By_Linenum(lnum) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(lnum)
if fidx == -1 if fidx == -1
return return
endif endif
@ -3096,10 +3139,10 @@ function! s:Tlist_Show_Info()
endif endif
" Get the tag output line for the current tag " Get the tag output line for the current tag
let tidx = s:Tlist_Get_Tag_Index(fidx, lnum) let tidx = s:Tlist_Window_Get_Tag_Index(fidx, lnum)
if tidx == 0 if tidx == 0
" Cursor is on a tag type " Cursor is on a tag type
let ttype = s:Tlist_Get_Tag_Type_By_Linenum(fidx, lnum) let ttype = s:Tlist_Window_Get_Tag_Type_By_Linenum(fidx, lnum)
if ttype == '' if ttype == ''
return return
endif endif
@ -3193,12 +3236,12 @@ function! s:Tlist_Find_Nearest_Tag_Idx(fidx, linenum)
return left return left
endfunction endfunction
" Tlist_Highlight_Tag() " Tlist_Window_Highlight_Tag()
" Highlight the current tag " Highlight the current tag
" cntx == 1, Called by the taglist plugin itself " cntx == 1, Called by the taglist plugin itself
" cntx == 2, Forced by the user through the TlistHighlightTag command " cntx == 2, Forced by the user through the TlistHighlightTag command
" center = 1, move the tag line to the center of the taglist window " center = 1, move the tag line to the center of the taglist window
function! s:Tlist_Highlight_Tag(filename, cur_lnum, cntx, center) function! s:Tlist_Window_Highlight_Tag(filename, cur_lnum, cntx, center)
" Highlight the current tag only if the user configured the " Highlight the current tag only if the user configured the
" taglist plugin to do so or if the user explictly invoked the " taglist plugin to do so or if the user explictly invoked the
" command to highlight the current tag. " command to highlight the current tag.
@ -3418,12 +3461,12 @@ function! Tlist_Get_Tagname_By_Line(...)
return s:tlist_{fidx}_{tidx}_tag_name return s:tlist_{fidx}_{tidx}_tag_name
endfunction endfunction
" Tlist_Move_To_File " Tlist_Window_Move_To_File
" Move the cursor to the beginning of the current file or the next file " Move the cursor to the beginning of the current file or the next file
" or the previous file in the taglist window " or the previous file in the taglist window
" dir == -1, move to start of current or previous function " dir == -1, move to start of current or previous function
" dir == 1, move to start of next function " dir == 1, move to start of next function
function! s:Tlist_Move_To_File(dir) function! s:Tlist_Window_Move_To_File(dir)
if foldlevel('.') == 0 if foldlevel('.') == 0
" Cursor is on a non-folded line (it is not in any of the files) " Cursor is on a non-folded line (it is not in any of the files)
" Move it to a folded line " Move it to a folded line
@ -3437,7 +3480,7 @@ function! s:Tlist_Move_To_File(dir)
endif endif
endif endif
let fidx = s:Tlist_Get_File_Index_By_Linenum(line('.')) let fidx = s:Tlist_Window_Get_File_Index_By_Linenum(line('.'))
if fidx == -1 if fidx == -1
return return
endif endif
@ -3451,24 +3494,25 @@ function! s:Tlist_Move_To_File(dir)
return return
endif endif
if fidx == 0 if fidx != 0
" At the first file, can't move to previous file " Move to the beginning of the previous file
return let fidx = fidx - 1
else
" Cursor is at the first file, wrap around to the last file
let fidx = s:tlist_file_count - 1
endif endif
" Otherwise, move to the beginning of the previous file
let fidx = fidx - 1
exe s:tlist_{fidx}_start exe s:tlist_{fidx}_start
return return
else else
" Move to the beginning of the next file
let fidx = fidx + 1 let fidx = fidx + 1
if fidx == s:tlist_file_count if fidx >= s:tlist_file_count
" At the last file, can't move to the next file " Cursor is at the last file, wrap around to the first file
return let fidx = 0
endif endif
" Otherwise, move to the beginning of the next file
if s:tlist_{fidx}_start != 0 if s:tlist_{fidx}_start != 0
exe s:tlist_{fidx}_start exe s:tlist_{fidx}_start
endif endif
@ -3595,7 +3639,7 @@ function! s:Tlist_Session_Load(...)
let save_winnr = winnr() let save_winnr = winnr()
" Goto the taglist window " Goto the taglist window
call s:Tlist_Goto_Window() call s:Tlist_Window_Goto_Window()
" Refresh the taglist window " Refresh the taglist window
call s:Tlist_Window_Refresh() call s:Tlist_Window_Refresh()
@ -3698,7 +3742,7 @@ function! s:Tlist_Session_Save(...)
endfunction endfunction
" Tlist_Buffer_Removed " Tlist_Buffer_Removed
" A buffer is wiped out from the Vim buffer list. Remove the tags defined " A buffer is removed from the Vim buffer list. Remove the tags defined
" for that file " for that file
function! s:Tlist_Buffer_Removed(filename) function! s:Tlist_Buffer_Removed(filename)
call s:Tlist_Log_Msg('Tlist_Buffer_Removed (' . a:filename . ')') call s:Tlist_Log_Msg('Tlist_Buffer_Removed (' . a:filename . ')')
@ -3722,10 +3766,10 @@ endfunction
" When a buffer is deleted, remove the file from the taglist " When a buffer is deleted, remove the file from the taglist
autocmd BufDelete * silent call s:Tlist_Buffer_Removed(expand('<afile>:p')) autocmd BufDelete * silent call s:Tlist_Buffer_Removed(expand('<afile>:p'))
" Tlist_Close_File_Fold " Tlist_Window_Close_File_Fold
" Close the fold for the specified file " Close the fold for the specified file
function! s:Tlist_Close_File_Fold(filename) function! s:Tlist_Window_Close_File_Fold(filename)
call s:Tlist_Log_Msg('Tlist_Close_File_Fold (' . a:filename . ')') call s:Tlist_Log_Msg('Tlist_Window_Close_File_Fold (' . a:filename . ')')
" Make sure a valid filename is supplied " Make sure a valid filename is supplied
if a:filename == '' if a:filename == ''
return return
@ -3775,11 +3819,11 @@ function! s:Tlist_Close_File_Fold(filename)
endif endif
endfunction endfunction
" Tlist_Auto_Open_Check " Tlist_Window_Check_Auto_Open
" Open the taglist window automatically on Vim startup. " Open the taglist window automatically on Vim startup.
" Open the window only when files present in any of the Vim windows support " Open the window only when files present in any of the Vim windows support
" tags. " tags.
function! s:Tlist_Check_Auto_Open() function! s:Tlist_Window_Check_Auto_Open()
let open = 0 let open = 0
let i = 1 let i = 1
@ -3799,7 +3843,7 @@ function! s:Tlist_Check_Auto_Open()
endif endif
endfunction endfunction
function! s:Tlist_Add_Base_Menu() function! s:Tlist_Menu_Add_Base_Menu()
call s:Tlist_Log_Msg('Adding the base menu') call s:Tlist_Log_Msg('Adding the base menu')
" Add the menu " Add the menu
@ -3826,14 +3870,20 @@ let s:menu_char_prefix =
" Tlist_Menu_Get_Tag_Type_Cmd " Tlist_Menu_Get_Tag_Type_Cmd
" Get the menu command for the specified tag type " Get the menu command for the specified tag type
function! s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, ttype_idx) " fidx - File type index
" ftype - File Type
" add_ttype_name - To add or not to add the tag type name to the menu entries
" ttype_idx - Tag type index
function! s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, add_ttype_name, ttype_idx)
" Curly brace variable name optimization " Curly brace variable name optimization
let ftype_ttype_idx = a:ftype . '_' . a:ttype_idx let ftype_ttype_idx = a:ftype . '_' . a:ttype_idx
let ttype = s:tlist_{ftype_ttype_idx}_name let ttype = s:tlist_{ftype_ttype_idx}_name
" If the tag type name contains space characters, escape it. This if a:add_ttype_name
" will be used to create the menu entries. " If the tag type name contains space characters, escape it. This
let ttype_fullname = escape(s:tlist_{ftype_ttype_idx}_fullname, ' ') " will be used to create the menu entries.
let ttype_fullname = escape(s:tlist_{ftype_ttype_idx}_fullname, ' ')
endif
" Curly brace variable name optimization " Curly brace variable name optimization
let fidx_ttype = a:fidx . '_' . ttype let fidx_ttype = a:fidx . '_' . ttype
@ -3871,9 +3921,11 @@ function! s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, ttype_idx)
let last_tag = strpart(last_tag, 0, g:Tlist_Max_Tag_Length) let last_tag = strpart(last_tag, 0, g:Tlist_Max_Tag_Length)
" Form the menu command prefix " Form the menu command prefix
let m_prefix = 'anoremenu <silent> T\&ags.' . let m_prefix = 'anoremenu <silent> T\&ags.'
\ ttype_fullname . '.' . if a:add_ttype_name
\ first_tag . '\.\.\.' . last_tag . '.' let m_prefix = m_prefix . ttype_fullname . '.'
endif
let m_prefix = m_prefix . first_tag . '\.\.\.' . last_tag . '.'
" Character prefix used to number the menu items (hotkey) " Character prefix used to number the menu items (hotkey)
let m_prefix_idx = 0 let m_prefix_idx = 0
@ -3896,7 +3948,10 @@ function! s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, ttype_idx)
" Character prefix used to number the menu items (hotkey) " Character prefix used to number the menu items (hotkey)
let m_prefix_idx = 0 let m_prefix_idx = 0
let m_prefix = 'anoremenu <silent> T\&ags.' . ttype_fullname . '.' let m_prefix = 'anoremenu <silent> T\&ags.'
if a:add_ttype_name
let m_prefix = m_prefix . ttype_fullname . '.'
endif
let j = 1 let j = 1
while j <= tcnt while j <= tcnt
let tidx = s:tlist_{fidx_ttype}_{j} let tidx = s:tlist_{fidx_ttype}_{j}
@ -3999,10 +4054,23 @@ function! s:Tlist_Menu_Update_File(clear_menu)
let cmd = '' let cmd = ''
" Determine whether the tag type name needs to be added to the menu
" If more than one tag type is present in the taglisting for a file,
" then the tag type name needs to be present
let add_ttype_name = -1
let i = 1
while i <= s:tlist_{ftype}_count && add_ttype_name < 1
let ttype = s:tlist_{ftype}_{i}_name
if s:tlist_{fidx}_{ttype}_count
let add_ttype_name = add_ttype_name + 1
endif
let i = i + 1
endwhile
" Process the tags by the tag type and get the menu command " Process the tags by the tag type and get the menu command
let i = 1 let i = 1
while i <= s:tlist_{ftype}_count while i <= s:tlist_{ftype}_count
let mcmd = s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, i) let mcmd = s:Tlist_Menu_Get_Tag_Type_Cmd(fidx, ftype, add_ttype_name, i)
if mcmd != '' if mcmd != ''
let cmd = cmd . mcmd let cmd = cmd . mcmd
endif endif
@ -4040,7 +4108,7 @@ function! s:Tlist_Menu_Remove_File()
silent! unmenu! PopUp.T&ags silent! unmenu! PopUp.T&ags
endif endif
call s:Tlist_Add_Base_Menu() call s:Tlist_Menu_Add_Base_Menu()
" Remove the dummy menu item " Remove the dummy menu item
unmenu T&ags.Dummy unmenu T&ags.Dummy
@ -4093,7 +4161,7 @@ endfunction
" Tlist_Menu_Init " Tlist_Menu_Init
" Initialize the taglist menu " Initialize the taglist menu
function! s:Tlist_Menu_Init() function! s:Tlist_Menu_Init()
call s:Tlist_Add_Base_Menu() call s:Tlist_Menu_Add_Base_Menu()
" Automatically add the tags defined in the current file to the menu " Automatically add the tags defined in the current file to the menu
augroup TagListMenuCmds augroup TagListMenuCmds