1
1
" Insert Docstring.
2
2
" Author: Shinya Ohyanagi <[email protected] >
3
- " Version: 0.1.5
3
+ " Version: 0.1.6
4
4
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
5
5
" Description: Generate Python docstring to your Python script file.
6
6
" License: BSD, see LICENSE for more details.
@@ -48,26 +48,26 @@ function! s:parseClass(line)
48
48
" do that by just delete every white spaces and the whole parenthesics if
49
49
" existed.
50
50
let header = substitute (a: line , ' \s\|(.*\|:' , ' ' , ' g' )
51
- let parse = {' type' : ' class' , ' header' : header, ' args' : ' ' , ' returnType ' : ' ' }
51
+ let parse = {' type' : ' class' , ' header' : header, ' args' : ' ' , ' return_type ' : ' ' }
52
52
return parse
53
53
endfunction
54
54
55
- function ! s: parseFunc (type , line )
55
+ function ! s: parse_func (type , line )
56
56
let header = substitute (a: line , ' \s\|(.*\|:' , ' ' , ' g' )
57
57
58
- let argsStr = substitute (a: line , ' \s\|.*(\|).*' , ' ' , ' g' )
59
- let args = split (argsStr , ' ,' )
58
+ let args_str = substitute (a: line , ' \s\|.*(\|).*' , ' ' , ' g' )
59
+ let args = split (args_str , ' ,' )
60
60
61
- let arrowIndex = match (a: line , " ->" )
62
- if arrowIndex != -1
63
- let substring = strpart (a: line , arrowIndex + 2 )
61
+ let arrow_index = match (a: line , " ->" )
62
+ if arrow_index != -1
63
+ let substring = strpart (a: line , arrow_index + 2 )
64
64
" issue #28 `\W*` would deleted `.`.
65
- let returnType = substitute (substring, ' [^0-9A-Za-z_.]*' , ' ' , ' g' )
65
+ let return_type = substitute (substring, ' [^0-9A-Za-z_.]*' , ' ' , ' g' )
66
66
else
67
- let returnType = ' '
67
+ let return_type = ' '
68
68
endif
69
69
70
- let parse = {' type' : a: type , ' header' : header, ' args' : args , ' returnType ' : returnType }
70
+ let parse = {' type' : a: type , ' header' : header, ' args' : args , ' return_type ' : return_type }
71
71
return parse
72
72
endfunction
73
73
@@ -90,7 +90,7 @@ function! s:parse(line)
90
90
return 0
91
91
endif
92
92
93
- return s: parseFunc (type , str)
93
+ return s: parse_func (type , str)
94
94
endfunction
95
95
96
96
" Vim Script does not support lambda function...
@@ -104,7 +104,7 @@ endfunction
104
104
" Check if we should show args in the docstring. We won't do that in case:
105
105
" - There's no args.
106
106
" - There's only one arg that match with g:pydocstring_ignore_args_pattern
107
- function ! s: shouldIncludeArgs (args )
107
+ function ! s: should_include_args (args )
108
108
if len (a: args ) == 0
109
109
return 0
110
110
endif
@@ -124,33 +124,33 @@ endfunction
124
124
" g:pydocstring_ignore_args_pattern
125
125
"
126
126
" Return 1 for True, and 0 for False
127
- function ! s: shouldUseOneLineDocString (type , args , returnType )
127
+ function ! s: should_use_one_line_docstring (type , args , return_type )
128
128
if a: type != ' def'
129
129
return 1
130
130
endif
131
131
132
- if a: returnType != ' '
132
+ if a: return_type != ' '
133
133
return 0
134
134
endif
135
135
136
- return ! s: shouldIncludeArgs (a: args )
136
+ return ! s: should_include_args (a: args )
137
137
endfunction
138
138
139
139
function ! s: builddocstring (strs, indent , nested_indent)
140
140
let type = a: strs [' type' ]
141
141
let prefix = a: strs [' header' ]
142
142
let args = a: strs [' args' ]
143
- let returnType = a: strs [' returnType ' ]
143
+ let return_type = a: strs [' return_type ' ]
144
144
145
- if s: shouldUseOneLineDocString (type , args , returnType )
145
+ if s: should_use_one_line_docstring (type , args , return_type )
146
146
return s: readoneline (a: indent , prefix)
147
147
endif
148
148
149
149
let tmpl = ' '
150
150
let docstrings = []
151
151
let lines = s: readtmpl (' multi' )
152
152
let has_return_type = 0
153
- if match (lines , ' \c{{_returnType_}}' ) != -1
153
+ if match (lines , ' \c{{_returnType_}}\|\c{{_return_type_}} ' ) != -1
154
154
let has_return_type = 1
155
155
endif
156
156
for line in lines
@@ -186,7 +186,7 @@ function! s:builddocstring(strs, indent, nested_indent)
186
186
" '''
187
187
" {{_header_}}
188
188
" :param {{_args_}}:
189
- " :rtype: {{_returnType_ }}
189
+ " :rtype: {{_return_type_ }}
190
190
" '''
191
191
let template = substitute (template, ' :$' , ' ' , ' g' )
192
192
endif
@@ -203,9 +203,9 @@ function! s:builddocstring(strs, indent, nested_indent)
203
203
elseif line = ~ ' {{_indent_}}'
204
204
let arg = substitute (line , ' {{_indent_}}' , a: indent , ' g' )
205
205
call add (docstrings, arg)
206
- elseif line = ~ ' {{_returnType_}}'
207
- if strlen (returnType ) != 0
208
- let rt = substitute (line , ' {{_returnType_}}' , returnType , ' ' )
206
+ elseif line = ~ ' {{_returnType_}}\|{{_return_type_}} '
207
+ if strlen (return_type ) != 0
208
+ let rt = substitute (line , ' {{_returnType_}}\|{{_return_type_}} ' , return_type , ' ' )
209
209
call add (docstrings, a: indent . rt)
210
210
else
211
211
call remove (docstrings, -1 )
0 commit comments