title: Is there any way to format a complete python buffer in emacs with a key press?
body: <p>I am looking for any way to have Emacs format a Python buffer by hitting a few keys.  By format, I mean:</p>
  
  <ol>
  <li>Replace tabs with 4 spaces</li>
  <li>Wrap all long lines correctly at 79 chars.  This includes wrapping &amp; concatenating long strings, wrapping long comments, wrapping lists, function headers, etc.</li>
  <li>Unrelated, but when I hit enter, it'd be nice if the cursor was tabbed in automatically.</li>
  </ol>
  
  <p>In general I'd like to just format everything according to PEP 8.</p>
  
  <p>I've looked for a pretty printer / code beautifier / code formatter for Python to run the buffer through, but can't find an open source one.</p>
  
  <p>My .emacs is <a href="http://dpaste.com/hold/81704/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>For those who are going to answer "You don't need a formatter for Python, it's beautiful by the nature of the language," I say to you that this is not correct.  In real software systems, comments should be auto-wrapped for you, strings are going to be longer than 79 characters, tab levels run 3+ deep.  Please just help me solve my issue directly without some philosophical discussion about the merits of formatting Python source.</p>