Replace pylint.el with Ian Eure's version. Closes #20693

Changes:

No longer unconditionally adds a function to python-mode-hook. Split the hook functions into a key binding one and a menu one. Added to the Tools customization group. pylint-options is now a list of strings. This makes it easier to add and remove individual options. Turn off reports by default. Allow for a nonstandard pylint executable name with pylint-command. Allow for unconditionally saving files before running (default is ask). Prettier colors in the output buffer. Make it work well with tramp. Make it compatible with package.el.

authorjpkotta@shannon
changeset83dc19b76886
branchdefault
phasepublic
hiddenno
parent revision#1b2d31a41778 Fix ChangeLog for 0.26.0
child revision#73472a5cb03a Change the regular expression for inline options so that a preceeding # is not optional.
files modified by this revision
ChangeLog
elisp/pylint.el
# HG changeset patch
# User jpkotta@shannon
# Date 1352723748 -3600
# Mon Nov 12 13:35:48 2012 +0100
# Node ID 83dc19b76886c62947c87c91c3ced3200f85920c
# Parent 1b2d31a417780fdaaa288303d005b4ae6e3260fe
Replace pylint.el with Ian Eure's version. Closes #20693

Changes:

No longer unconditionally adds a function to python-mode-hook.
Split the hook functions into a key binding one and a menu one.
Added to the Tools customization group.
pylint-options is now a list of strings. This makes it easier to add and remove individual options.
Turn off reports by default.
Allow for a nonstandard pylint executable name with pylint-command.
Allow for unconditionally saving files before running (default is ask).
Prettier colors in the output buffer.
Make it work well with tramp.
Make it compatible with package.el.

