Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

pre { tab-size: 4 } #170

Closed
Rich-Harris opened this issue Apr 17, 2014 · 151 comments
Closed

pre { tab-size: 4 } #170

Rich-Harris opened this issue Apr 17, 2014 · 151 comments

Comments

@Rich-Harris
Copy link

For some unfathomable reason, browsers render tabs as 8 spaces. Even among the minority of developers who agree that tabs > spaces, I've yet to find anyone who thinks that makes sense.

Happily, most browsers allow you to set the tab width with the CSS tab-size property. Adding something like the following to the CSS used on github.com and gist.github.com would make code previews much more readable:

pre {
  -moz-tab-size: 4;
  tab-size: 4;
}
@nschonni
Copy link

👍 I find it annoying too. I reached out to GitHub about this when they decided to drop tab characters entirely (now restored). The hack they shared was to add ?ts=4 to the URL to override the value. EX https://github.com/wet-boew/wet-boew/blob/master/Gruntfile.coffee?ts=4

@Rich-Harris
Copy link
Author

@nschonni Thanks, didn't know that. Weird that they'd implement that but not have a sensible default! Also, it doesn't work on gist.github.com sadly

@nschonni
Copy link

Not to hijack the request, but it would be nice to be able to set your preference in your user profile or by project

@rlidwka
Copy link

rlidwka commented Apr 18, 2014

it would be nice to be able to set your preference in your user profile or by project

+1

@Rich-Harris
Copy link
Author

From GitHub:

Hi Rich,

Thanks for your feedback! We're always working to improve GitHub and we consider every suggestion we receive. I've added your idea about changing the tab spacing on GitHub to four to our internal Feature Request List.

We can't say if/when we may add a feature, however your feedback has definitely been recorded.

Cheers,
Steven!

@tobiasvl
Copy link

👍

1 similar comment
@bevacqua
Copy link

👍

@sindresorhus
Copy link

I suggested this in early april and got this response from GitHub:

Would you mind adding tab-size: 4; to your
pre {} rule? It makes tab sized indentation
have sane indentation (4 char instead of 8)
in diff views.

We have discussed this many times but we find 8 to be the safest option. Some browsers only support the default, which is 8. Also, changing the default would break repositories that mix spaces and tabs, like ruby/ruby for example.

We haven’t given up on this though. We still want to find a solution, but we need to find a solution that fixes this without creating new problems.

@bkeepers
Copy link

We actually do use tab-size in CSS now, but it's still 8 because people get 😠 when you change stuff like that on them.

I just proposed to the team that we persist the ?ts=4 param per-user. So you only have to visit it once and it changes it for you forever. I haven't fully thought through the idea, so maybe it's a horrible idea. But we'll see what the consensus is.

@Rich-Harris
Copy link
Author

@bkeepers That sounds to me like a winning solution - grants all the customisability without having to crowbar in extra complexity to the account settings page. Fingers crossed your colleagues go for it. Thanks!

@sindresorhus
Copy link

We actually do use tab-size in CSS now, but it's still 8 because people get 😠 when you change stuff like that on them.

Even if it's a good change that most will want? As an example, Facebook has changed their design a lot, people got angry, but in the end everyone got used to it, and most even found it better. Just saying.

@bkeepers
Copy link

Even if it's a good change that most will want?

I'm all for changing it then, but we don't really have an easy way to quantify that besides gut feeling. We could take time to research it, but honestly I would rather just make ts sticky and move on to something more productive.

@nschonni
Copy link

The way to quantify would be the feedback you received last time you completely replaced tabs with spaces in the diffs and the feedback that got 😉

@tj
Copy link

tj commented Jun 3, 2014

big +1 to changing this it looks ridiculous right now

@narirou
Copy link

narirou commented Jul 3, 2014

+1!
Some projects are sharing the information of the tab size by .editorconfig.
If it is possible to apply this information, not break the display that mix spaces and tabs?

@indexzero
Copy link

Yes. Please.

@mehulkar
Copy link

👍

@sindresorhus
Copy link

I made a quick Chrome extension that fixes this: https://github.com/sindresorhus/github-tab-size

Still hoping for GitHub to fix it themselves though.

refined-github also includes a fix for this.

@gwgundersen
Copy link

+1

@tj
Copy link

tj commented Aug 4, 2014

thou shalt not have nice tabs

@alganet
Copy link

alganet commented Sep 5, 2014

What about reading modelines?

@rlidwka
Copy link

rlidwka commented Sep 5, 2014

supporting .editorconfig is better than modelines, and it was suggested a while ago... still nothing

@f3cuk
Copy link

f3cuk commented Sep 7, 2014

Please change this or give us a good option to do it ourselves. Quantify? What about checking default tab size on decent editors like Notepad++, Sublime. After that check the default tab size on MS 👯

@izaakschroeder
Copy link

+1 .editorconfig

@hrasoa
Copy link

hrasoa commented Oct 6, 2014

+1

@genbit
Copy link

genbit commented Oct 17, 2014

👍 for ?ts=4 only one time
👍 for .editorconfig

@avitex
Copy link

avitex commented Oct 21, 2014

+1

@RReverser
Copy link

Hi there, I've just published a browser extension that provides EditorConfig support for GitHub's code viewer and editor:

