33

I've seen other questions regarding the same, but in this case I think it is a little different. I know the Markdown handles tabs correctly (when generating the HTML code), but that's not what I'm requesting.

I think it would be good to automatically convert tabs to spaces when storing the code in a post. I mean, changing the Markdown source.

Although you think nobody mixes tabs with spaces, well, lots of people copy some piece of code from a website, or from their IDE, and do some edits (maybe looking for a correct indentation here on Stack Overflow), and then it happens.

The thing about it is that it makes editing much harder. You have to copy the code to a text editor, replace tabs with spaces, and then paste the code on the site again and indent it correctly.

10
  • 14
    The real problem, of course, is that those people are using tabs instead of spaces in their IDEs.
    – Cody Gray
    Commented May 12, 2011 at 3:39
  • 2
    Whenever I install a new editor/IDE, the first first two things I do are: Configure the compiler, in case it is a text editor, and turn on the option to automatically convert from TABs to Spaces :) You don't need how bad it can be until you start programming in Python :/ Commented May 12, 2011 at 3:47
  • 5
    Really? You really have to paste it into a text editor and convert tabs to spaces first? Just today I worked with several code samples of my own and others that had mixed tabs and spaces, and somehow I managed.
    – Nicole
    Commented May 12, 2011 at 5:36
  • 2
    Also, TAB is not an acronym.
    – Nicole
    Commented May 12, 2011 at 5:38
  • 3
    @Renesis Yes, I have to do that. Also, TAB is not an acronym. So what? Commented May 12, 2011 at 5:49
  • 2
    The feature request aside, if Tabs don't work as expected, then a recent fix failed. Leaving comments for balpha there might be helpful. Works for me though.
    – Arjan
    Commented May 12, 2011 at 6:10
  • 3
    I like Tabs, and turtles.
    – brunnerh
    Commented May 12, 2011 at 6:41
  • 1
    The real problem is when leading-tab and leading-space lines are in the same code block: They may align in the editor, but in the rendering they become jagged. It would be best if they were automatically converted to spaces when pasted in. It would have the end result of a lot more readable code on the site, and save editors the most tedious and mind-numbing work they do--aligning code blocks. And, if in the conversion, alignment changes because of a difference in tab size between the pasted-in code and SO, the poster could deal with it right there.
    – Curt
    Commented Aug 7, 2013 at 14:39
  • 1
    Tabs vs. spaces, ponies vs. unicorns... its not about whose right or wrong, its about picking a style and sticking to it. So what we should be asking for is a style guide and a linter, not inciting a flame war thats been hashed to death since the dawn of ASCII.
    – jibsales
    Commented Dec 13, 2013 at 16:55
  • Rather than converting into spaces, implemented using minitech's answer; see Please set the editor tab size to 4.
    – Arjan
    Commented Jun 29, 2014 at 20:38

5 Answers 5

10

I'm absolutely in favour of dealing with the problem of tabs. I just edited one too many terribly formatted post by some poor schlub who probably never thought about indenting in their IDE in the first place, but definitely made zero effort to make the result readable on Stack Overflow.

Now, I'm always happy to help and edit something to look better, but having tabs in the original makes this incredibly frustrating. What's missing isn't necessarily automatic conversion, but a tool to help us edit such posts.

When I'm editing, I'm already prepared to cut up and rearrange the original material, so preserving original material is secondary. What I would really, really welcome is an editing tool that performs the conversion on request.

So, here's what I'd like: Add a tool button to the editor that converts tabs to spaces.

(Here is a related question on this topic.)

7

I'm against this on principle - when I go back to edit something I've posted, I expect to see the text I entered, as I entered it. The Markdown renderer, and then the renderer in the users' browsers will transform it into something very different, but I like to know that what I typed is still there, behind the scenes, somewhere.

That said, whitespace is really small potatoes. And I don't use tabs anyway, so... y'know... It wouldn't affect me, screw everyone who does.

...If there's actually some tangible benefit to it. You're talking about re-indenting someone else's code - this is actually harder when the original text is indented using spaces, since you can just tell your text editor to expand tabs to n spaces, where n is whatever your preferred indentation might be. It's... kinda the only advantage tabs have going for them.

Of course, if you really want to make your life easy, you use a pretty-print utility.

4
  • I agree with you about seeing the text as the OP wrote it originally, but the thing is that this problem usually occurs with new users, and not only new, but also users that probably won't visit the site again. Registered users interested on asking/answering interesting questions/answers usually do not mix tabs with spaces in their code, or if they do, at least they are familiar with the markdown renderer, so questions/answers won't have to be edited that much by other users. Commented May 12, 2011 at 5:02
  • That is how I see it. We have to compare both affected sides. The post owner or the community. If they don't want the code to be edited and modified, then they could put a minimum of interest and at least see in the preview how they question looks like before submitting it. Otherwise it should be modified so people can easily read and understand the question, and TABs and Spaces at the same time make this process harder :/ Commented May 12, 2011 at 5:04
  • 4
    There's plenty of tangible benefit. Especially when a tab is 8 spaces in the editor in Firefox and Chrome (like most other editors out there), but 4 spaces in what's displayed, so what looks perfectly well indented in one is completely screwed up in the other. There's no right way to use tabs here, and no benefit in to supporting them. Commented Sep 2, 2012 at 13:13
  • Also, some things actually rely on tabs, like makefiles, for which it's already bad enough that tabs are rendered as 4 spaces.
    – Arjan
    Commented Aug 15, 2015 at 13:28
5

Non-content-destroying fix to at least make indentation less of a guessing game:

.wmd-input {
    -moz-tab-size: 4;
      -o-tab-size: 4;
         tab-size: 4;
}
4
  • 2
    Simply assuming this works: very, VERY nice. No need for anything else then I'd say. (Will make a jsFiddle/JS Bin when at a regular computer, and delete my own answer if this solves it. Nice!)
    – Arjan
    Commented Jul 21, 2013 at 16:22
  • (Oh, forgot that jsFiddle. Later...)
    – Arjan
    Commented Aug 22, 2013 at 22:42
  • Finally, the fiddle is here. And someone wants your proposal to become real.
    – Arjan
    Commented Jun 29, 2014 at 9:08
  • 3
    I totally missed this answer of yours previously. Absolutely makes sense.
    – balpha StaffMod
    Commented Jun 29, 2014 at 19:20
2

I am against this because you propose that they should edit what was entered, not martial what they display.

I am against anything that causes them to change what I submitted, given the way things are structured around here right now. I don't mind edits, I don't mind changing how you display it, but if I key it in in a certain way, that's what I expect to get entered.

Consider it a form of anti-censorship.

Just my $0.05 of course

2
  • 1
    You're just daring me to edit that to $0.02 aren't you? ಠ_ಠ
    – Bill the Lizard Mod
    Commented May 12, 2011 at 12:14
  • 1
    @Bill it's because of inflation (of my ego most likely) ...
    – jcolebrand
    Commented May 12, 2011 at 14:17
0

Doing this is actually troublesome for languages that rely on tabs, like makefiles:

A makefile consists of “rules” with the following construct.

target: dependencies
<Tab ↹> system command(s)

Note: It is important to insert a <Tab ↹> character before the commands.

(For those, it's also a problem that tabs are converted to spaces when rendered on the site.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .