|
| 1 | +Using Pylint through Flymake in Emacs |
| 2 | +===================================== |
| 3 | + |
| 4 | +To enable Flymake for Python, insert the following into your .emacs: |
| 5 | + |
| 6 | +.. sourcecode:: common-lisp |
| 7 | + |
| 8 | + ;; Configure Flymake for Python |
| 9 | + (when (load "flymake" t) |
| 10 | + (defun flymake-pylint-init () |
| 11 | + (let* ((temp-file (flymake-init-create-temp-buffer-copy |
| 12 | + 'flymake-create-temp-inplace)) |
| 13 | + (local-file (file-relative-name |
| 14 | + temp-file |
| 15 | + (file-name-directory buffer-file-name)))) |
| 16 | + (list "epylint" (list local-file)))) |
| 17 | + (add-to-list 'flymake-allowed-file-name-masks |
| 18 | + '("\\.py\\'" flymake-pylint-init))) |
| 19 | + |
| 20 | + ;; Set as a minor mode for Python |
| 21 | + (add-hook 'python-mode-hook '(lambda () (flymake-mode))) |
| 22 | + |
| 23 | +Above stuff is in ``pylint/elisp/pylint-flymake.el``, which should be automatically |
| 24 | +installed on Debian systems, in which cases you don't have to put it in your ``.emacs`` file. |
| 25 | + |
| 26 | +Other things you may find useful to set: |
| 27 | + |
| 28 | +.. sourcecode:: common-lisp |
| 29 | + |
| 30 | + ;; Configure to wait a bit longer after edits before starting |
| 31 | + (setq-default flymake-no-changes-timeout '3) |
| 32 | + |
| 33 | + ;; Keymaps to navigate to the errors |
| 34 | + (add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-cn" 'flymake-goto-next-error))) |
| 35 | + (add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-cp" 'flymake-goto-prev-error))) |
| 36 | + |
| 37 | + |
| 38 | +Finally, by default Flymake only displays the extra information about the error when you |
| 39 | +hover the mouse over the highlighted line. The following will use the minibuffer to display |
| 40 | +messages when you the cursor is on the line. |
| 41 | + |
| 42 | +.. sourcecode:: common-lisp |
| 43 | + |
| 44 | + ;; To avoid having to mouse hover for the error message, these functions make Flymake error messages |
| 45 | + ;; appear in the minibuffer |
| 46 | + (defun show-fly-err-at-point () |
| 47 | + "If the cursor is sitting on a Flymake error, display the message in the minibuffer" |
| 48 | + (require 'cl) |
| 49 | + (interactive) |
| 50 | + (let ((line-no (line-number-at-pos))) |
| 51 | + (dolist (elem flymake-err-info) |
| 52 | + (if (eq (car elem) line-no) |
| 53 | + (let ((err (car (second elem)))) |
| 54 | + (message "%s" (flymake-ler-text err))))))) |
| 55 | + |
| 56 | + (add-hook 'post-command-hook 'show-fly-err-at-point) |
| 57 | + |
| 58 | + |
| 59 | +Alternative, if you only wish to pollute the minibuffer after an explicit flymake-goto-* then use |
| 60 | +the following instead of a post-command-hook |
| 61 | + |
| 62 | +.. sourcecode:: common-lisp |
| 63 | + |
| 64 | + (defadvice flymake-goto-next-error (after display-message activate compile) |
| 65 | + "Display the error in the mini-buffer rather than having to mouse over it" |
| 66 | + (show-fly-err-at-point)) |
| 67 | + |
| 68 | + (defadvice flymake-goto-prev-error (after display-message activate compile) |
| 69 | + "Display the error in the mini-buffer rather than having to mouse over it" |
| 70 | + (show-fly-err-at-point)) |
0 commit comments