What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 127 Stack Exchange communities.

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.

share|improve this question
The real problem, of course, is that those people are using tabs instead of spaces in their IDEs. –  Cody Gray May 12 '11 at 3:39
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 :/ –  Oscar Mederos May 12 '11 at 3:47
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. –  NickC May 12 '11 at 5:36
Also, TAB is not an acronym. –  NickC May 12 '11 at 5:38
@Renesis Yes, I have to do that. Also, TAB is not an acronym. So what? –  Oscar Mederos May 12 '11 at 5:49
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 May 12 '11 at 6:10
I like Tabs, and turtles. –  H.B. May 12 '11 at 6:41
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 Aug 7 '13 at 14:39
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 Dec 13 '13 at 16:55
Rather than converting into spaces, implemented using minitech's answer; see Please set the editor tab size to 4. –  Arjan Jun 29 at 20:38
add comment

5 Answers

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.

share|improve this answer
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. –  Oscar Mederos May 12 '11 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 :/ –  Oscar Mederos May 12 '11 at 5:04
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. –  Gilles Sep 2 '12 at 13:13
add comment

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

share|improve this answer
You're just daring me to edit that to $0.02 aren't you? ಠ_ಠ –  Bill the Lizard May 12 '11 at 12:14
@Bill it's because of inflation (of my ego most likely) ... –  jcolebrand May 12 '11 at 14:17
add comment

I'd only like this if it's done while pasting, hence using JavaScript.

To me, the main advantage would then be that the preview and the final result, which convert tabs to spaces based on a width of 4, will match the (pasted) text in the edit box.

(Hardly anyone will know how to type tabs in the editor anyhow, as most browsers will change the focus to another input while pressing Tab. If done in JavaScript then it might not work for some users, or on some devices, tabs will be left in some posts then.)

share|improve this answer
add comment

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.)

share|improve this answer
add comment

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;
share|improve this answer
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 Jul 21 '13 at 16:22
(Oh, forgot that jsFiddle. Later...) –  Arjan Aug 22 '13 at 22:42
I totally missed this answer of yours previously. Absolutely makes sense. –  balpha Jun 29 at 19:20
add comment

You must log in to answer this question.

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