@Alhadis
Copy link

Alhadis commented Feb 10, 2020

@ioquatix What about mobile users, or those whose browsers don't support such a thing?

@ioquatix
Copy link

Oh, I totally agree, and I advocate for:

  • Per project setting (some projects using hard tabs simply require them to be 8 spaces, they are not a form of variable indentation).
  • Per organisation default (if nothing else is configured, use the specified default).
  • Per user default (if this is set, it overrides per-organisation defaults).

@natematykiewicz
Copy link

@ioquatix Ironically, I found this post by reading some of your code and wishing I could make the tabs be 2 spaces. 😅

@Alhadis
Copy link

Alhadis commented Feb 24, 2020

It's time for my annual "nag GitHub support to add this feature again". This time I was more clear about receiving an explanation. CC'd here for transparency:

Dear GitHub,

I've requested this almost every year since 2015, and will continue to do so: Please add a repository-level setting to change the default tab-width of 8 columns. You added .editorconfig support, but that isn't an adequate solution — you're forcing users to abuse an EditorConfig setting that affects how collaborators can contribute to their repository.

The whole point of semantic tab-use is to enable others to read your code with the indentation-size they're most comfortable with. This might be simple preference, or a product of physical constraints such as screen- or font-size. By requiring indent_size = 4 to override an unwieldy historical default, you're taking this benefit away from users whose codebases are formatted with accessibility in mind.

PLEASE add a repository-level setting for this. It's a simple case of adding the following CSS to a page's header:

<style>
	/* Replace `8` with configured repository setting */
	:root{
		--tab-size: 8;
	}

	/* Add any other selectors styled with `white-space: pre;` */
	.blob-code-inner, pre, code, tt {
		-moz-tab-size: var(--tab-size);
		tab-size:      var(--tab-size);
	}
</style>

The solution above uses a CSS variable that can be overridden in specific elements by adding style="--tab-size: 4", if such a thing is needed.

If there's a reason GitHub staff refuse to add this feature, please e-mail me the official explanation.

Punting this as "low priority" is absurd when it takes very little effort to add, and many users have requested it time and time again… for years.

Moreover, you listened to my incessant nagging about adding 1-pixel dividers between language-colours in repository stat-bars, which is no less complicated (and far more trivial) than adding a tab-size feature.

Yours,
@Alhadis

@ioquatix
Copy link

One way to get GitHub to move on this might be to implement a similar feature in GitLab...

https://gitlab.com/gitlab-org/gitlab/issues/26768

I'm going to take a stab at it if I have time.

@maximal
Copy link

maximal commented Feb 27, 2020

One way to get GitHub to move on this might be to implement a similar feature in GitLab...

https://gitlab.com/gitlab-org/gitlab/issues/26768

Yes, guys, comment and upvote there!

t-b added a commit to AllenInstitute/MIES that referenced this issue Apr 7, 2020
This adds an editorconfig file. It's main purpose is to tell github how
wide a tab character is. This is supported according to [1].

[1]: isaacs/github#170 (comment)
@melgu
Copy link

melgu commented May 16, 2020

This also applies to Markdown previews.
For those not even the ?ts=4 trick works.

Bitbucket handles tabs correctly, by the way.

@RomainLanz
Copy link

Any news on this feature?

@Primajin
Copy link

Since Github offers things like setting emoji color and theme in here: https://github.com/settings/appearance this should be the right place to also set preferred tab size.

@AverageHelper
Copy link

Since I just found this, and I don't know if it's been posted already, and I think it makes relevant arguments, I'll link this Reddit post.

TL;DR:
There is a significant population of developers and potential developers with visual impairments who rely on editor-level tab-size configuration to do their work. The fact that GitHub et al do not permit this sort of configuration is a pain point for them.

+1 for adding an optional user-level tab-width config. Bonus points to actively recommend that new repos use tabs.

@Rybec
Copy link

Rybec commented Jun 2, 2021

I just want to express my desire for a repo level tab setting that does not require pushing contributors to use that same setting in their own editors. I go to great effort to make sure my code looks right in any tab setting (tabs for indentation, spaces for alignment), but I want the Github presentation to be 4 character widths for tabs. Tabs more than 4 characters wide rapidly push code so far to the right that it can become a serious problem for readability.

@GregWoods
Copy link

just created my first gist. Yay!
But wait, what the hell is wrong with formatting?
Ah wait there's an open issue for this.
But it is 7 years old
Goodbye gists :(

@Levi-Lesches
Copy link
Contributor

I didn't realize there wasn't anything open at github/feedback, so I opened community/community#4893 and linked back here. Upvote (not just 👍) there to get GitHub's attention on this.

@michellemerrill
Copy link
Collaborator

Hey everyone 👋 good news, you can now define the tab size in the Appearance settings of your user account. Code rendered on GitHub with tab indent will use your preferred tab size.

shrianshChari added a commit to shrianshChari/shrianshChari that referenced this issue Oct 30, 2021
ghost pushed a commit to Road6943/RoadRayge that referenced this issue Oct 31, 2021
- Sets the default tab width to 4 (instead of 8) when viewing JS files via GitHub 
- Source: isaacs/github#170 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests