11" Insert Docstring.
22" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3- " Version: 0.0.4
3+ " Version: 0.0.5
44" License: This file is placed in the public domain.
55" WebPage: http://github.com/heavenshell/vim-pydocstriong/
66" Description: Generate Python docstring to your Python script file.
@@ -24,6 +24,12 @@ if !exists('g:pydocstring_ignore_args_pattern')
2424 let g: pydocstring_ignore_args_pattern = ' self\|cls'
2525endif
2626
27+ let s: regexs = {
28+ \ ' def' : ' ^def\s\|^\s*def\s' ,
29+ \ ' class' : ' ^class\s\|^\s*class\s' ,
30+ \ ' async' : ' ^async\s*def\s\|^\s*async\sdef\s'
31+ \ }
32+
2733function ! s: readtmpl (type )
2834 let path = s: tmpldir . a: type . ' .txt'
2935 if ! filereadable (path )
@@ -36,14 +42,14 @@ endfunction
3642function ! s: parse (line )
3743 let str = substitute (a: line , ' \\' , ' ' , ' g' )
3844 let type = ' '
39- if str = ~ ' ^ def\s\|^\s*def\s '
40- let str = substitute (str, ' ^ def\s\|^\s*def\s ' , ' ' , ' ' )
45+ if str = ~ s: regexs [ ' def' ]
46+ let str = substitute (str, s: regexs [ ' def' ] , ' ' , ' ' )
4147 let type = ' def'
42- elseif str = ~ ' ^ async\s*def\s\|^\s*async\sdef\s '
43- let str = substitute (str, ' ^ async\sdef\s\|^\s*async\sdef\s ' , ' ' , ' ' )
48+ elseif str = ~ s: regexs [ ' async' ]
49+ let str = substitute (str, s: regexs [ ' async' ] , ' ' , ' ' )
4450 let type = ' def'
45- elseif str = ~ ' ^ class\s\|^\s*class\s '
46- let str = substitute (str, ' ^ class\s\|^\s*class\s ' , ' ' , ' ' )
51+ elseif str = ~ s: regexs [ ' class' ]
52+ let str = substitute (str, s: regexs [ ' class' ] , ' ' , ' ' )
4753 let type = ' class'
4854 else
4955 return 0
0 commit comments