Skip to content

Commit a34cdc6

Browse files
committed
Merge branch 'fix_nested_indent'
2 parents 1d0abf8 + 7376911 commit a34cdc6

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 0.0.7
2+
-------------
3+
Released on June 1th 2016
4+
5+
- add ``_nested_indent_`` template variable.
6+
see https://github.com/heavenshell/vim-pydocstring/issues/3#issuecomment-222584162
7+
Thx @pirDOL
8+
19
Version 0.0.6
210
-------------
311
Released on January 17th 2016

autoload/pydocstring.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Insert Docstring.
22
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3-
" Version: 0.0.6
3+
" Version: 0.0.7
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.
@@ -76,7 +76,7 @@ function! s:readoneline(indent, prefix)
7676
return tmpl
7777
endfunction
7878

79-
function! s:builddocstring(strs, indent)
79+
function! s:builddocstring(strs, indent, nested_indent)
8080
let type = a:strs['type']
8181
let prefix = a:strs['header']
8282
let args = a:strs['args']
@@ -108,6 +108,7 @@ function! s:builddocstring(strs, indent)
108108
let arg = substitute(line, '{{_arg_}}', arg, 'g')
109109
let arg = substitute(arg, '{{_lf_}}', "\n", '')
110110
let arg = substitute(arg, '{{_indent_}}', a:indent, 'g')
111+
let arg = substitute(arg, '{{_nested_indent_}}', a:nested_indent, 'g')
111112
call add(docstrings, a:indent . arg)
112113
endfor
113114
elseif line =~ '{{_indent_}}'
@@ -165,13 +166,15 @@ function! pydocstring#insert()
165166
call s:insert(startpos, indent . tmpl)
166167
endif
167168
else
169+
let space = repeat(' ', &softtabstop)
170+
let nested_indent = space
168171
if len(indent) == 0
169-
let indent = repeat(' ', &softtabstop)
172+
let indent = space
170173
else
171-
let indent = indent . repeat(' ', &softtabstop)
174+
let indent = indent . space
172175
endif
173176
try
174-
let result = s:builddocstring(docstring, indent)
177+
let result = s:builddocstring(docstring, indent, nested_indent)
175178
call s:insert(insertpos + 1, result)
176179
catch /^Template/
177180
echomsg v:exception

doc/pydocstring.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Template variables.
139139
|{{_arg_}}| Assign function or method's argument.
140140
|{{_ln_}}| Assign line break.
141141
|{{_indent_}}| Assign indent.
142+
|{{_nested_indent_}}| Assign indent.
142143

143144
==============================================================================
144145
VARIABLES *pydocstring-vim-variables*
@@ -199,6 +200,33 @@ Numpy style docstring template example.
199200
"""
200201
pass
201202
203+
Nested indent example.
204+
205+
Add following template to multi.txt
206+
>
207+
"""{{_header_}}
208+
209+
{{_indent_}}Args:
210+
{{_nested_indent_}}{{_arg_}}:
211+
"""
212+
<
213+
Set cursor on `def arg1` line and type following.
214+
>
215+
:Pydocstring
216+
<
217+
Then docstring put under `def` line.
218+
>
219+
class Foo(object):
220+
def foo(self, arg1, arg2):
221+
"""foo
222+
223+
Args:
224+
arg1:
225+
arg2:
226+
"""
227+
pass
228+
<
229+
202230
Override default mapping.
203231

204232
Add following setting to your .vimrc or _vimrc.

ftplugin/python/pydocstring.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" File: pydocstring.vim
22
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3-
" Version: 0.0.6
3+
" Version: 0.0.7
44
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
55
" Description: Generate Python docstring to your Python script file.
66
" License: BSD, see LICENSE for more details.

0 commit comments

Comments
 (0)