Skip to content

Instantly share code, notes, and snippets.

@ChillarAnand
Last active August 29, 2015 14:21
Show Gist options
  • Save ChillarAnand/0e8c8351799cdd7254d7 to your computer and use it in GitHub Desktop.
Save ChillarAnand/0e8c8351799cdd7254d7 to your computer and use it in GitHub Desktop.
autopep8
(defcustom python-autopep8-path (executable-find "autopep8")
"autopep8 executable path."
:group 'python
:type 'string)
(defun python-autopep8 ()
"Automatically formats Python code to conform to the PEP 8 style guide.
$ autopep8 --in-place --aggressive --aggressive <filename>"
(interactive)
(when (eq major-mode 'python-mode)
(shell-command
(format "%s --in-place --aggressive %s" python-autopep8-path
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t)))
(bind-key "C-c C-a" 'python-auto-format)
(eval-after-load 'python
'(if python-autopep8-path
(add-hook 'before-save-hook 'python-autopep8)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment