[vim] update echofunc plugin
This commit is contained in:
parent
5430a53e4a
commit
be6b68af9c
@ -6,8 +6,8 @@
|
|||||||
" supports.
|
" supports.
|
||||||
" Authors: Ming Bai <mbbill AT gmail DOT com>,
|
" Authors: Ming Bai <mbbill AT gmail DOT com>,
|
||||||
" Wu Yongwei <wuyongwei AT gmail DOT com>
|
" Wu Yongwei <wuyongwei AT gmail DOT com>
|
||||||
" Last Change: 2009-04-30 21:17:26
|
" Last Change: 2011-06-22 16:34:01
|
||||||
" Version: 1.19
|
" Version: 1.3
|
||||||
"
|
"
|
||||||
" Install: 1. Put echofunc.vim to /plugin directory.
|
" Install: 1. Put echofunc.vim to /plugin directory.
|
||||||
" 2. Use the command below to create tags
|
" 2. Use the command below to create tags
|
||||||
@ -28,26 +28,67 @@
|
|||||||
" macro name, etc. This works with when
|
" macro name, etc. This works with when
|
||||||
" +balloon_eval is compiled in.
|
" +balloon_eval is compiled in.
|
||||||
"
|
"
|
||||||
|
" Because the message line often cleared by
|
||||||
|
" some other plugins (e.g. ominicomplete), an
|
||||||
|
" other choice is to show message in status line.
|
||||||
|
" First, add %{EchoFuncGetStatusLine()} to
|
||||||
|
" your 'statusline' option.
|
||||||
|
" Second, add the following line to your vimrc
|
||||||
|
" let g:EchoFuncShowOnStatus = 1
|
||||||
|
" to avoid echoing function name in message line.
|
||||||
|
"
|
||||||
" Options: g:EchoFuncLangsDict
|
" Options: g:EchoFuncLangsDict
|
||||||
" Dictionary to map the Vim file types to
|
" Dictionary to map the Vim file types to
|
||||||
" tags languages that should be used. You do
|
" tags languages that should be used. You do
|
||||||
" not need to touch it in most cases.
|
" not need to touch it in most cases.
|
||||||
|
"
|
||||||
" g:EchoFuncLangsUsed
|
" g:EchoFuncLangsUsed
|
||||||
" File types to enable echofunc, in case you
|
" File types to enable echofunc, in case you
|
||||||
" do not want to use EchoFunc on all file
|
" do not want to use EchoFunc on all file
|
||||||
" types supported. Example:
|
" types supported. Example:
|
||||||
" let g:EchoFuncLangsUsed = ["java","cpp"]
|
" let g:EchoFuncLangsUsed = ["java","cpp"]
|
||||||
|
"
|
||||||
" g:EchoFuncMaxBalloonDeclarations
|
" g:EchoFuncMaxBalloonDeclarations
|
||||||
" Maximum lines to display in balloon declarations.
|
" Maximum lines to display in balloon declarations.
|
||||||
" g:EchoFuncKeyNext
|
|
||||||
" Key to echo the next function
|
|
||||||
" g:EchoFuncKeyPrev
|
|
||||||
" Key to echo the previous function
|
|
||||||
"
|
"
|
||||||
" Thanks: edyfox minux
|
" g:EchoFuncKeyNext
|
||||||
|
" Key to echo the next function.
|
||||||
|
"
|
||||||
|
" g:EchoFuncKeyPrev
|
||||||
|
" Key to echo the previous function.
|
||||||
|
"
|
||||||
|
" g:EchoFuncShowOnStatus
|
||||||
|
" Show function name on status line. NOTE,
|
||||||
|
" you should manually add %{EchoFuncGetStatusLine()}
|
||||||
|
" to your 'statusline' option.
|
||||||
|
"
|
||||||
|
" g:EchoFuncAutoStartBalloonDeclaration
|
||||||
|
" Automatically start balloon declaration if not 0.
|
||||||
|
"
|
||||||
|
" g:EchoFuncPathMappingEnabled
|
||||||
|
" g:EchoFuncPathMapping
|
||||||
|
" The new feature added by Zhao Cai provides ability
|
||||||
|
" to shorten file path in some specific directory. e.g.
|
||||||
|
" /home/username/veryveryvery/long/file/path/blabla
|
||||||
|
" could be showed as
|
||||||
|
" ~/veryveryvery/long/file/path/blabla
|
||||||
|
" If you want to disable this feature, add
|
||||||
|
" let g:EchoFuncPathMappingEnabled = 0
|
||||||
|
" to your vimrc. It's enabled by default.
|
||||||
|
" To add more mappings in g:EchoFuncPathMapping, search
|
||||||
|
" this script and you will know how to do it.
|
||||||
|
"
|
||||||
|
"
|
||||||
|
" Thanks: edyfox
|
||||||
|
" minux
|
||||||
|
" Zhao Cai
|
||||||
"
|
"
|
||||||
"==================================================
|
"==================================================
|
||||||
|
|
||||||
|
if &compatible == 1
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
" Vim version 7.x is needed.
|
" Vim version 7.x is needed.
|
||||||
if v:version < 700
|
if v:version < 700
|
||||||
echohl ErrorMsg | echomsg "Echofunc.vim needs vim version >= 7.0!" | echohl None
|
echohl ErrorMsg | echomsg "Echofunc.vim needs vim version >= 7.0!" | echohl None
|
||||||
@ -57,10 +98,46 @@ endif
|
|||||||
let s:res=[]
|
let s:res=[]
|
||||||
let s:count=1
|
let s:count=1
|
||||||
|
|
||||||
|
if !exists("g:EchoFuncPathMapping")
|
||||||
|
" Note: longest match first
|
||||||
|
let g:EchoFuncPathMapping = [
|
||||||
|
\ [expand("$HOME") , '~'],
|
||||||
|
\ [expand("$VIM") , '$VIM']
|
||||||
|
\]
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("g:EchoFuncPathMappingEnabled")
|
||||||
|
let g:EchoFuncPathMappingEnabled = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
func! s:EchoFuncPathMapping(path)
|
||||||
|
if g:EchoFuncPathMappingEnabled != 1
|
||||||
|
return a:path
|
||||||
|
endif
|
||||||
|
let l:path = a:path
|
||||||
|
for item in g:EchoFuncPathMapping
|
||||||
|
"let l:path = substitute(l:path, escape(item[0],'/'), escape(item[1],'/'), 'ge' )
|
||||||
|
let l:path = substitute(l:path, '\V'.escape(item[0],'\'), item[1], 'ge' )
|
||||||
|
endfor
|
||||||
|
return l:path
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! EchoFuncGetStatusLine()
|
||||||
|
if len(s:res) == 0
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
return '[' . substitute(s:res[s:count-1],'^\s*','','') . ']'
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:EchoFuncDisplay()
|
function! s:EchoFuncDisplay()
|
||||||
if len(s:res) == 0
|
if len(s:res) == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
if g:EchoFuncShowOnStatus == 1
|
||||||
|
exec "redrawstatus"
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
set noshowmode
|
set noshowmode
|
||||||
let content=s:res[s:count-1]
|
let content=s:res[s:count-1]
|
||||||
let wincols=&columns
|
let wincols=&columns
|
||||||
@ -80,12 +157,35 @@ function! s:EchoFuncDisplay()
|
|||||||
echohl Type | echo content | echohl None
|
echohl Type | echo content | echohl None
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" add this function to avoid E432
|
||||||
|
function! s:CallTagList(str)
|
||||||
|
let ftags = []
|
||||||
|
try
|
||||||
|
let ftags=taglist(a:str)
|
||||||
|
catch /^Vim\%((\a\+)\)\=:E/
|
||||||
|
" if error occured, reset tagbsearch option and try again.
|
||||||
|
let bak=&tagbsearch
|
||||||
|
set notagbsearch
|
||||||
|
let ftags=taglist(a:str)
|
||||||
|
let &tagbsearch=bak
|
||||||
|
endtry
|
||||||
|
return ftags
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:GetFunctions(fun, fn_only)
|
function! s:GetFunctions(fun, fn_only)
|
||||||
let s:res=[]
|
let s:res=[]
|
||||||
let ftags=taglist('^'.escape(a:fun,'[\*~^').'$')
|
let funpat=escape(a:fun,'[\*~^')
|
||||||
|
let ftags=s:CallTagList('^'.funpat.'$')
|
||||||
|
|
||||||
|
if (type(ftags)==type(0) || ((type(ftags)==type([])) && ftags==[]))
|
||||||
|
if &filetype=='cpp' && funpat!~'^\(catch\|if\|for\|while\|switch\)$'
|
||||||
|
" Namespaces may be omitted
|
||||||
|
let ftags=s:CallTagList('::'.funpat.'$')
|
||||||
if (type(ftags)==type(0) || ((type(ftags)==type([])) && ftags==[]))
|
if (type(ftags)==type(0) || ((type(ftags)==type([])) && ftags==[]))
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
let fil_tag=[]
|
let fil_tag=[]
|
||||||
for i in ftags
|
for i in ftags
|
||||||
if !has_key(i,'name')
|
if !has_key(i,'name')
|
||||||
@ -105,9 +205,12 @@ function! s:GetFunctions(fun, fn_only)
|
|||||||
if (!a:fn_only || (i.kind=='p' || i.kind=='f') ||
|
if (!a:fn_only || (i.kind=='p' || i.kind=='f') ||
|
||||||
\(i.kind == 'm' && has_key(i,'cmd') &&
|
\(i.kind == 'm' && has_key(i,'cmd') &&
|
||||||
\ match(i.cmd,'(') != -1)) &&
|
\ match(i.cmd,'(') != -1)) &&
|
||||||
\i.name==a:fun
|
\i.name=~funpat
|
||||||
|
if &filetype!='cpp' || !has_key(i,'class') ||
|
||||||
|
\i.name!~'::' || i.name=~i.class
|
||||||
let fil_tag+=[i]
|
let fil_tag+=[i]
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
if !a:fn_only && i.name == a:fun
|
if !a:fn_only && i.name == a:fun
|
||||||
let fil_tag+=[i]
|
let fil_tag+=[i]
|
||||||
@ -120,11 +223,12 @@ function! s:GetFunctions(fun, fn_only)
|
|||||||
let s:count=1
|
let s:count=1
|
||||||
for i in fil_tag
|
for i in fil_tag
|
||||||
if has_key(i,'kind') && has_key(i,'name') && has_key(i,'signature')
|
if has_key(i,'kind') && has_key(i,'name') && has_key(i,'signature')
|
||||||
let tmppat=escape(i.name,'[\*~^')
|
let tmppat=substitute(escape(i.name,'[\*~^'),'^.*::','','')
|
||||||
if &filetype == 'cpp'
|
if &filetype == 'cpp'
|
||||||
let tmppat=substitute(tmppat,'\<operator ','operator\\s*','')
|
let tmppat=substitute(tmppat,'\<operator ','operator\\s*','')
|
||||||
let tmppat=substitute(tmppat,'^\(.*::\)','\\(\1\\)\\?','')
|
"let tmppat=substitute(tmppat,'^\(.*::\)','\\(\1\\)\\?','')
|
||||||
let tmppat=tmppat . '\s*(.*'
|
let tmppat=tmppat . '\s*(.*'
|
||||||
|
let tmppat='\([A-Za-z_][A-Za-z_0-9]*::\)*'.tmppat
|
||||||
else
|
else
|
||||||
let tmppat=tmppat . '\>.*'
|
let tmppat=tmppat . '\>.*'
|
||||||
endif
|
endif
|
||||||
@ -187,7 +291,7 @@ function! s:GetFunctions(fun, fn_only)
|
|||||||
let name=substitute(name,'^\s\+','','')
|
let name=substitute(name,'^\s\+','','')
|
||||||
let name=substitute(name,'\s\+$','','')
|
let name=substitute(name,'\s\+$','','')
|
||||||
let name=substitute(name,'\s\+',' ','g')
|
let name=substitute(name,'\s\+',' ','g')
|
||||||
let file_line=i.filename
|
let file_line=s:EchoFuncPathMapping(i.filename)
|
||||||
if i.cmd > 0
|
if i.cmd > 0
|
||||||
let file_line=file_line . ':' . i.cmd
|
let file_line=file_line . ':' . i.cmd
|
||||||
endif
|
endif
|
||||||
@ -258,6 +362,7 @@ endfunction
|
|||||||
|
|
||||||
function! EchoFuncClear()
|
function! EchoFuncClear()
|
||||||
echo ''
|
echo ''
|
||||||
|
let s:res=[]
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -374,12 +479,28 @@ if !exists("g:EchoFuncMaxBalloonDeclarations")
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:EchoFuncKeyNext")
|
if !exists("g:EchoFuncKeyNext")
|
||||||
|
if has ("mac")
|
||||||
|
let g:EchoFuncKeyNext='≠'
|
||||||
|
else
|
||||||
let g:EchoFuncKeyNext='<M-=>'
|
let g:EchoFuncKeyNext='<M-=>'
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
if !exists("g:EchoFuncKeyPrev")
|
if !exists("g:EchoFuncKeyPrev")
|
||||||
|
if has ("mac")
|
||||||
|
let g:EchoFuncKeyPrev='±'
|
||||||
|
else
|
||||||
let g:EchoFuncKeyPrev='<M-->'
|
let g:EchoFuncKeyPrev='<M-->'
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("g:EchoFuncShowOnStatus")
|
||||||
|
let g:EchoFuncShowOnStatus = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("g:EchoFuncAutoStartBalloonDeclaration")
|
||||||
|
let g:EchoFuncAutoStartBalloonDeclaration = 1
|
||||||
|
endif
|
||||||
|
|
||||||
function! s:CheckTagsLanguage(filetype)
|
function! s:CheckTagsLanguage(filetype)
|
||||||
return index(g:EchoFuncLangsUsed, a:filetype) != -1
|
return index(g:EchoFuncLangsUsed, a:filetype) != -1
|
||||||
@ -392,7 +513,7 @@ function! CheckedEchoFuncStart()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! CheckedBalloonDeclarationStart()
|
function! CheckedBalloonDeclarationStart()
|
||||||
if s:CheckTagsLanguage(&filetype)
|
if s:CheckTagsLanguage(&filetype) && g:EchoFuncAutoStartBalloonDeclaration
|
||||||
call BalloonDeclarationStart()
|
call BalloonDeclarationStart()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user