Skip to content

Add support for smarttab / shiftwidth #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ type `:PydocstringFormat` will insert all docstrings to current buffer.

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

Example ``.vimrc``

.. code::

autocmd FileType python setlocal tabstop=4 shiftwidth=4 smarttab expandtab

Or:

.. code::

autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
Expand Down
13 changes: 9 additions & 4 deletions autoload/pydocstring.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ let g:pydocstring_doq_path = get(

let s:results = []

function! s:get_indent_width() abort
" Get indentation width
return &smarttab ? &shiftwidth : &softtabstop
endfunction

function! s:get_range() abort
" Get visual mode selection.
let mode = visualmode(1)
Expand Down Expand Up @@ -147,7 +152,7 @@ function! s:create_cmd(style, omissions) abort
\ expand(g:pydocstring_doq_path),
\ a:style,
\ g:pydocstring_formatter,
\ &softtabstop
\ s:get_indent_width()
\ )
else
let cmd = printf(
Expand All @@ -156,7 +161,7 @@ function! s:create_cmd(style, omissions) abort
\ a:style,
\ g:pydocstring_formatter,
\ a:omissions,
\ &softtabstop
\ s:get_indent_width()
\ )
endif
if g:pydocstring_templates_path !=# ''
Expand All @@ -169,7 +174,7 @@ endfunction
function! pydocstring#format() abort
let lines = printf("%s\n", join(getbufline(bufnr('%'), 1, '$'), "\n"))
let cmd = s:create_cmd('string', '')
let indent = &softtabstop
let indent = s:get_indent_width()
let end_lineno = line('.')
call s:execute(
\ cmd,
Expand All @@ -188,7 +193,7 @@ function! pydocstring#insert(...) abort
let line = getline('.')
let indent = matchstr(line, '^\(\s*\)')

let space = repeat(' ', &softtabstop)
let space = repeat(' ', s:get_indent_width())
let indent = indent . space
if len(indent) == 0
let indent = space
Expand Down