Skip to content

Commit f028b57

Browse files
authored
Merge pull request #110 from brentyi/master
Add support for smarttab / shiftwidth
2 parents 99efe11 + a3eec15 commit f028b57

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

README.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ type `:PydocstringFormat` will insert all docstrings to current buffer.
6969

7070
Settings
7171
--------
72-
Pydocstring depends on ``softtabstop``.
73-
You need to set like ``set softtabstop=4``.
72+
Pydocstring depends on ``shiftwidth`` if ``smarttab`` is set, otherwise
73+
``softtabstop``. For the latter, you need to set like ``set softtabstop=4``.
7474

7575
Example ``.vimrc``
7676

77+
.. code::
78+
79+
autocmd FileType python setlocal tabstop=4 shiftwidth=4 smarttab expandtab
80+
81+
Or:
82+
7783
.. code::
7884
7985
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab

autoload/pydocstring.vim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ let g:pydocstring_doq_path = get(
1818

1919
let s:results = []
2020

21+
function! s:get_indent_width() abort
22+
" Get indentation width
23+
return &smarttab ? &shiftwidth : &softtabstop
24+
endfunction
25+
2126
function! s:get_range() abort
2227
" Get visual mode selection.
2328
let mode = visualmode(1)
@@ -147,7 +152,7 @@ function! s:create_cmd(style, omissions) abort
147152
\ expand(g:pydocstring_doq_path),
148153
\ a:style,
149154
\ g:pydocstring_formatter,
150-
\ &softtabstop
155+
\ s:get_indent_width()
151156
\ )
152157
else
153158
let cmd = printf(
@@ -156,7 +161,7 @@ function! s:create_cmd(style, omissions) abort
156161
\ a:style,
157162
\ g:pydocstring_formatter,
158163
\ a:omissions,
159-
\ &softtabstop
164+
\ s:get_indent_width()
160165
\ )
161166
endif
162167
if g:pydocstring_templates_path !=# ''
@@ -169,7 +174,7 @@ endfunction
169174
function! pydocstring#format() abort
170175
let lines = printf("%s\n", join(getbufline(bufnr('%'), 1, '$'), "\n"))
171176
let cmd = s:create_cmd('string', '')
172-
let indent = &softtabstop
177+
let indent = s:get_indent_width()
173178
let end_lineno = line('.')
174179
call s:execute(
175180
\ cmd,
@@ -188,7 +193,7 @@ function! pydocstring#insert(...) abort
188193
let line = getline('.')
189194
let indent = matchstr(line, '^\(\s*\)')
190195

191-
let space = repeat(' ', &softtabstop)
196+
let space = repeat(' ', s:get_indent_width())
192197
let indent = indent . space
193198
if len(indent) == 0
194199
let indent = space

0 commit comments

Comments
 (0)