diff --git a/ChangeLog b/ChangeLog
@@ -1,12 +1,16 @@
1  ChangeLog for PyLint
2  ====================
3 
4  --
5 -    * add support for --disable=all option (#105327)
6 +
7 +    * #20693: replace pylint.el by Ian Eure version (patch by J.Kotta)
8 
9 -    * deprecate the 'disable-all' inline directive in favour of 'skip-file'
10 +    * #105327: add support for --disable=all option and deprecate the
11 +      'disable-all' inline directive in favour of 'skip-file' (patch by
12 +      A.Fayolle)
13 +
14 
15  2012-10-05  --  0.26.0
16      * #106534: add --ignore-imports option to code similarity checking
17        and 'symilar' command line tool (patch by Ry4an Brase)
18 
diff --git a/elisp/pylint.el b/elisp/pylint.el
@@ -1,68 +1,151 @@
19 -;; Fixed bug where py-mode-map is undefined in Gnu Emacs 22 and 23
20 -;; Yuen Ho Wong (2009)
21 +;;; pylint.el --- minor mode for running `pylint'
22 +
23 +;; Copyright (c) 2009, 2010 Ian Eure <ian.eure@gmail.com>
24 +
25 +;; Author: Ian Eure <ian.eure@gmail.com>
26 +
27 +;; Keywords: languages python
28 +;; Version: 1.01
29 +
30 +;; pylint.el is free software; you can redistribute it and/or modify it
31 +;; under the terms of the GNU General Public License as published by the Free
32 +;; Software Foundation; either version 2, or (at your option) any later
33 +;; version.
34  ;;
35 -;; Modifications done by Yarosav O. Halchenko (2008):
36 -;;  - enable user-visible variables
37 -;; distributed under the same copyright/license terms as
38 -;; pylint itself
39 +;; It is distributed in the hope that it will be useful, but WITHOUT ANY
40 +;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
41 +;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
42 +;; details.
43  ;;
44 +;; You should have received a copy of the GNU General Public License along
45 +;; with your copy of Emacs; see the file COPYING.  If not, write to the Free
46 +;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
47 +;; 02111-1307, USA.
48 +
49 +;;; Commentary:
50 +;;
51 +;; Specialized compile mode for pylint.  You may want to add the
52 +;; following to your init.el:
53 +;;
54 +;;   (autoload 'pylint "pylint")
55 +;;   (add-hook 'python-mode-hook 'pylint-add-menu-items)
56 +;;   (add-hook 'python-mode-hook 'pylint-add-key-bindings)
57 +
58 +;;; Code:
59 +
60  (require 'compile)
61 
62 -;; user definable variables
63 -;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
64 +(defgroup pylint nil
65 +  "Minor mode for running the Pylint Python checker"
66 +  :prefix "pylint-"
67 +  :group 'tools
68 +  :group 'languages)
69 +
70 +(defvar pylint-last-buffer nil
71 +  "The most recent PYLINT buffer.
72 +A PYLINT buffer becomes most recent when you select PYLINT mode in it.
73 +Notice that using \\[next-error] or \\[compile-goto-error] modifies
74 +`complation-last-buffer' rather than `pylint-last-buffer'.")
75 
76 -(defgroup pylint nil
77 -  "Emacs support for the Pylint Python checker"
78 -  :group 'languages
79 -  :prefix "pylint-")
80 +(defconst pylint-regexp-alist
81 +  (let ((base "^\\(.*\\):\\([0-9]+\\):\s+\\(\\[%s.*\\)$"))
82 +    (list
83 +     (list (format base "[FE]") 1 2)
84 +     (list (format base "[RWC]") 1 2 nil 1)))
85 +  "Regexp used to match PYLINT hits.  See `compilation-error-regexp-alist'.")
86 
87 -(defcustom pylint-options "--output-format=parseable"
88 -  "*Command line options to be used with pylint call"
89 -  :type 'string
90 +(defcustom pylint-options '("--reports=n" "--output-format=parseable")
91 +  "Options to pass to pylint.py"
92 +  :type '(repeat string)
93 +  :group 'pylint)
94 +
95 +(defcustom pylint-command "pylint"
96 +  "PYLINT command."
97 +  :type '(file)
98 +  :group 'pylint)
99 +
100 +(defcustom pylint-ask-about-save nil
101 +  "Non-nil means \\[pylint] asks which buffers to save before compiling.
102 +Otherwise, it saves all modified buffers without asking."
103 +  :type 'boolean
104    :group 'pylint)
105 
106 +(define-compilation-mode pylint-mode "PYLINT"
107 +  (setq pylint-last-buffer (current-buffer))
108 +  (set (make-local-variable 'compilation-error-regexp-alist)
109 +       pylint-regexp-alist)
110 +  (set (make-local-variable 'compilation-disable-input) t))
111 
112 -;; adapted from pychecker for pylint
113 -(defun pylint-python-hook ()
114 -  (defun pylint ()
115 -    "Run pylint against the file behind the current buffer after
116 -    checking if unsaved buffers should be saved."
117 +(defvar pylint-mode-map
118 +  (let ((map (make-sparse-keymap)))
119 +    (set-keymap-parent map compilation-minor-mode-map)
120 +    (define-key map " " 'scroll-up)
121 +    (define-key map "\^?" 'scroll-down)
122 +    (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
123 +
124 +    (define-key map "\r" 'compile-goto-error)  ;; ?
125 +    (define-key map "n" 'next-error-no-select)
126 +    (define-key map "p" 'previous-error-no-select)
127 +    (define-key map "{" 'compilation-previous-file)
128 +    (define-key map "}" 'compilation-next-file)
129 +    (define-key map "\t" 'compilation-next-error)
130 +    (define-key map [backtab] 'compilation-previous-error)
131 +    map)
132 +  "Keymap for PYLINT buffers.
133 +`compilation-minor-mode-map' is a cdr of this.")
134 
135 -    (interactive)
136 -    (let* ((file (buffer-file-name (current-buffer)))
137 -           (command (concat "pylint " pylint-options " \"" file "\"")))
138 -      (save-some-buffers (not compilation-ask-about-save) nil) ; save  files.
139 -      (compilation-start command)))
140 +;;;###autoload
141 +(defun pylint ()
142 +  "Run PYLINT, and collect output in a buffer, much like `compile'.
143 +
144 +While pylint runs asynchronously, you can use \\[next-error] (M-x next-error),
145 +or \\<pylint-mode-map>\\[compile-goto-error] in the grep \
146 +output buffer, to go to the lines where pylint found matches.
147 +
148 +\\{pylint-mode-map}"
149 +  (interactive)
150 
151 -  (let ((python-mode-map (cond ((boundp 'py-mode-map) py-mode-map)
152 -                               ((boundp 'python-mode-map) python-mode-map))))
153 +  (save-some-buffers (not pylint-ask-about-save) nil)
154 +  (let* ((tramp (tramp-tramp-file-p (buffer-file-name)))
155 +         (file (or (and tramp
156 +                        (aref (tramp-dissect-file-name (buffer-file-name)) 3))
157 +                   (buffer-file-name)))
158 +         (command (mapconcat
159 +                   'identity
160 +                   (list pylint-command
161 +                         (mapconcat 'identity pylint-options " ")
162 +                         (comint-quote-filename file)) " ")))
163 +
164 +    (compilation-start command 'pylint-mode)))
165 +
166 +;;;###autoload
167 +(defun pylint-add-key-bindings ()
168 +  (let ((map (cond
169 +              ((boundp 'py-mode-map) py-mode-map)
170 +              ((boundp 'python-mode-map) python-mode-map))))
171 
172      ;; shortcuts in the tradition of python-mode and ropemacs
173 -    (define-key python-mode-map (kbd "C-c m l") 'pylint)
174 -    (define-key python-mode-map (kbd "C-c m p") 'previous-error)
175 -    (define-key python-mode-map (kbd "C-c m n") 'next-error)
176 +    (define-key map (kbd "C-c m l") 'pylint)
177 +    (define-key map (kbd "C-c m p") 'previous-error)
178 +    (define-key map (kbd "C-c m n") 'next-error)
179 +    nil))
180 
181 -  (let ((map))
182 -    (if(boundp 'py-mode-map)
183 -        (setq map py-mode-map)
184 -      (setq map python-mode-map)
185 -      (define-key
186 -        map
187 -        [menu-bar Python pylint-separator]
188 -        '("--" . pylint-seperator))
189 -      (define-key
190 -        map
191 -        [menu-bar Python next-error]
192 -        '("Next error" . next-error))
193 -      (define-key
194 -        map
195 -        [menu-bar Python prev-error]
196 -        '("Previous error" . previous-error))
197 -      (define-key
198 -        map
199 -        [menu-bar Python lint]
200 -        '("Pylint" . pylint))
201 -      ))
202 -    ))
203 +;;;###autoload
204 +(defun pylint-add-menu-items ()
205 +  (let ((map (cond
206 +              ((boundp 'py-mode-map) py-mode-map)
207 +              ((boundp 'python-mode-map) python-mode-map))))
208 +  
209 +    (define-key map [menu-bar Python pylint-separator]
210 +      '("--" . pylint-seperator))
211 +    (define-key map [menu-bar Python next-error]
212 +      '("Next error" . next-error))
213 +    (define-key map [menu-bar Python prev-error]
214 +      '("Previous error" . previous-error))
215 +    (define-key map [menu-bar Python lint]
216 +      '("Pylint" . pylint))
217 +    nil))
218 
219 -(add-hook 'python-mode-hook 'pylint-python-hook)
220 +(provide 'pylint)
221 +
222 +;;; pylint.el ends here