Obviously this is personal preference when you're creating code on your own machine. However, since adding tabs to a text box is not (as far as I know) natively supported in most browsers. Three or four spaces would make editing/formatting questions and answers easier. This wouldn't need to be done on paste (though that would be nifty), but could be done at question/answer save time. Is something like that feasible?

For example:

    Two tabs
    Eight spaces

Appears in the editor like:

same as text above but two tabs text is spaced further to the right than eight spaces text

Which makes it annoying for lining up things for formatting. Maybe this is just nit-picky, but it would be nice to have some consistency.

EDIT

Allow me to make this clearer, since Lohoris seems to be confused. I clearly agree that mixing tabs and spaces is bad. This post is advocating for not having both. Since browsers typically only allow spaces as input, I'm saying we should automatically switch to spaces. Otherwise, if you want to edit code that's been pasted in with tabs, you can only add spaces, therefore mixing tabs and spaces. If the editor converted tabs to spaces, we'd never have mixed tabs and spaces.

share
you mean other than the currently implemented 4 spaces? you know inserting 4 spaces works exactly like a tab – Gajoo Apr 27 '12 at 20:40
Well not exactly like a tab, but yes I'm aware that I can use spaces. However, if I copy and paste my code that contains tabs, they remain tabs even when saved. This means if I wanted to easily change the formatting I'd have to convert it to spaces or edit it outside the browser with tabs and paste it in then. – Byte56 Apr 27 '12 at 20:44
still you can use spaces even if you are editing a code which is indented by tabs. but I agree with you saying it's easier if all of them were the same. – Gajoo Apr 27 '12 at 20:51
1  
Upvoted for great justice. I'd like to see this. Formatting on-paste might be a better idea because otherwise any adjustments to your code in the editor might look completely different when you post it. – Jonathan Hobbs Apr 27 '12 at 23:56
some text editors support tab->Xspaces, and reverse such as notepad++. though I can see a possible issue having to copy over just to copy it again to SE – gardian06 May 4 '12 at 9:39
Yeah, it's easy with find replace is most text editors. And I've done with when editing other people's code, hence the request. – Byte56 May 4 '12 at 12:51
Much more clear now. – Lohoris May 13 '12 at 15:27

1 Answer

I like the initial idea, but at the same time. I am going to play some "devil's advocate".

first the system would have to know the difference between code, and text upon insert, and the system does not know this until after the tags have been processed (which for many users myself included not even entered until after the question has been written/copied) so the system would have to know what code looks like.

the only way to implement this cleanly would probably require users to use XML/HTML tags for example: (not that [ is equivalent to <, and ] is equivalent to > )

[Code]

//paste code here, and have tabs converted to 4 spaces

[/Code]

which are valid tags, but some users myself included don't use them, and just want to be able to paste in code, and have this kind of functionality there

the other thing that I could see is for those users that purposely format their code with tabs for spacing of comments to the right of code test (for clarity/explanation)

TYPE varName        // this var does ______

so that it is not confused as part of the code line just in case color formatting doesn't like it, and say that I just wanted 2 slashes.

but on the other hand I really would like something like this, and would appreciate it being implemented across all stackExchange sites, and probably the metas as well (code sometimes ends up on the meta sites)

share
3  
"first the system would have to know the difference between code, and text upon insert, and the system does not know this until after the tags have been processed" This site doesn't use BBCode tags; it uses Markdown. You indent by four spaces or one tab for code. The system can understand immediately upon insert what's code or not. – Jonathan Hobbs Nov 10 '12 at 10:18

You must log in to answer this question.

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