Skip to content
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

Set shiftwidth to 0 (defaults to tabstop value) #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 0 additions & 17 deletions doc/editorconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,6 @@ max_line_length is set:
<
This option defaults to 0.

*g:EditorConfig_softtabstop_space*
When spaces are used for indent, Vim's 'softtabstop' feature will make the
backspace key delete one indent level. If you turn off that feature (by
setting the option to 0), only a single space will be deleted.
This option defaults to 1, which enables 'softtabstop' and uses the
'shiftwidth' value for it. You can also set this to -1 to automatically follow
the current 'shiftwidth' value (since Vim 7.3.693). Or set this to [] if
EditorConfig should not touch 'softtabstop' at all.

*g:EditorConfig_softtabstop_tab*
When tabs are used for indent, Vim's 'softtabstop' feature only applies to
backspacing over existing runs of spaces.
This option defaults to 1, so backspace will delete one indent level worth of
spaces; -1 does the same but automatically follows the current 'shiftwidth'
value. Set this to 0 to have backspace delete just a single space character.
Or set this to [] if EditorConfig should not touch 'softtabstop' at all.

*g:EditorConfig_verbose*
Set this to 1 if you want debug info printed:
>
Expand Down
50 changes: 15 additions & 35 deletions plugin/editorconfig.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ if !exists('g:EditorConfig_enable_for_new_buf')
let g:EditorConfig_enable_for_new_buf = 0
endif

if !exists('g:EditorConfig_softtabstop_space')
let g:EditorConfig_softtabstop_space = 1
endif

if !exists('g:EditorConfig_softtabstop_tab')
let g:EditorConfig_softtabstop_tab = 1
endif

" Copy some of the globals into script variables --- changes to these
" globals won't affect the plugin until the plugin is reloaded.
if exists('g:EditorConfig_core_mode') && !empty(g:EditorConfig_core_mode)
Expand Down Expand Up @@ -454,38 +446,26 @@ function! s:ApplyConfig(bufnr, config) abort
endif
endif

" Set tabstop. Skip this for terminal buffers, e.g., :FZF (#224).
if s:IsRuleActive('tab_width', a:config) && bufname(a:bufnr) !~# '^!\w*sh$'
let l:tabstop = str2nr(a:config["tab_width"])
call setbufvar(a:bufnr, '&tabstop', l:tabstop)
else
" Grab the current ts so we can use it below
let l:tabstop = getbufvar(a:bufnr, '&tabstop')
endif

if s:IsRuleActive('indent_size', a:config)
" if indent_size is 'tab', set shiftwidth to tabstop;
" if indent_size is a positive integer, set shiftwidth to the integer
" value
if a:config["indent_size"] == "tab"
call setbufvar(a:bufnr, '&shiftwidth', l:tabstop)
if type(g:EditorConfig_softtabstop_tab) != type([])
call setbufvar(a:bufnr, '&softtabstop',
\ g:EditorConfig_softtabstop_tab > 0 ?
\ l:tabstop : g:EditorConfig_softtabstop_tab)
endif
else
" Skip terminal buffers as setting tabstop affects cursor position (#224).
if s:IsRuleActive('indent_size', a:config) && bufname(a:bufnr) !~# '^!\w*sh$'
" When shiftwidth is 0 it uses the value of tabstop
call setbufvar(a:bufnr, '&shiftwidth', 0)
" Disable softtabstop so it doesn't conflict with editorconfig
" indentation settings
call setbufvar(a:bufnr, '&softtabstop', 0)
if a:config["indent_size"] != "tab"
let l:indent_size = str2nr(a:config["indent_size"])
if l:indent_size > 0
call setbufvar(a:bufnr, '&shiftwidth', l:indent_size)
if type(g:EditorConfig_softtabstop_space) != type([])
call setbufvar(a:bufnr, '&softtabstop',
\ g:EditorConfig_softtabstop_space > 0 ?
\ l:indent_size : g:EditorConfig_softtabstop_space)
endif
call setbufvar(a:bufnr, '&tabstop', l:indent_size)
endif
endif
endif

" Set tabstop. Skip this for terminal buffers, e.g., :FZF (#224).
if s:IsRuleActive('tab_width', a:config) && bufname(a:bufnr) !~# '^!\w*sh$'
if a:config["indent_style"] == "tab"
call setbufvar(a:bufnr, '&tabstop', str2nr(a:config["tab_width"]))
endif
endif

if s:IsRuleActive('end_of_line', a:config) &&
Expand Down
17 changes: 11 additions & 6 deletions tests/plugin/spec/editorconfig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ def test_instance(vim)
it '3_space.py' do
test_editorconfig vim, '3_space.txt',
expandtab: '1',
shiftwidth: '3',
shiftwidth: '0',
softtabstop: '0',
tabstop: '3'
end
end

it '4_space.py' do
test_editorconfig vim, '4_space.py',
expandtab: '1',
shiftwidth: '4',
tabstop: '8'
shiftwidth: '0',
softtabstop: '0',
tabstop: '4'
end

it 'space.txt' do
test_editorconfig vim, 'space.txt',
expandtab: '1',
shiftwidth: vim.echo('&l:tabstop')
shiftwidth: '0',
softtabstop: '0'
end

it 'tab.txt' do
Expand All @@ -61,14 +64,16 @@ def test_instance(vim)
it '4_tab.txt' do
test_editorconfig vim, '4_tab.txt',
expandtab: '0',
shiftwidth: '4',
shiftwidth: '0',
softtabstop: '0',
tabstop: '4'
end

it '4_tab_width_of_8' do
test_editorconfig vim, '4_tab_width_of_8.txt',
expandtab: '0',
shiftwidth: '4',
shiftwidth: '0',
softtabstop: '0',
tabstop: '8'
end

Expand Down