Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 1.2

Add one feature and two user interfaces.
You can use your own map key to force to complete one refreshing operation. And it will take a less waiting time sometimes.
Additionally, users can set update time interval by themselves in this version.
  • Loading branch information...
commit a25d946ffc5bf3c5bdbad20b54151a9e0f070b4e 1 parent 75bc8be
@wesleyche wesleyche authored committed
Showing with 189 additions and 89 deletions.
  1. +189 −89 plugin/srcexpl.vim
View
278 plugin/srcexpl.vim
@@ -1,34 +1,76 @@
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" File: (G)Vim script file named srcexpl.vim
" Description: A (G)VIM Plugin for exploring the C/C++
" source code based on 'tags' and 'quickfix'.
" Author: Che Wenlong
" Mail: chewenlong@buaa.edu.cn
" Copyright: Copyright (C) 2008
-" Last Change: 2008 Mar 06
+" Last Change: 2008 Mar 9
+
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" A_setting_example_in_my_vimrc_file:
+
+" // Set one second time for refreshing
+" let g:SrcExpl_RefreshTime = 1
+" // Set the window height of the Souce Explorer
+" let g:SrcExpl_WinHeight = 9
+" // Set "Space" key do the refreshing operation
+" let g:SrcExpl_RefreshMapKey = "<Space>"
+" // Set "Ctrl-b" key go back from the definition context
+" let g:SrcExpl_GoBackMapKey = "<C-b>"
+" // The switch of Source Explorer plugin
+" nmap <F8> :SrcExplToggle<CR>
+
+" You_can_change_above_of_them_by_yourself:
+
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if exists("loaded_srcexpl")
finish
endif
+
let loaded_srcexpl = 1
let s:save_cpo = &cpoptions
+
set cpoptions&vim
-" User interface to open and
-" close the Source Explorer
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" User interface for switching the Source Explorer Plugin
command! -nargs=0 -bar SrcExplToggle
\ call <SID>SrcExpl_Toggle()
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" User interface for changing the
-" height of the Source Explorer
+" height of the Source Explorer Window
if !exists('g:SrcExpl_WinHeight')
let g:SrcExpl_WinHeight = 10
endif
+" User interface for setting the
+" update time interval of each refreshing
+if !exists('g:SrcExpl_RefreshTime')
+ let g:SrcExpl_RefreshTime = 1
+endif
+
+" User interface for back from
+" the definition context
if !exists('g:SrcExpl_GoBackMapKey')
let g:SrcExpl_GoBackMapKey = ""
endif
+" User interface for refreshing one
+" definition searching manually
+if !exists('g:SrcExpl_RefreshMapKey')
+ let g:SrcExpl_RefreshMapKey = ""
+endif
+
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" The key word symbol for exploring
let s:SrcExpl_Symbol = ""
" Whole file path being explored now
@@ -48,17 +90,95 @@ let s:SrcExpl_Switch = 0
" 3: multi-definitions
let s:SrcExpl_Status = 0
-" Adapter function for back to editor window
-function! <SID>SrcExpl_WinPosAdapter()
- " Taglist Plug exists
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" NOTE: You gugs can change this function by yourselves
+" in order to adapt the editor window position for
+" the Source Explorer position.
+
+function! g:SrcExpl_WinPosAdapter()
+ " If the Taglist(I can't work without it!) Plugin existed
if bufname("%") == "__Tag_List__"
- " move the cursor to its right window
+ " Move the cursor to its right window
+ " Because I used to put the taglist
+ " Window on my left.
silent! wincmd l
endif
endfunction
-" Go Back from definition context.
-" User can map this function
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" Refresh the Source Explorer window and update the status
+
+function! g:SrcExpl_Refresh()
+ " Only Source Explorer window is valid
+ if &previewwindow
+ return
+ endif
+ " Get the symbol under the cursor
+ let l:result = <SID>SrcExpl_GetSymbol()
+ " The symbol is invalid
+ if l:result != 0
+ return
+ endif
+ " Explore the source code using tag tool
+ " First Just try to get the definition of the symbol
+ try
+ " First move to the Source Explorer window
+ silent! wincmd P
+ if &previewwindow
+ " Get the whole file path of the buffer before tag
+ let s:SrcExpl_FilePath = expand("%:p")
+ " Get the current line before tag
+ let s:SrcExpl_CurrLine = line(".")
+ " Get the current colum before tag
+ let s:SrcExpl_CurrCol = col(".")
+ " Go back to the privious window
+ silent! wincmd p
+ " Indeed back to the editor window
+ call g:SrcExpl_WinPosAdapter()
+ endif
+ " Begin to tag the symbol
+ exe "silent " . "ptag " . s:SrcExpl_Symbol
+ catch
+ " Tag unsuccessfully
+ let s:SrcExpl_Status = 3
+ " Tell the Source Explorer window wyh
+ call <SID>SrcExpl_Report()
+ " Go back to the privious window again
+ silent! wincmd p
+ " Indeed back to the editor window
+ call g:SrcExpl_WinPosAdapter()
+ return
+ endtry
+ " Tag successfully and move to the preview window
+ silent! wincmd P
+ if &previewwindow
+ " Judge that if or not point to the definition
+ if (s:SrcExpl_FilePath == expand("%:p")) &&
+ \ (s:SrcExpl_CurrLine == line(".")) &&
+ \ (s:SrcExpl_CurrCol == col("."))
+ " Mulitple definition
+ let s:SrcExpl_Status = 2
+ call <SID>SrcExpl_Report()
+ else " Source Explorer Has pointed to the definition already
+ let s:SrcExpl_Status = 1
+ " Make the definition hightlight
+ call <SID>SrcExpl_MatchSymbol()
+ endif
+ " Go back to the privious window again
+ silent! wincmd p
+ " Indeed back to the editor window
+ call g:SrcExpl_WinPosAdapter()
+ endif
+
+endfunction
+
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" Go Back from the definition context.
+" Users can call this function using their mapping key.
+
function! g:SrcExpl_GoBack()
" Can not do this operation in Source Explorer
if (!&previewwindow)
@@ -67,7 +187,10 @@ function! g:SrcExpl_GoBack()
endif
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" Opreation when WinEnter Event happens
+
function! <SID>SrcExpl_WinEnter()
" In the Source Explorer
if &previewwindow
@@ -104,7 +227,10 @@ function! <SID>SrcExpl_WinEnter()
endif
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" Jump to the editor window and point to the definition
+
function! <SID>SrcExpl_Jump()
" Only do the operation on the Source Explorer
" window is valid
@@ -120,7 +246,7 @@ function! <SID>SrcExpl_Jump()
" Go back to the privious window
silent! wincmd p
" Indeed back to the editor window
- call <SID>SrcExpl_WinPosAdapter()
+ call g:SrcExpl_WinPosAdapter()
" We got Multiple definitions
if s:SrcExpl_Status == 2
" Use tag tool again to point to the definition
@@ -138,8 +264,10 @@ function! <SID>SrcExpl_Jump()
call cursor(s:SrcExpl_CurrLine, s:SrcExpl_CurrCol)
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Highlight the Symbol of definition
+
function! <SID>SrcExpl_MatchSymbol()
" First open the folding if exists
if has("folding")
@@ -160,7 +288,10 @@ function! <SID>SrcExpl_MatchSymbol()
let s:SrcExpl_CurrCol = col(".")
endfunction!
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" Report to the Source Explorer what happens
+
function! <SID>SrcExpl_Report()
" Do the Source Explorer exsited already?
let l:bufnum = bufnr(s:SrcExpl_Title)
@@ -194,7 +325,10 @@ function! <SID>SrcExpl_Report()
endif
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" Get key word symbol under the current cursor
+
function! <SID>SrcExpl_GetSymbol()
" Get the current charactor under the cursor
let l:cchar = getline('.')[col('.') - 1]
@@ -225,72 +359,10 @@ function! <SID>SrcExpl_GetSymbol()
return 0
endfunction
-" Refresh the Source Explorer window and update the status
-function! <SID>SrcExpl_Refresh()
- " Only Source Explorer window is valid
- if &previewwindow
- return
- endif
- " Get the symbol under the cursor
- let l:result = <SID>SrcExpl_GetSymbol()
- " The symbol is invalid
- if l:result != 0
- return
- endif
- " Explore the source code using tag tool
- " First Just try to get the definition of the symbol
- try
- " First move to the Source Explorer window
- silent! wincmd P
- if &previewwindow
- " Get the whole file path of the buffer before tag
- let s:SrcExpl_FilePath = expand("%:p")
- " Get the current line before tag
- let s:SrcExpl_CurrLine = line(".")
- " Get the current colum before tag
- let s:SrcExpl_CurrCol = col(".")
- " Go back to the privious window
- silent! wincmd p
- " Indeed back to the editor window
- call <SID>SrcExpl_WinPosAdapter()
- endif
- " Begin to tag the symbol
- exe "silent " . "ptag " . s:SrcExpl_Symbol
- catch
- " Tag unsuccessfully
- let s:SrcExpl_Status = 3
- " Tell the Source Explorer window wyh
- call <SID>SrcExpl_Report()
- " Go back to the privious window again
- silent! wincmd p
- " Indeed back to the editor window
- call <SID>SrcExpl_WinPosAdapter()
- return
- endtry
- " Tag successfully and move to the preview window
- silent! wincmd P
- if &previewwindow
- " Judge that if or not point to the definition
- if (s:SrcExpl_FilePath == expand("%:p")) &&
- \ (s:SrcExpl_CurrLine == line(".")) &&
- \ (s:SrcExpl_CurrCol == col("."))
- " Mulitple definition
- let s:SrcExpl_Status = 2
- call <SID>SrcExpl_Report()
- else " Source Explorer Has pointed to the definition already
- let s:SrcExpl_Status = 1
- " Make the definition hightlight
- call <SID>SrcExpl_MatchSymbol()
- endif
- " Go back to the privious window again
- silent! wincmd p
- " Indeed back to the editor window
- call <SID>SrcExpl_WinPosAdapter()
- endif
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-endfunction
+" Clean up the rubbish of plugin and free the mapping resouces
-" Unmap the mapping and unload the autocmd group
function! <SID>SrcExpl_Cleanup()
if has("gui_running")
" Delet the SrcExplGoBack item in Popup menu
@@ -304,6 +376,11 @@ function! <SID>SrcExpl_Cleanup()
unmap <silent> <CR>
endif
" Unmap the user's key
+ if maparg(g:SrcExpl_RefreshMapKey, 'n') ==
+ \ ":call g:SrcExpl_Refresh()<CR>"
+ exe "unmap " . g:SrcExpl_RefreshMapKey
+ endif
+ " Unmap the user's key
if maparg(g:SrcExpl_GoBackMapKey, 'n') ==
\ ":call g:SrcExpl_GoBack()<CR>"
exe "unmap " . g:SrcExpl_GoBackMapKey
@@ -312,14 +389,28 @@ function! <SID>SrcExpl_Cleanup()
silent! autocmd! SrcExpl_AutoCmd
endfunction
-" Get the plugin ID and load the autocmd group
-function! <SID>SrcExpl_Init()
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" Initialize the Souce Explorer proprities
+
+function! <SID>SrcExpl_Initialize()
+ " First set the height of preview window
+ exe "set previewheight=". string(g:SrcExpl_WinHeight)
+ " Set the actual update time according to user's requestion
+ " one second/times by default
+ exe "set updatetime=" . string(g:SrcExpl_RefreshTime * 1000)
" Map the user's key to go back from the
" definition context.
if g:SrcExpl_GoBackMapKey != ""
exe "nnoremap " . g:SrcExpl_GoBackMapKey .
\ " :call g:SrcExpl_GoBack()<CR>"
endif
+ " Map the user's key to refresh the definition
+ " updating manually.
+ if g:SrcExpl_RefreshMapKey != ""
+ exe "nnoremap " . g:SrcExpl_RefreshMapKey .
+ \ " :call g:SrcExpl_Refresh()<CR>"
+ endif
" First get the srcexpl.vim's ID
map <SID>xx <SID>xx
let s:SrcExpl_ScriptID = substitute(maparg('<SID>xx'),
@@ -329,14 +420,15 @@ function! <SID>SrcExpl_Init()
augroup SrcExpl_AutoCmd
" Delete the autocmd group first
autocmd!
- au! CursorHold * nested call <SID>SrcExpl_Refresh()
+ au! CursorHold * nested call g:SrcExpl_Refresh()
au! WinEnter * nested call <SID>SrcExpl_WinEnter()
augroup end
-
endfunction
-" Close the Source Explorer window
-" and delete its buffer
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" Close the Source Explorer window and delete its buffer
+
function! <SID>SrcExpl_CloseWin()
" Just close the preview window
pclose
@@ -349,11 +441,12 @@ function! <SID>SrcExpl_CloseWin()
endif
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
" Open the Source Explorer window under the bottom of (G)Vim,
" and set the buffer's proprity of the Source Explorer
+
function! <SID>SrcExpl_OpenWin()
- " First set the height of preview window
- exe "set previewheight=". string(g:SrcExpl_WinHeight)
" Open the Source Explorer window as the idle one
exe "silent! " . "pedit " . s:SrcExpl_Title
" Jump to the Source Explorer
@@ -374,30 +467,37 @@ function! <SID>SrcExpl_OpenWin()
" Go back to the privious window
silent! wincmd p
" Indeed back to the editor window
- call <SID>SrcExpl_WinPosAdapter()
+ call g:SrcExpl_WinPosAdapter()
endfunction
-" The User Interface function for open/close
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" The User Interface function for open / close
" the Source Explorer
+
function! <SID>SrcExpl_Toggle()
" Closed
if s:SrcExpl_Switch == 0
let s:SrcExpl_Switch = 1
+ " Initialize the proprities
+ call <SID>SrcExpl_Initialize()
" Open the window
call <SID>SrcExpl_OpenWin()
- " Initialize the buffer
- call <SID>SrcExpl_Init()
" Opened
else
- " Do the cleaning first
- call <SID>SrcExpl_Cleanup()
" Close the window
call <SID>SrcExpl_CloseWin()
+ " Do the cleaning work
+ call <SID>SrcExpl_Cleanup()
let s:SrcExpl_Switch = 0
endif
endfunction
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
set cpoptions&
let &cpoptions = s:save_cpo
unlet s:save_cpo
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
Please sign in to comment.
Something went wrong with that request. Please try again.