LDoc Lua , ,LDoc Github , vim , vim script, vim , , , 。 ldoc.vim ~/.vim/plugin : , , LdocM,LdocT,LdocF , , map
- vim script http://vimdoc.sourceforge.net/htmldoc/usr_41.html
- ldoc http://keplerproject.github.io/luadoc/manual.html
" http://vimdoc.sourceforge.net/htmldoc/usr_41.html
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
function! s:warnMsg(msg)
echohl WarningMsg
echo a:msg
echohl None
endfunction
"
if exists("loaded_ldoc_ddc")
call s:warnMsg("Ldoc Already Loaded!")
finish
endif
let loaded_ldoc_ddc = 1
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
if !exists("g:ldoc_startBeginCommentTag")
let g:ldoc_startBeginCommentTag = "----------------------------------------"
endif
if !exists("g:ldoc_startEndCommentTag")
let g:ldoc_startEndCommentTag = "----------------------------------------"
endif
if !exists("g:ldoc_startNoteCommentTag")
let g:ldoc_startNoteCommentTag = "--- "
endif
if !exists("g:ldoc_startFlagCommentTag")
let g:ldoc_startFlagCommentTag = "-- "
endif
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
if !exists("g:ldoc_flagAuthor")
let g:ldoc_flagAuthor = "@author "
endif
if !exists("g:ldoc_flagType")
let g:ldoc_flagType = "@type "
endif
if !exists("g:ldoc_flagParam")
let g:ldoc_flagParam = "@param "
endif
if !exists("g:ldoc_flagReturn")
let g:ldoc_flagReturn = "@return "
endif
"""""""""""""""""""""""""""""
"
" append , 2
"""""""""""""""""""""""""""""
function! s:writeToNextLine(str)
call append(line("."), a:str)
endfunction
function! s:writeToPrevLine(str)
call append(line(".")-1, a:str)
endfunction
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
function! <SID>ldoc_moduleComment()
if !exists("g:ldoc_authorName")
let g:ldoc_authorName = input(" ( ):")
endif
if(strlen(g:ldoc_authorName) == 0)
let l:whoami = system("whoami")
let g:ldoc_authorName = substitute(l:whoami, '
', "", "")
echo g:ldoc_authorName
endif
let l:moduleDesc = input(" ( , ):")
mark l
let l:writeText = [g:ldoc_startBeginCommentTag]
let l:markJump = 0
let l:str = g:ldoc_startNoteCommentTag
if(strlen(l:moduleDesc) == 0)
let l:markJump = 1
else
let l:str = l:str . l:moduleDesc
endif
call add(l:writeText, l:str)
call add(l:writeText, g:ldoc_startFlagCommentTag . g:ldoc_flagAuthor . g:ldoc_authorName)
call add(l:writeText, g:ldoc_startEndCommentTag)
call s:writeToPrevLine(l:writeText)
if(l:markJump == 1)
exec "normal " . (line(".") - len(l:writeText) + 1) . "G$"
else
exec "normal 'l"
endif
endfunction
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
function! <SID>ldoc_typeComment()
let l:curLineStr = getline(line("."))
let l:typeNameList = matchlist(l:curLineStr, 'local[ \t]\+\([a-zA-Z0-9_]\+\)[ \t]\+')
if(len(l:typeNameList) < 2)
call s:warnMsg(" type ,call [email protected]")
return
endif
let l:typeName = l:typeNameList[1]
let l:typeDesc = input(" ( , ):")
mark l
let l:writeText = []
let l:markJump = 0
let l:str = g:ldoc_startNoteCommentTag
if(strlen(l:typeDesc) == 0)
let l:markJump = 1
else
let l:str = l:str . l:typeDesc
endif
call add(l:writeText, l:str)
call add(l:writeText, g:ldoc_startFlagCommentTag . g:ldoc_flagType . l:typeName)
call s:writeToPrevLine(l:writeText)
if(l:markJump == 1)
exec "normal " . (line(".") - len(l:writeText)) . "G$"
else
exec "normal 'l"
endif
endfunction
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
function! <SID>ldoc_functionComment()
let l:curLineStr = getline(line("."))
let l:paramList = matchlist(l:curLineStr, 'function[ \t]\+\([a-zA-Z0-9_.:]\+\)[ \t]*(\([a-zA-Z0-9_, \t\.]*\))')
if(len(l:paramList) >= 2)
else
let l:paramList = matchlist(l:curLineStr, '\([a-zA-Z0-9_]\+\)[ \t]*=[ \t]*function[ \t]*(\([a-zA-Z0-9_, \t\.]*\))')
if(len(l:paramList) < 2)
call s:warnMsg(" ,call [email protected]")
return
endif
endif
let l:funcName = l:paramList[1]
if(len(l:paramList) > 3)
let l:paramList = split(l:paramList[2], '[ \t]*,[ \t]*')
let l:paramList2 = []
for l:ele in l:paramList
call add(l:paramList2, substitute(l:ele, '[ \t]+', "", ""))
endfor
endif
mark l
let l:funcDesc = input(" [" . l:funcName . "] ( , ):")
let l:writeText = []
let l:str = g:ldoc_startNoteCommentTag
let l:markJump = 0
if(strlen(l:funcDesc) == 0)
let l:markJump = 1
else
let l:str = l:str . l:funcDesc
endif
call add(l:writeText, l:str)
for l:ele in l:paramList2
let l:str = g:ldoc_startFlagCommentTag . g:ldoc_flagParam . l:ele
let l:paramDesc = input(" [" . l:ele . "] :")
if(strlen(l:paramDesc) > 0)
let l:str = l:str . "\t" . l:paramDesc
endif
call add(l:writeText, l:str)
endfor
call s:writeToPrevLine(l:writeText)
if(l:markJump == 1)
exec "normal " . (line(".") - len(l:writeText)) . "G$"
else
exec "normal 'l"
endif
endfunction
"""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""
command! -nargs=0 LdocM :call <SID>ldoc_moduleComment()
command! -nargs=0 LdocT :call <SID>ldoc_typeComment()
command! -nargs=0 LdocF :call <SID>ldoc_functionComment()