Python buffers (that aren't tramp remote) will be highlighted by pyflakes and pep8. They have 'questionable' lines highlighted and error lines significantly highlighted. When you move the cursor into that section it should print the error message in the minibuffer; if there are two errors it will only print the first.
You can use the keychord M-n
and M-p
to go to the next and
previous error section; these are bound to
flymake-goto-{next,prev}-error
.
You can use the keychord C-c i
to ignore the error code on the
current line; M-x my-pyflakes-reset-ignore
will reset to ignoring none.
You can run the function M-x mypylint
to run the pylint version of
the code analysis. This tends to be similar but has slightly different
conditions. In the resulting buffer i
will ignore a message and
M-x mypylint-reset-ignore
will reset. The two lists are distinct
since the error messages are distinct.
I'm running emacs 24.3.50.1
which can be gotten with emacs-snapshot from:
sudo add-apt-repository ppa:cassou/emacs;
sudo aptitude update;
sudo aptitude install emacs-snapshot
This will all probably work with emacs 24.1, but I don't know. I've been running this emacs-snapshot branch for quite some time and can't recall being bitten by instability.
flake8 is the command that actually checks the code (pep8 + other)
Install the python packages
sudo pip install flake8 pylint
Install the emacs packages
M-x package-list-packages
Select
python-pylint
1.1flymake-python-pyflakes
0.8
and install (hit i
).
By default flymake will highlight lines that are erring, but does not
make it obvious what the error is. You have to do things like M-x flymake-goto-next-error
and M-x flymake-display-err-menu-for-current-line
.
Our solution is to define a small minor mode to make this easier.
Add mypylint.el
to your site-lisp
folder (i.e. in your load-path
somewhere) and add the following snippet to your emacs init.el
(or
appropriate settings file).
;;;; pyflakes
(autoload 'mypylint "mypylint")
(autoload 'my-flymake-minor-mode "mypylint")
(defun maybe-flymake-activate ()
(cond ((not (tramp-handle-file-remote-p (buffer-file-name)))
(message "Activating flymake-python-pyflakes")
(flymake-python-pyflakes-load)
(message "Activing custom navigation minor-mode.")
(my-flymake-minor-mode))
(t
(message "Skipping flymake on remote tramp buffer."))))
;;; maybe start pyflakes when we load python