Skip to content

Commit 4715071

Browse files
committed
commit version 2.6 (released on June 9, 2003)
1 parent 6c34101 commit 4715071

File tree

1 file changed

+85
-24
lines changed

1 file changed

+85
-24
lines changed

plugin/taglist.vim

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" File: taglist.vim
22
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3-
" Version: 2.5
4-
" Last Modified: April 26, 2003
3+
" Version: 2.6
4+
" Last Modified: June 9, 2003
55
"
66
" Overview
77
" --------
@@ -94,7 +94,8 @@
9494
" You can close the taglist window from the taglist window by pressing 'q' or
9595
" using the Vim ":q" command. You can also use any of the Vim window commands
9696
" to close the taglist window. Invoking the ":Tlist" command when the taglist
97-
" window is opened, will close the taglist window.
97+
" window is opened, will close the taglist window. You can also close the
98+
" taglist window by invoking the ":TlistClose" command.
9899
"
99100
" As you switch between source files, the taglist window will be automatically
100101
" updated with the tag listing for the current source file. The tag names
@@ -112,7 +113,9 @@
112113
" You can select a tag either by pressing the <Enter> key or by double
113114
" clicking the tag name using the mouse. You can configure the taglist plugin
114115
" by setting the 'Tlist_Use_SingleClick' variable to jump to a tag on a single
115-
" mouse click.
116+
" mouse click. You can press the 'o' key to jump to the tag in a new window.
117+
" You can press the 'p' key to jump to the tag but still keep the cursor in
118+
" the taglist window itself.
116119
"
117120
" This plugin will automatically highlight the name of the current tag. The
118121
" tag name will be highlighted after 'updatetime' milliseconds. The default
@@ -153,6 +156,8 @@
153156
" defined.
154157
" o Jump to the location where the tag under cursor is
155158
" defined in a new window.
159+
" p Display the tag definition in the file window and
160+
" keep the cursor in the taglist window itself.
156161
" <Space> Display the prototype of the tag under the cursor.
157162
" u Update the tags listed in the taglist window
158163
" s Change the sort order of the tags (by name or by order)
@@ -279,6 +284,13 @@
279284
"
280285
" let Tlist_Compact_Format = 1
281286
"
287+
" If you want to exit Vim if only the taglist window is currently open, then
288+
" set the Tlist_Exit_OnlyWindow variable to one. By default, this variable is
289+
" set to zero and the Vim instance will not be closed if only the taglist
290+
" window is open.
291+
"
292+
" let Tlist_Exit_OnlyWindow = 1
293+
"
282294
" Extending
283295
" ---------
284296
" You can extend exuberant ctags to add support for new languages. For more
@@ -401,6 +413,12 @@ if !exists('Tlist_Compact_Format')
401413
let Tlist_Compact_Format = 0
402414
endif
403415

416+
" Exit Vim if only the taglist window is currently open. By default, this is
417+
" set to zero.
418+
if !exists('Tlist_Exit_OnlyWindow')
419+
let Tlist_Exit_OnlyWindow = 0
420+
endif
421+
404422
" assembly language
405423
let s:tlist_def_asm_settings = 'asm;d:define;l:label;m:macro;t:type'
406424

