editorconfig / editorconfig-vim

EditorConfig plugin for Vim
http://editorconfig.org
Other
3.13k stars 137 forks source link

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

Closed gwymor closed 1 year ago

gwymor commented 3 years ago

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.

cxw42 commented 3 years ago

Looks reasonable. Thanks for the contribution!

Unfortunately, my motherboard died, so I will not be able to test this until late next week when the new one comes in :( .

cxw42 commented 2 years ago

My PC is working again! :tada:

When I run the tests, I get failures in 4_space.py:

Failures:

  1) plugin/editorconfig.vim 4_space.py
     Failure/Error: expect(vimval).to eq(val), "key #{key} had value #{vimval}, but I expected #{val}"
       key tabstop had value 8, but I expected 4
     # ./tests/plugin/spec/editorconfig_spec.rb:22:in `block in test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `each'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:44:in `block (2 levels) in test_instance'

  2) plugin/editorconfig.vim 4_space.py
     Failure/Error: expect(vimval).to eq(val), "key #{key} had value #{vimval}, but I expected #{val}"
       key tabstop had value 8, but I expected 4
     # ./tests/plugin/spec/editorconfig_spec.rb:22:in `block in test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `each'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:44:in `block (2 levels) in test_instance'

  3) plugin/editorconfig.vim 4_space.py
     Failure/Error: expect(vimval).to eq(val), "key #{key} had value #{vimval}, but I expected #{val}"
       key tabstop had value 8, but I expected 4
     # ./tests/plugin/spec/editorconfig_spec.rb:22:in `block in test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `each'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:44:in `block (2 levels) in test_instance'

  4) plugin/editorconfig.vim 4_space.py
     Failure/Error: expect(vimval).to eq(val), "key #{key} had value #{vimval}, but I expected #{val}"
       key tabstop had value 8, but I expected 4
     # ./tests/plugin/spec/editorconfig_spec.rb:22:in `block in test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `each'
     # ./tests/plugin/spec/editorconfig_spec.rb:20:in `test_editorconfig'
     # ./tests/plugin/spec/editorconfig_spec.rb:44:in `block (2 levels) in test_instance'

Finished in 6.91 seconds (files took 0.96871 seconds to load)
64 examples, 4 failures

Do the tests pass on your machine? I did sudo apt install bundler and then ./tests/travis-test.sh plugin.

gwymor commented 2 years ago

No, the tests weren't passing locally, but I may have missed that because I had a different version of the plugin installed which may have thrown off test results.

Am I correct in thinking that given the config:

[*]
indent_style = space
indent_size = 4
tab_width = 8

If I indent, I should get 4 spaces, and that tab_width should not have any effect on indent width, as indent_style is not tab? If so I have a fix.

gwymor commented 2 years ago

@cxw42 Did those changes fix the issue for you?

gwymor commented 1 year ago

@cxw42 This conflicts with the recently-merged #198, as this PR removes setting softtabstop entirely as it was unneeded after these changes. As that PR adds new config options affecting softtabstop, how would you like to proceed here?

In the mean time, I've rebased this PR and temporarily reverted #198 in my PR so I can continue to use the behavior of my PR.