summaryrefslogtreecommitdiff
path: root/elisp/pylint.el
blob: 01d15f125211fc13b2ffd97ba1e6da9aa3451fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;; Fixed bug where py-mode-map is undefined in Gnu Emacs 22 and 23
;; Yuen Ho Wong (2009)
;;
;; Modifications done by Yarosav O. Halchenko (2008):
;;  - enable user-visible variables
;; distributed under the same copyright/license terms as
;; pylint itself
;;
(require 'compile)

;; user definable variables
;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

(defgroup pylint nil
  "Emacs support for the Pylint Python checker"
  :group 'languages
  :prefix "pylint-")

(defcustom pylint-options "--output-format=parseable"
  "*Command line options to be used with pylint call"
  :type 'string
  :group 'pylint)


;; adapted from pychecker for pylint
(defun pylint-python-hook ()
  (defun pylint ()
    "Run pylint against the file behind the current buffer after
    checking if unsaved buffers should be saved."

    (interactive)
    (let* ((file (buffer-file-name (current-buffer)))
           (command (concat "pylint " pylint-options " \"" file "\"")))
      (save-some-buffers (not compilation-ask-about-save) nil) ; save  files.
      (compilation-start command)))

  (let ((python-mode-map (cond ((boundp 'py-mode-map) py-mode-map)
                               ((boundp 'python-mode-map) python-mode-map))))

    ;; shortcuts in the tradition of python-mode and ropemacs
    (define-key python-mode-map (kbd "C-c m l") 'pylint)
    (define-key python-mode-map (kbd "C-c m p") 'previous-error)
    (define-key python-mode-map (kbd "C-c m n") 'next-error)

    (define-key
      python-mode-map
      [menu-bar Python pylint-separator]
      '("--" . pylint-seperator))

    (define-key
      python-mode-map
      [menu-bar Python next-error]
      '("Next error" . next-error))
    (define-key
      python-mode-map
      [menu-bar Python prev-error]
      '("Previous error" . previous-error))
    (define-key
      python-mode-map
      [menu-bar Python lint]
      '("Pylint" . pylint))
    ))

(add-hook 'python-mode-hook 'pylint-python-hook)