From 9edac64ca5d80f8200ceec378663bc55cdb3cd5d Mon Sep 17 00:00:00 2001 From: Gwyneth Morgan Date: Sun, 12 Mar 2023 16:21:05 +0000 Subject: [PATCH] Set shiftwidth to 0 (defaults to tabstop value) The current behavior is to set both shiftwidth and tabstop/softtabstop. shiftwidth gets set to the same value as tabstop. If I open a file that editorconfig indents with 8-space hard tabs, then ":set tabstop=4", my shiftwidth will still be 8, meaning that when I indent I will get two tabs. Set shiftwidth to 0, which defaults to the value of tabstop, and doesn't set softtabstop either. This should have the same end result with less complication. This removes the g:EditorConfig_softtabstop_space and g:EditorConfig_softtabstop_tab options, as we now don't need to touch softtabstop at all. --- doc/editorconfig.txt | 17 ------------ plugin/editorconfig.vim | 36 +++++++------------------- tests/plugin/spec/editorconfig_spec.rb | 12 ++++----- 3 files changed, 15 insertions(+), 50 deletions(-) diff --git a/doc/editorconfig.txt b/doc/editorconfig.txt index 0b7916ed..52f15882 100644 --- a/doc/editorconfig.txt +++ b/doc/editorconfig.txt @@ -173,23 +173,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: > diff --git a/plugin/editorconfig.vim b/plugin/editorconfig.vim index c489342b..1d1c76c2 100644 --- a/plugin/editorconfig.vim +++ b/plugin/editorconfig.vim @@ -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) @@ -395,31 +387,21 @@ function! s:ApplyConfig(config) abort " Set the buffer options {{{1 endif endif - if s:IsRuleActive('tab_width', a:config) - let &l:tabstop = str2nr(a:config["tab_width"]) - 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" - let &l:shiftwidth = &l:tabstop - if type(g:EditorConfig_softtabstop_tab) != type([]) - let &l:softtabstop = g:EditorConfig_softtabstop_tab > 0 ? - \ &l:shiftwidth : g:EditorConfig_softtabstop_tab - endif - else + " When shiftwidth is 0 it uses the value of tabstop + let &l:shiftwidth = 0 + if a:config["indent_size"] != "tab" let l:indent_size = str2nr(a:config["indent_size"]) if l:indent_size > 0 - let &l:shiftwidth = l:indent_size - if type(g:EditorConfig_softtabstop_space) != type([]) - let &l:softtabstop = g:EditorConfig_softtabstop_space > 0 ? - \ &l:shiftwidth : g:EditorConfig_softtabstop_space - endif + let &l:tabstop = l:indent_size endif endif + endif + if s:IsRuleActive('tab_width', a:config) + if a:config["indent_style"] == "tab" + let &l:tabstop = str2nr(a:config["tab_width"]) + endif endif if s:IsRuleActive('end_of_line', a:config) && diff --git a/tests/plugin/spec/editorconfig_spec.rb b/tests/plugin/spec/editorconfig_spec.rb index 67e2eb71..8ffb78af 100644 --- a/tests/plugin/spec/editorconfig_spec.rb +++ b/tests/plugin/spec/editorconfig_spec.rb @@ -35,7 +35,7 @@ def test_instance(vim) it '3_space.py' do test_editorconfig vim, '3_space.txt', expandtab: '1', - shiftwidth: '3', + shiftwidth: '0', tabstop: '3' end end @@ -43,14 +43,14 @@ def test_instance(vim) it '4_space.py' do test_editorconfig vim, '4_space.py', expandtab: '1', - shiftwidth: '4', - tabstop: '8' + shiftwidth: '0', + tabstop: '4' end it 'space.txt' do test_editorconfig vim, 'space.txt', expandtab: '1', - shiftwidth: vim.echo('&l:tabstop') + shiftwidth: '0' end it 'tab.txt' do @@ -61,14 +61,14 @@ def test_instance(vim) it '4_tab.txt' do test_editorconfig vim, '4_tab.txt', expandtab: '0', - shiftwidth: '4', + shiftwidth: '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', tabstop: '8' end