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.

To future readers

I agree, this deserves its current low ranking. You are free to downvote it again if you wish, but I don't believe it will actually accomplish anything as it is already a -6.

Original post:

So, the most common edit that I make is to simply highlight a block of text and then hit "ctrl+k". Could there be an easy way to simply highlight the text and press a button and have the currently selected text indented (without my having to actually enter into question edit mode)?

Basically, given this:

if foo: doBar()

(Which is really
if foo:
   doBar()
in the source of the question)

I would be able to select "if foo: doBar()", click the button and it would change to

if foo:
    doBar()

(the same as above, only with an additional 4 spaces in front of it)

EDIT

Currently, to fix bad indenting:

  1. See where error is in document.
  2. (possibly) scroll to edit button.
  3. Page re-renders (yes, it is inline, but now there is a large box on the top which makes it so that you have further loss of reference)
  4. Find area in document which was badly formatted in the new textarea.
  5. format.
  6. commit changes with "Save Edits".
share|improve this question
1  
Why not ask this question? I was about to! Much of my editing of other's posts is to do basic formatting of their appallingly formatted code. I'm not adding much intellectual value - it's pretty mechanical. Couldn't some javascript be written to apply basic formatting at the user's request (and have the javascript detect the language)? –  Bohemian Jan 5 '12 at 4:21

2 Answers 2

up vote 7 down vote accepted

Per

Simple method for reliably detecting code in text?

We just deployed a method that we think is quite reliable for blocking 98% of posts submitted with code that has improper code formatting (or no code formatting at all).

For example, when I go into Chrome incognito and attempt to ask this question body on Stack Overflow right now:

I needed to add up all the rows for a result. Using the select_sum as follows

Here is the model

function Dues_Paid_Tot($date)
    {
        $query = $this->db->select_sum('Dues_Paid', 'Dues_Paid_Tot');
        $query = $this->db->get('Membership');
        return $query->result();
    }

Here is the controller

function Fiscal2()
    {
    $date = $this->input->post('Select_Date');
        if($query = $this->report_model->fiscal_list($date))
        {
            $data['records'] = $query;
        }
    $data['date'] = $this->input->post('Select_Date');
    $data['Dues_Paid_Tot'] = $this->report_model->Dues_Paid_Tot($date);
    $data['main_content'] = 'report_fiscal_view';
    $this->load->view('includes/template', $data);
}

I get back:

Oops! Your question couldn't be submitted because:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

This check is limited to users with <= 50 reputation and is performed on questions / answers / edits and suggested edits.

If you see or hear of any cases where this is triggered inappropriately -- or not triggered, and it should have been -- let us know.

share|improve this answer
    
Awesome. Didn't know about that. Honestly, there are still times when people w/ rep > 50 make these mistakes (I know that I've left off a space and it's broken the highlighter at least once), but my guess is that they got there before this feature was implemented. –  cwallenpoole Jul 13 '11 at 12:37

Yes, that's a regrettably common edit. But it seems to me that this feature already exists...

For starters, inline editing is now supported across the entire Stack Exchange network (for those with edit privileges), so all you have to do is click the "edit" link underneath the offending question and the markdown editor will appear right where the question text used to be.

Then, you select (highlight) the code block you want to format, and click the "Code Sample" button in the editing toolbar. On Stack Overflow, it looks like a pair of curly braces ({}). This automatically inserts the additional 4 spaces in front of each line, no extra effort required. (Alternatively, of course, you can also press Ctrl+K if you're among the enlightened folks who know just how much more productive using keyboard shortcuts can be.)

   Click the icon with the curly braces

And you're done!

share|improve this answer
    
I don't mean inline editing. I mean one step further. Add that button to the actual screen itself (without the need to enter into the edit mode). Yes, it is very lazy feature, but it would be a definite nicety –  cwallenpoole Jul 13 '11 at 12:13
    
@cwallenpoole: Hmm... If we did that, what would prevent people from making accidental edits? And if we're going to add the code format button, why not add the rest of them, too? Why should we stop there? Other types of edits are common. –  Cody Gray Jul 13 '11 at 12:15
    
(Personally, I use CTRL+K and not the mouse button while editting) Other edits are common too, but my guess is that, on StackOverflow at least, this one is more common. I say this because it is needed there more than the other StackExchange sites... but I've no statistics, so I can't really back that up with anything save anecdote. As to accidental edits, it would take two separate gestures to accomplish this edit, often this involves scrolling as well. –  cwallenpoole Jul 13 '11 at 12:20

You must log in to answer this question.

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