Created
October 17, 2012 04:54
-
-
Save sunvisor/3903772 to your computer and use it in GitHub Desktop.
insert jsdoc style comment. (vim function)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" JSDoc形式のコメントを追加(functionの行で実行する) | |
" hogeFunc: function() の形式と function hogeFunc() に対応 | |
" 関数定義でない場合は、コメントだけ出力する | |
function! AddJSDoc() | |
let l:jsDocregex = '\s*\([a-zA-Z]*\)\s*[:=]\s*function\s*(\s*\(.*\)\s*).*' | |
let l:jsDocregex2 = '\s*function \([a-zA-Z]*\)\s*(\s*\(.*\)\s*).*' | |
let l:line = getline('.') | |
let l:indent = indent('.') | |
let l:space = repeat(" ", l:indent) | |
if l:line =~ l:jsDocregex | |
let l:flag = 1 | |
let l:regex = l:jsDocregex | |
elseif l:line =~ l:jsDocregex2 | |
let l:flag = 1 | |
let l:regex = l:jsDocregex2 | |
else | |
let l:flag = 0 | |
endif | |
let l:lines = [] | |
let l:desc = input('Description :') | |
call add(l:lines, l:space. '/**') | |
call add(l:lines, l:space . ' * ' . l:desc) | |
if l:flag | |
let l:funcName = substitute(l:line, l:regex, '\1', "g") | |
let l:arg = substitute(l:line, l:regex, '\2', "g") | |
let l:args = split(l:arg, '\s*,\s*') | |
call add(l:lines, l:space . ' * @name ' . l:funcName) | |
call add(l:lines, l:space . ' * @function') | |
for l:arg in l:args | |
call add(l:lines, l:space . ' * @param ' . l:arg) | |
endfor | |
endif | |
call add(l:lines, l:space . ' */') | |
call append(line('.')-1, l:lines) | |
endfunction | |
" JSDocのキーバインド | |
nmap ,d :<C-u>call AddJSDoc()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment