1
1
" File: taglist.vim
2
2
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3
- " Version: 4.0 Beta 4
4
- " Last Modified: April 12 , 2006
3
+ " Version: 4.0
4
+ " Last Modified: September 6 , 2006
5
5
"
6
6
" The "Tag List" plugin is a source code browser plugin for Vim and provides
7
7
" an overview of the structure of the programming language files and allows
@@ -252,20 +252,20 @@ if !exists('loaded_taglist')
252
252
autocmd BufFilePost __Tag_List__ call s: Tlist_Vim_Session_Load ()
253
253
254
254
" Define the user commands to manage the taglist window
255
- command ! -nargs =0 TlistToggle call s: Tlist_Window_Toggle ()
256
- command ! -nargs =0 TlistOpen call s: Tlist_Window_Open ()
255
+ command ! -nargs =0 - bar TlistToggle call s: Tlist_Window_Toggle ()
256
+ command ! -nargs =0 - bar TlistOpen call s: Tlist_Window_Open ()
257
257
" For backwards compatiblity define the Tlist command
258
- command ! -nargs =0 Tlist TlistToggle
258
+ command ! -nargs =0 - bar Tlist TlistToggle
259
259
command ! -nargs =+ -complete =file TlistAddFiles
260
260
\ call s: Tlist_Add_Files (<f-args> )
261
261
command ! -nargs =+ -complete =dir TlistAddFilesRecursive
262
262
\ call s: Tlist_Add_Files_Recursive (<f-args> )
263
- command ! -nargs =0 TlistClose call s: Tlist_Window_Close ()
264
- command ! -nargs =0 TlistUpdate call s: Tlist_Update_Current_File ()
265
- command ! -nargs =0 TlistHighlightTag call s: Tlist_Window_Highlight_Tag (
263
+ command ! -nargs =0 - bar TlistClose call s: Tlist_Window_Close ()
264
+ command ! -nargs =0 - bar TlistUpdate call s: Tlist_Update_Current_File ()
265
+ command ! -nargs =0 - bar TlistHighlightTag call s: Tlist_Window_Highlight_Tag (
266
266
\ fnamemodify (bufname (' %' ), ' :p' ), line (' .' ), 2 , 1 )
267
267
" For backwards compatiblity define the TlistSync command
268
- command ! -nargs =0 TlistSync TlistHighlightTag
268
+ command ! -nargs =0 - bar TlistSync TlistHighlightTag
269
269
command ! -nargs =* -complete =buffer TlistShowPrototype
270
270
\ echo Tlist_Get_Tag_Prototype_By_Line (<f-args> )
271
271
command ! -nargs =* -complete =buffer TlistShowTag
@@ -274,14 +274,14 @@ if !exists('loaded_taglist')
274
274
\ call s: Tlist_Session_Load (<q-args> )
275
275
command ! -nargs =* -complete =file TlistSessionSave
276
276
\ call s: Tlist_Session_Save (<q-args> )
277
- command ! TlistLock let Tlist_Auto_Update= 0
278
- command ! TlistUnlock let Tlist_Auto_Update= 1
277
+ command ! TlistLock - bar let Tlist_Auto_Update= 0
278
+ command ! TlistUnlock - bar let Tlist_Auto_Update= 1
279
279
280
280
" Commands for enabling/disabling debug and to display debug messages
281
- command ! -nargs =? -complete =file TlistDebug
281
+ command ! -nargs =? -complete =file - bar TlistDebug
282
282
\ call s: Tlist_Debug_Enable (<q-args> )
283
- command ! -nargs =0 TlistUndebug call s: Tlist_Debug_Disable ()
284
- command ! -nargs =0 TlistMessages echo s: tlist_msg
283
+ command ! -nargs =0 - bar TlistUndebug call s: Tlist_Debug_Disable ()
284
+ command ! -nargs =0 - bar TlistMessages echo s: tlist_msg
285
285
286
286
" Define autocommands to autoload the taglist plugin when needed.
287
287
@@ -468,7 +468,7 @@ let s:tlist_def_yacc_settings = 'yacc;l:label'
468
468
" ------------------- end of language specific options --------------------
469
469
470
470
" Vim window size is changed by the taglist plugin or not
471
- let s: tlist_winsize_chgd = 0
471
+ let s: tlist_winsize_chgd = -1
472
472
" Taglist window is maximized or not
473
473
let s: tlist_win_maximized = 0
474
474
" Name of files in the taglist
@@ -1244,20 +1244,22 @@ function! s:Tlist_Window_Create()
1244
1244
" Horizontal window height
1245
1245
let win_size = g: Tlist_WinHeight
1246
1246
else
1247
- " Open a vertically split window. Increase the window size, if
1248
- " needed, to accomodate the new window
1249
- if g: Tlist_Inc_Winwidth &&
1250
- \ &columns < (80 + g: Tlist_WinWidth )
1251
- " Save the original window position
1252
- let s: tlist_pre_winx = getwinposx ()
1253
- let s: tlist_pre_winy = getwinposy ()
1254
-
1255
- " one extra column is needed to include the vertical split
1256
- let &columns = &columns + g: Tlist_WinWidth + 1
1257
-
1258
- let s: tlist_winsize_chgd = 1
1259
- else
1260
- let s: tlist_winsize_chgd = 0
1247
+ if s: tlist_winsize_chgd == -1
1248
+ " Open a vertically split window. Increase the window size, if
1249
+ " needed, to accomodate the new window
1250
+ if g: Tlist_Inc_Winwidth &&
1251
+ \ &columns < (80 + g: Tlist_WinWidth )
1252
+ " Save the original window position
1253
+ let s: tlist_pre_winx = getwinposx ()
1254
+ let s: tlist_pre_winy = getwinposy ()
1255
+
1256
+ " one extra column is needed to include the vertical split
1257
+ let &columns = &columns + g: Tlist_WinWidth + 1
1258
+
1259
+ let s: tlist_winsize_chgd = 1
1260
+ else
1261
+ let s: tlist_winsize_chgd = 0
1262
+ endif
1261
1263
endif
1262
1264
1263
1265
if g: Tlist_Use_Right_Window
@@ -1315,6 +1317,26 @@ function! s:Tlist_Window_Zoom()
1315
1317
endif
1316
1318
endfunction
1317
1319
1320
+ " Tlist_Ballon_Expr
1321
+ " When the mouse cursor is over a tag in the taglist window, display the
1322
+ " tag prototype (balloon)
1323
+ function ! Tlist_Ballon_Expr ()
1324
+ " Get the file index
1325
+ let fidx = s: Tlist_Window_Get_File_Index_By_Linenum (v: beval_lnum )
1326
+ if fidx == -1
1327
+ return ' '
1328
+ endif
1329
+
1330
+ " Get the tag output line for the current tag
1331
+ let tidx = s: Tlist_Window_Get_Tag_Index (fidx, v: beval_lnum )
1332
+ if tidx == 0
1333
+ return ' '
1334
+ endif
1335
+
1336
+ " Get the tag search pattern and display it
1337
+ return s: Tlist_Get_Tag_Prototype (fidx, tidx)
1338
+ endfunction
1339
+
1318
1340
" Tlist_Window_Check_Width
1319
1341
" Check the width of the taglist window. For horizontally split windows, the
1320
1342
" 'winfixheight' option is used to fix the height of the window. For
@@ -1341,6 +1363,32 @@ function! s:Tlist_Window_Check_Width()
1341
1363
endif
1342
1364
endfunction
1343
1365
1366
+ " Tlist_Window_Exit_Only_Window
1367
+ " If the 'Tlist_Exit_OnlyWindow' option is set, then exit Vim if only the
1368
+ " taglist window is present.
1369
+ function ! s: Tlist_Window_Exit_Only_Window ()
1370
+ " Before quitting Vim, delete the taglist buffer so that
1371
+ " the '0 mark is correctly set to the previous buffer.
1372
+ if v: version < 700
1373
+ if winbufnr (2 ) == -1
1374
+ bdelete
1375
+ quit
1376
+ endif
1377
+ else
1378
+ if winbufnr (2 ) == -1
1379
+ if tabpagenr (' $' ) == 1
1380
+ " Only one tag page is present
1381
+ bdelete
1382
+ quit
1383
+ else
1384
+ " More than one tab page is present. Close only the current
1385
+ " tab page
1386
+ close
1387
+ endif
1388
+ endif
1389
+ endif
1390
+ endfunction
1391
+
1344
1392
" Tlist_Window_Init
1345
1393
" Set the default options for the taglist window
1346
1394
function ! s: Tlist_Window_Init ()
@@ -1439,6 +1487,12 @@ function! s:Tlist_Window_Init()
1439
1487
set winfixwidth
1440
1488
endif
1441
1489
1490
+ " Setup balloon evaluation to display tag prototype
1491
+ if v: version >= 700 && has (' balloon_eval' )
1492
+ setlocal balloonexpr = Tlist_Ballon_Expr ()
1493
+ set ballooneval
1494
+ endif
1495
+
1442
1496
" Setup the cpoptions properly for the maps to work
1443
1497
let old_cpoptions = &cpoptions
1444
1498
set cpoptions &vim
@@ -1531,17 +1585,15 @@ function! s:Tlist_Window_Init()
1531
1585
1532
1586
" Adjust the Vim window width when taglist window is closed
1533
1587
autocmd BufUnload __Tag_List__ call s: Tlist_Post_Close_Cleanup ()
1534
- " Close the fold for this buffer when it's not visible in any window
1588
+ " Close the fold for this buffer when leaving the buffer
1535
1589
if g: Tlist_File_Fold_Auto_Close
1536
- autocmd BufWinLeave * silent
1590
+ autocmd BufWinLeave , BufLeave * silent
1537
1591
\ call s: Tlist_Window_Close_File_Fold (expand (' <afile>:p' ))
1538
1592
endif
1539
1593
" Exit Vim itself if only the taglist window is present (optional)
1540
1594
if g: Tlist_Exit_OnlyWindow
1541
- " Before quitting Vim, delete the taglist buffer so that
1542
- " the '0 mark is correctly set to the previous buffer.
1543
- autocmd BufEnter __Tag_List__ nested if winbufnr (2 ) == -1 |
1544
- \ bdelete | quit | endif
1595
+ autocmd BufEnter __Tag_List__ nested
1596
+ \ call s: Tlist_Window_Exit_Only_Window ()
1545
1597
endif
1546
1598
if s: tlist_app_name != " winmanager" &&
1547
1599
\ ! g: Tlist_Process_File_Always &&
@@ -1670,7 +1722,7 @@ function! s:Tlist_Post_Close_Cleanup()
1670
1722
1671
1723
if s: tlist_app_name != " winmanager"
1672
1724
if g: Tlist_Use_Horiz_Window || g: Tlist_Inc_Winwidth == 0 ||
1673
- \ s: tlist_winsize_chgd == 0 ||
1725
+ \ s: tlist_winsize_chgd != 1 ||
1674
1726
\ &columns < (80 + g: Tlist_WinWidth )
1675
1727
" No need to adjust window width if using horizontally split taglist
1676
1728
" window or if columns is less than 101 or if the user chose not to
@@ -1689,6 +1741,8 @@ function! s:Tlist_Post_Close_Cleanup()
1689
1741
endif
1690
1742
endif
1691
1743
1744
+ let s: tlist_winsize_chgd = -1
1745
+
1692
1746
" Reset taglist state variables
1693
1747
if s: tlist_app_name == " winmanager"
1694
1748
let s: tlist_app_name = " none"
@@ -3006,6 +3060,15 @@ function! s:Tlist_Window_Open_File(win_ctrl, filename, tagpat)
3006
3060
" Mark the window, so that it can be reused.
3007
3061
let w: tlist_file_window = " yes"
3008
3062
else
3063
+ if v: version >= 700
3064
+ " If the file is opened in more than one window, then check
3065
+ " whether the last accessed window has the selected file.
3066
+ " If it does, then use that window.
3067
+ let lastwin_bufnum = winbufnr (winnr (' #' ))
3068
+ if bufnr (a: filename ) == lastwin_bufnum
3069
+ let winnum = winnr (' #' )
3070
+ endif
3071
+ endif
3009
3072
exe winnum . ' wincmd w'
3010
3073
3011
3074
" If the user asked to jump to the tag in a new window, then split the
@@ -3824,21 +3887,21 @@ endfunction
3824
3887
" Open the window only when files present in any of the Vim windows support
3825
3888
" tags.
3826
3889
function ! s: Tlist_Window_Check_Auto_Open ()
3827
- let open = 0
3890
+ let open_window = 0
3828
3891
3829
3892
let i = 1
3830
3893
let buf_num = winbufnr (i )
3831
3894
while buf_num != -1
3832
3895
let filename = fnamemodify (bufname (buf_num), ' :p' )
3833
3896
if ! s: Tlist_Skip_File (filename, getbufvar (buf_num, ' &filetype' ))
3834
- let open = 1
3897
+ let open_window = 1
3835
3898
break
3836
3899
endif
3837
3900
let i = i + 1
3838
3901
let buf_num = winbufnr (i )
3839
3902
endwhile
3840
3903
3841
- if open
3904
+ if open_window
3842
3905
call s: Tlist_Window_Toggle ()
3843
3906
endif
3844
3907
endfunction
0 commit comments