Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Some people, myself included, thought that buttons to adjust the indentation of code blocks would be useful, since apparently such buttons in all likelihood won't be implemented offically i tried to add this functionality via JavaScript.


Screenshot

The script can be found on GitHub (Source).

The direct link should (prompt for confirmation &) install the script if the browser supports it (i don't know about other browsers but Chrome has some native support and in Firefox you should install the Greasemonkey addon).

Feel free to contribute to and improve* the script, it could do with a more extensive list of includes as it only runs on StackOverflow (and Meta) for now. Another thing that is missing is the automatic preview update, i do not know how to trigger it via code, it should be called after the indentations are executed.

Edits:

  • Script now supports the "new" dynamically added inline editors.

*Two weeks ago i pretty much used JavaScript for the first time, the code is likely to be crap.

share|improve this question
    
According to Google, "In the latest version of Google Chrome, you must explicitly tell Chrome that you want to install these extensions by adding them through the Extensions page." (that being said, I've tried manually adding the extension -- and it's present -- but it doesn't do anything) –  Kirk Woll Jan 17 '13 at 2:42
    
@KirkWoll: That is unfortunate and i cannot tell you what might be wrong; i have not tested this on Chrome for a long time and the new extension mechanism is a bit of a pain. I can tell you that it still seems to work on FF if i have the same version installed. –  H.B. Jan 17 '13 at 6:49

1 Answer 1

Very cool! Just as a reminder, though, there is some built in functionality worth reminding people about.

Starting with this:

                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");

I highlight it all, then hit nothing but the Code Formatting (aka ctrl+k) button 7 times, and...

Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");

It will only go in one direction until it hits the end, though that should be sufficient to most purposes. Doing this to your whole code block should keep everything in their proper alignment for your post.

There currently isn't any sort of built-in method to add tabs more than one deep.

share|improve this answer
    
I am quite aware of this but others might not; One problem is that this backward shifting does not always seem to work (not sure if tab vs. spaces makes a difference) and increasing indentation is helpful for example when having code in a list (which requires 8 spaces indentation). –  H.B. Jun 7 '11 at 12:39

You must log in to answer this question.

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