Vim插件生成Javascript文档注释 [英] Vim plugin to generate Javascript Documentation comments
本文介绍了Vim插件生成Javascript文档注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个vim的插件,有点像Jsbeautify,它自动生成JavaDoc,如脚本文件中的注释。
Is there a plugin for vim, somewhat like Jsbeautify, which automatically generates JavaDoc like comments in the script files.
例如,它将采用
function(a , b , c){
}
并返回
/**
* Description.
*
* @param a Description.
* @param b Description.
* @param c Description.
*/
function(a , b , c){
}
推荐答案
这里有一些东西让你开始 - 根据需要调整 - )
Here's a little something to get you started - tweak as required!-)
" generate doc comment template
map <LocalLeader>/ :call GenerateDOCComment()<cr>
function! GenerateDOCComment()
let l = line('.')
let i = indent(l)
let pre = repeat(' ',i)
let text = getline(l)
let params = matchstr(text,'([^)]*)')
let paramPat = '\([$a-zA-Z_0-9]\+\)[, ]*\(.*\)'
echomsg params
let vars = []
let m = ' '
let ml = matchlist(params,paramPat)
while ml!=[]
let [_,var;rest]= ml
let vars += [pre.' * @param '.var]
let ml = matchlist(rest,paramPat,0)
endwhile
let comment = [pre.'/**',pre.' * '] + vars + [pre.' */']
call append(l-1,comment)
call cursor(l+1,i+3)
endfunction
假设参数列表在一行,它尝试匹配参数,建立一个注释字符串,并将该注释字符串附加到函数头之前的行。
Assuming the parameter list is on one line, it tries to match out the parameters, builds up a comment string, and appends that comment string to the line before the function header.
这篇关于Vim插件生成Javascript文档注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文