@@ -880,17 +898,18 @@ function! s:Tlist_Init_Window(bufnum)
880898
if exists("s:tlist_show_help") && s:tlist_show_help == 1
881899
call append(0, '" <enter> : Jump to tag definition')
882900
call append(1, '" o : Jump to tag definition in new window')
883-
call append(2, '" <space> : Display tag prototype')
884-
call append(3, '" u : Update tag list')
885-
call append(4, '" s : Select sort field')
886-
call append(5, '" x : Zoom-out/Zoom-in taglist window')
887-
call append(6, '" + : Open a fold')
888-
call append(7, '" - : Close a fold')
889-
call append(8, '" * : Open all folds')
890-
call append(9, '" q : Close the taglist window')
891-
call append(10, '" ? : Remove help text')
892-
call append(11, '" Sorted by ' . b:tlist_sort_type)
893-
call append(12, '"= ' . fnamemodify(filename, ':t') . ' (' .
901+
call append(2, '" p : Preview the tag definition')
902+
call append(3, '" <space> : Display tag prototype')
903+
call append(4, '" u : Update tag list')
904+
call append(5, '" s : Select sort field')
905+
call append(6, '" x : Zoom-out/Zoom-in taglist window')
906+
call append(7, '" + : Open a fold')
907+
call append(8, '" - : Close a fold')
908+
call append(9, '" * : Open all folds')
909+
call append(10, '" q : Close the taglist window')
910+
call append(11, '" ? : Remove help text')
911+
call append(12, '" Sorted by ' . b:tlist_sort_type)
912+
call append(13, '"= ' . fnamemodify(filename, ':t') . ' (' .
894913
\ fnamemodify(filename, ':p:h') . ')')
895914
else
896915
call append(0, '" Press ? to display help text')
@@ -962,6 +981,7 @@ function! s:Tlist_Init_Window(bufnum)
962981
" Create buffer local mappings for jumping to the tags and sorting the list
963982
nnoremap <buffer> <silent> <CR> :call <SID>Tlist_Jump_To_Tag(0)<CR>
964983
nnoremap <buffer> <silent> o :call <SID>Tlist_Jump_To_Tag(1)<CR>
984+
nnoremap <buffer> <silent> p :call <SID>Tlist_Jump_To_Tag(2)<CR>
965985
nnoremap <buffer> <silent> <2-LeftMouse> :call <SID>Tlist_Jump_To_Tag(0)<CR>
966986
nnoremap <buffer> <silent> s :call <SID>Tlist_Change_Sort()<CR>
967987
nnoremap <buffer> <silent> + :silent! foldopen<CR>
@@ -981,6 +1001,7 @@ function! s:Tlist_Init_Window(bufnum)
9811001
" Windows needs return
9821002
inoremap <buffer> <silent> <Return> <C-o>:call <SID>Tlist_Jump_To_Tag(0)<CR>
9831003
inoremap <buffer> <silent> o <C-o>:call <SID>Tlist_Jump_To_Tag(1)<CR>
1004+
inoremap <buffer> <silent> p <C-o>:call <SID>Tlist_Jump_To_Tag(2)<CR>
9841005
inoremap <buffer> <silent> <2-LeftMouse> <C-o>:call
9851006
\ <SID>Tlist_Jump_To_Tag(0)<CR>
9861007
inoremap <buffer> <silent> s <C-o>:call <SID>Tlist_Change_Sort()<CR>
@@ -1011,7 +1032,8 @@ function! s:Tlist_Init_Window(bufnum)
10111032
" Highlight the current tag
10121033
autocmd CursorHold * silent call <SID>Tlist_Highlight_Tag(bufnr('%'),
10131034
\ line('.'))
1014-
autocmd BufUnload __Tag_List__ call <SID>Tlist_Close_Window()
1035+
autocmd BufUnload __Tag_List__ call <SID>Tlist_Post_Close_Cleanup()
1036+
autocmd BufEnter __Tag_List__ call <SID>Tlist_Check_Only_Window()
10151037
if !s:tlist_part_of_winmanager
10161038
" Adjust the Vim window width when taglist window is closed
10171039
" Auto refresh the taglisting window
@@ -1020,9 +1042,9 @@ function! s:Tlist_Init_Window(bufnum)
10201042
augroup end
10211043
endfunction
10221044

1023-
" Tlist_Close_Window()
1045+
" Tlist_Post_Close_Cleanup()
10241046
" Close the taglist window and adjust the Vim window width
1025-
function! s:Tlist_Close_Window()
1047+
function! s:Tlist_Post_Close_Cleanup()
10261048
" Remove the autocommands for the taglist window
10271049
silent! autocmd! TagListAutoCmds
10281050

@@ -1054,6 +1076,19 @@ function! s:Tlist_Close_Window()
10541076
endif
10551077
endfunction
10561078

1079+
" Tlist_Check_Only_Window
1080+
" Check if only the taglist window is opened currently. If the
1081+
" Tlist_Exit_OnlyWindow variable is set, then close the taglist window
1082+
function! s:Tlist_Check_Only_Window()
1083+
if g:Tlist_Exit_OnlyWindow
1084+
if winbufnr(2) == -1
1085+
" If only the taglist window is currently open, then the buffer
1086+
" number associated with window 2 will be -1.
1087+
quit
1088+
endif
1089+
endif
1090+
endfunction
1091+
10571092
" Tlist_Explore_File()
10581093
" List the tags defined in the specified file in a Vim window
10591094
function! s:Tlist_Explore_File(bufnum)
@@ -1334,6 +1369,20 @@ function! s:Tlist_Explore_File(bufnum)
13341369
return
13351370
endfunction
13361371

1372+
" Tlist_Close_Window
1373+
" Close the taglist window
1374+
function! s:Tlist_Close_Window()
1375+
" Make sure the taglist window exists
1376+
let winnum = bufwinnr(g:TagList_title)
1377+
if winnum != -1
1378+
" Jump to the window if not already there
1379+
if winnr() != winnum
1380+
exe winnum . 'wincmd w'
1381+
endif
1382+
close
1383+
endif
1384+
endfunction
1385+
13371386
" Tlist_Toggle_Window()
13381387
" Open or close a taglist window
13391388
function! s:Tlist_Toggle_Window(bufnum)
@@ -1574,7 +1623,10 @@ endfunction
15741623

15751624
" Tlist_Jump_To_Tag()
15761625
" Jump to the location of the current tag
1577-
function! s:Tlist_Jump_To_Tag(new_window)
1626+
" win_ctrl == 0 - Reuse the existing file window
1627+
" win_ctrl == 1 - Open a new window
1628+
" win_ctrl == 2 - Preview the tag
1629+
function! s:Tlist_Jump_To_Tag(win_ctrl)
15781630
" Do not process comment lines and empty lines
15791631
let curline = getline('.')
15801632
if curline == '' || curline[0] == '"'
@@ -1607,7 +1659,7 @@ function! s:Tlist_Jump_To_Tag(new_window)
16071659
let s:Tlist_Skip_Refresh = 1
16081660

16091661
if s:tlist_part_of_winmanager
1610-
call WinManagerFileEdit(bufname(b:tlist_bufnum), a:new_window)
1662+
call WinManagerFileEdit(bufname(b:tlist_bufnum), a:win_ctrl)
16111663
else
16121664
" Goto the window containing the file. If the window is not there, open a
16131665
" new window
@@ -1636,7 +1688,7 @@ function! s:Tlist_Jump_To_Tag(new_window)
16361688

16371689
" If the user asked to jump to the tag in a new window, then split the
16381690
" existing window into two.
1639-
if a:new_window
1691+
if a:win_ctrl == 1
16401692
split
16411693
endif
16421694
endif
@@ -1655,6 +1707,14 @@ function! s:Tlist_Jump_To_Tag(new_window)
16551707
endif
16561708
endif
16571709

1710+
" If the user selects to preview the tag then jump back to the
1711+
" taglist window
1712+
if a:win_ctrl == 2
1713+
" Go back to the taglist window
1714+
let winnum = bufwinnr(g:TagList_title)
1715+
exe winnum . 'wincmd w'
1716+
endif
1717+
16581718
let s:Tlist_Skip_Refresh = 0
16591719
endfunction
16601720

@@ -1780,7 +1840,8 @@ endfunction
17801840
" Tlist_Highlight_Tag()
17811841
" Do a binary search in the array of tag names and pick a tag entry that
17821842
" contains the current line and highlight it. The idea behind this function
1783-
" is taken from the ctags.vim script available at the Vim online website.
1843+
" is taken from the ctags.vim script (by Alexey Marinichev) available at the
1844+
" Vim online website.
17841845
function! s:Tlist_Highlight_Tag(bufnum, curline)
17851846
let filename = fnamemodify(bufname(a:bufnum), ':p')
17861847
if filename == ''
@@ -1915,9 +1976,9 @@ if g:Tlist_Auto_Open
19151976
autocmd VimEnter * nested Tlist
19161977
endif
19171978

1918-
" Define the 'Tlist' and 'TlistSync' user commands to open/close taglist
1919-
" window
1979+
" Define the user commands to manage the taglist window
19201980
command! -nargs=0 Tlist call s:Tlist_Toggle_Window(bufnr('%'))
1981+
command! -nargs=0 TlistClose call s:Tlist_Close_Window()
19211982
command! -nargs=0 TlistSync call s:Tlist_Highlight_Tag(bufnr('%'), line('.'))
19221983
command! -nargs=? TlistShowPrototype echo s:Tlist_Get_Tag_Prototype_By_Line(<q-args>)
19231984

0 commit comments

Comments
 (0)