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

Related:

Note that this question, while related, is not the same as the ones linked.

In many cases, when people put code into questions or answers, they copy/paste the code from their editor. If their editor is using tab characters, the formatting will be broken after the post is submitted. For example, if a code is indented using TAB characters, then one TAB character in the beginning of a line will be treated as one level of indent and align with the left edge of the code, effectively indenting equally to 4 spaces. However in the post editor it looks indented twice - the same as 8 spaces.

I often edit other people's posts to improve code formatting and I find this TAB issue being the biggest annoyance.

Most of the times (I think) on SO, we use 4 spaces to format/indent the code. I think it would be an easy thing to auto-expand TAB characters inside <code> blocks by replacing them with 4 spaces when the post is submitted.

share|improve this question
    
If their editor is using tab characters, the formatting will be broken after the post is submitted. No repro, at least not as long everything has a leading tab or spaces. So, C&P code and press the Code-Formatting button works very well. If only the first line is intended, it can of course not work...examples? –  Time Traveling Bobby Sep 6 '12 at 11:03
    
For example, I edited this post earlier today. However the issue is more pertinent when I copy pieces of code to paste into my answer and then make changes in it. I would always use spaces, yet if the code has tabs, then I end up having to manually replace them with spaces to ensure the formatting is correct. –  Aleks G Sep 6 '12 at 11:09
    
That's exactly what I described. You should select the whole code-block instead of only the first few lines, and press the code formatting button. Then everything would align nicely. –  Time Traveling Bobby Sep 6 '12 at 11:19
    
I understand that. The bigger issue is with the copying original code into the answer and then making changes. –  Aleks G Sep 6 '12 at 11:27
1  
Also, I like my tabs 4 spaces long, not 8. And I know others who like them 2 spaces long...I'm not sure, but I think there are people which prefer 6 spaces. I don't think this can be "automatically fixed". –  Time Traveling Bobby Sep 6 '12 at 11:29
    
@Sorry, my mistake, I did mean 4 space (I updated my post), however I do appreciate that others may have other preferences. –  Aleks G Sep 6 '12 at 11:37
    
Yes yes, I can understand where you're coming from, but the problem here are not the tabs, but that people are formatting the code wrong, and also fix it incorrectly. At least to your example. –  Time Traveling Bobby Sep 6 '12 at 11:39
    
Would be nice if we can indent complete code block using TAB just like in NetBeans or Eclise... –  Alexandre Lavoie May 28 '13 at 2:07

1 Answer 1

I think Tab characters should be at least warned about, when posting a question text that contains them. Something like a popup with text:

Your post contains TAB characters. They often break formatting of any source code, and they make editing the question more difficult. Do you want to continue or go back and edit them out?

Ideally the editor would have a tool to convert tabs to spaces, which would show a pop-up asking how many spaces is one Tab.

I personally would simply not allow submitting a question or an answer, until all tabs chars are removed. This would be especially viable of TAB removal tool was added. But I understand if some would think this is going too far.


Are there any cases, where using TAB chars in SO code snippets is required? Makefile contents maybe, but do they get reliably preserved now, anyway?

share|improve this answer

You must log in to answer this question.

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