title: Atom auto indentation script ruins Python indentation
body: <p>I wrote this function in the init.coffee file for my Atom config to auto indent an entire file:</p>
  
  <pre><code>atom.commands.add 'body', 'custom:auto-format', -&gt;
      editor = atom.workspace.getActiveTextEditor();
  
      oldSelection = editor.getSelectedBufferRanges();
  
      editor.selectAll();
      editor.autoIndentSelectedRows();
  
      editor.setSelectedBufferRanges(oldSelection);
  </code></pre>
  
  <p>For every language EXCEPT Python, it works perfectly! I was very happy with the results. However, the CoffeeScript auto-indentation totally messes up with Phyton code.</p>
  
  <p>It takes this file:</p>
  
  <pre><code>import sys
  
  def factorial (n):
      if n == 1:
          return 1
      else:
          return n * factorial(n-1)
  
  if __name__ == "__main__":
      for arg in sys.argv[1:]:
          n = factorial(int(arg))
          print("The factorial of " + arg + " is " + str(n))
  </code></pre>
  
  <p>And is unable to recognize where the factorial function ends, and thus indents like this:</p>
  
  <pre><code>import sys
  
  def factorial (n):
      if n == 1:
          return 1
      else:
          return n * factorial(n-1)
  
          if __name__ == "__main__":
              for arg in sys.argv[1:]:
                  n = factorial(int(arg))
                  print("The factorial of " + arg + " is " + str(n))
  </code></pre>
  
  <p>If anyone has any insight into how to remedy this it would be greatly appreciated!</p>