1
1
" Insert Docstring.
2
2
" Author: Shinya Ohyanagi <[email protected] >
3
- " Version: 0.1.6
3
+ " Version: 0.2.0
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.
@@ -149,10 +149,6 @@ function! s:builddocstring(strs, indent, nested_indent)
149
149
let tmpl = ' '
150
150
let docstrings = []
151
151
let lines = s: readtmpl (' multi' )
152
- let has_return_type = 0
153
- if match (lines , ' \c{{_returnType_}}\|\c{{_return_type_}}' ) != -1
154
- let has_return_type = 1
155
- endif
156
152
for line in lines
157
153
if line = ~ ' {{_header_}}'
158
154
let header = substitute (line , ' {{_header_}}' , prefix, ' ' )
@@ -167,10 +163,10 @@ function! s:builddocstring(strs, indent, nested_indent)
167
163
let template = line
168
164
let typed = 0
169
165
if match (arg, ' :' ) != -1
170
- let argTemplate = join (s: readtmpl (' arg' ), ' ' )
171
- let argParts = split (arg, ' :' )
172
- let argTemplate = substitute (argTemplate , ' {{_name_}}' , argParts [0 ], ' g' )
173
- let arg = substitute (argTemplate , ' {{_type_}}' , argParts [1 ], ' g' )
166
+ let arg_template = join (s: readtmpl (' arg' ), ' ' )
167
+ let arg_parts = split (arg, ' :' )
168
+ let arg_template = substitute (arg_template , ' {{_name_}}' , arg_parts [0 ], ' g' )
169
+ let arg = substitute (arg_template , ' {{_type_}}' , arg_parts [1 ], ' g' )
174
170
let typed = 1
175
171
endif
176
172
let template = substitute (template, ' {{_args_}}' , arg, ' g' )
@@ -196,9 +192,6 @@ function! s:builddocstring(strs, indent, nested_indent)
196
192
let template = substitute (template, ' \s$' , ' ' , ' ' )
197
193
call add (docstrings, a: indent . template)
198
194
endfor
199
- if has_return_type == 1
200
- call add (docstrings, ' ' )
201
- endif
202
195
endif
203
196
elseif line = ~ ' {{_indent_}}'
204
197
let arg = substitute (line , ' {{_indent_}}' , a: indent , ' g' )
@@ -208,7 +201,9 @@ function! s:builddocstring(strs, indent, nested_indent)
208
201
let rt = substitute (line , ' {{_returnType_}}\|{{_return_type_}}' , return_type, ' ' )
209
202
call add (docstrings, a: indent . rt)
210
203
else
211
- call remove (docstrings, -1 )
204
+ if docstrings[-1 ] == ' '
205
+ call remove (docstrings, -1 )
206
+ endif
212
207
endif
213
208
elseif line == ' """' || line == " '''"
214
209
call add (docstrings, a: indent . line )
0 commit comments