I'd like to autoformat my python code from the buffer that contains it with a key.
I was looking at this tutorial. One can autoformat the code from the terminal with the command:
autopep8 --in-place --aggressive --aggressive <filename>
I tested it and it works. I'd like to have that bound to a key. The tutorial provides the code:
(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)))
that added to my
.emacs file, but when I try
Ctrl C - Ctrl A I get the error:
Wrong type argument: commandp, python-auto-format.
Reading the first answer of this question, they suggest the problem in their case might be that the snippet is for an older version of emacs. I suspect the problem here is the same as the tutorial is from 2015. I have no idea how to modify that code, so that it binds
Ctrl C - Ctrl A to the code autoformatting.