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

Sets sw=6, ts=8 when file uses tabs #65

Closed
HaleTom opened this issue Sep 3, 2020 · 5 comments
Closed

Sets sw=6, ts=8 when file uses tabs #65

HaleTom opened this issue Sep 3, 2020 · 5 comments

Comments

@HaleTom
Copy link

HaleTom commented Sep 3, 2020

Here's the file:

https://raw.githubusercontent.com/git/git/master/git-add--interactive.perl

I was expecting sw=4, ts=4 (preferred) or a least sw=8, ts=8.

@HaleTom
Copy link
Author

HaleTom commented Sep 4, 2020

Perhaps a user-settable variable to allow a person do define 2, 4, or 8 (etc) spaces as default if there are only TABs?

@HaleTom
Copy link
Author

HaleTom commented Sep 13, 2020

This may help detecting the causes in the provided file:

roryokane/detectindent#18

Repository owner deleted a comment from sheerun Dec 7, 2021
@tpope
Copy link
Owner

tpope commented Dec 7, 2021

We do respect 'tabstop' if there are nothing but tabs. Unfortunately, there's a single line that starts with 6 spaces:

https://github.com/git/git/blob/abe6bb3905392d5eb6b01fa6e54d7e784e0522aa/git-add--interactive.perl#L481

I'm not seeing an obvious fix here. While a single line 6 space indent is almost certainly spurious, that's not very far from a sole pair of 4 space indents, which is valid:

class MixedFile {
    public static void main(String[] args) {
	System.out.println("This file uses sw=4 ts=8 noet");
    }
}

Where do we draw the line?

I do have a fix coming for this particular example in the form of EditorConfig support. The repository in question has a .editorconfig with relevant settings:

[*.{c,h,sh,perl,pl,pm,txt}]
indent_style = tab
tab_width = 8

@tpope tpope closed this as completed in 3cf7825 Dec 8, 2021
@tpope
Copy link
Owner

tpope commented Dec 8, 2021

Looks like disallowing 6 as a valid indent level does allow it to detect this file as shiftwidth=8 tabstop=8, so I've gone ahead and done that. Unfortunately, this still won't allow shiftwidth=0 like it would with a purely tab indented file.

Specifically, I changed the even number requirement to a multiple of 4 requirement, and given precedence to 4 and 8 over the uncommon (but still occasionally used 3. I'm retaining support for large multiples of 4 because they have niche uses (e.g., I like sw=24 in Vim help files) and I don't think I've had any error reports of that nature.

@HaleTom
Copy link
Author

HaleTom commented Dec 8, 2021

Thanks for resolving this! 🎉🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants