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.

Problem

I'm sure everyone over 2.500 reputation has at least once had a question where the user simply didn't understand how to insert/highlight his code. Which often results in either none-formatted code which would be the least problematic option or in wrong-formatted code which means that they abused the block-quote function for that. The last part is where the it gets ugly.

For example I'm quite active on the Android tag where users tend to post their entire layout files content (XML) and those layout files can be very long sometimes. Editing such questions by hand line per line can drive you nuts.

Suggestion

My suggestion would be to have a simple window pop up when the user hits the code button. In that window you have only a textarea where you can paste your code and then you hit submit it posts the entire content formatted as code (i.e. properly indented) at the cursors position.

What do you think?

share|improve this question
2  
Editing such questions by hand line per line can drive you nuts. You know you can select multiple lines and click that code button from the editor's toolbar? (Or hit Ctrl-K.) –  Arjan Jan 19 '11 at 17:45
    
@Arjan: Of course I know that but if a user has wrapped a code snippet XML in a block-comment then you won't solve anything with that. Best example is here stackoverflow.com/q/4734932/418183. –  Octavian Damiean Jan 19 '11 at 17:48
    
I guess in that example my response would have been a downvote and a comment (especially as the author did make some minor other edit)... (But: thanks for cleaning up that mess!) –  Arjan Jan 19 '11 at 17:53
    
yes , that is a great idea. Just like we have in www.asp.net site. –  Chris Feb 10 '11 at 16:06
    
In that case, the user didn't just wrap it in a block-comment. It looks like he did a search and replace to replace \t with >\t. I'm not sure why he did that, but you can't get multiple-level blockquotes using the blockquote button. But the weird thing is that you can see that he did use the code button to begin with, because the text "enter code here" is present before the code. –  Kip Feb 10 '11 at 18:10
    
@Kip: Yea thats what I mean. The problem is that the current workflow to post code properly is not intuitive. –  Octavian Damiean Feb 10 '11 at 18:13
add comment

2 Answers

up vote 3 down vote accepted

I vote bad idea.

If you're trying to fix someone else's code, use something like Notepad++ with it's code reformatter/XML reflow engine (ok, I personally use Notepad++, you may very well use another notepadclone. I don't imply that this is the only solution, only that this is what I do for long blocks)

I think that having that popup everytime I wanted to insert code would drive me mad. And you can't do it for the rep1 users, cos then they'll want it when they're rep 2500.

So because it would drive me mad, I don't want it.

share|improve this answer
    
Good point with Notepad++ (or something similar). I really has never occurred to me to try that. –  Octavian Damiean Feb 10 '11 at 18:05
add comment

I would like to have an indent/outdent feature to reformat code that is way too much indented.

E.g. good:

protected void Myfunction(int i, int j)
{
    CallSomething(i);
    CallSomething(j);
    CallSomething(k);
}

and bad:

            protected void Myfunction(int i, int j)
            {
                    CallSomething(i);
                    CallSomething(j);
                    CallSomething(k);
            }

Edit: Oops, I just saw that multiple times clicking the {} button seems to do the trick?!?!

Edit 2: Seems that it only toggles, but not outdents/indents multiple times.

share|improve this answer
    
Retry: If the original code uses TABS it won't reflow it back and forth, but if you insert something with lots of spaces it will up to the last level (or did, in my previous experience) –  jcolebrand Feb 10 '11 at 18:12
add comment

You must log in to answer this question.

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