summaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
authorjpkotta <jpkotta@shannon>2012-11-12 13:35:48 +0100
committerjpkotta <jpkotta@shannon>2012-11-12 13:35:48 +0100
commit4a0c3e35bdde3f6218464242dc5c37c94126d236 (patch)
tree1c3d31c1977641bacecec8a1a123385fb7670354 /elisp
parentcaa8c7a4e7cf38532ae4475799f49809df091a6a (diff)
downloadpylint-4a0c3e35bdde3f6218464242dc5c37c94126d236.tar.gz
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.
Diffstat (limited to 'elisp')
-rw-r--r--elisp/pylint.el193
1 files changed, 138 insertions, 55 deletions
diff --git a/elisp/pylint.el b/elisp/pylint.el
index 0941a8b..09c22e6 100644
--- a/elisp/pylint.el
+++ b/elisp/pylint.el
@@ -1,68 +1,151 @@
-;; Fixed bug where py-mode-map is undefined in Gnu Emacs 22 and 23
-;; Yuen Ho Wong (2009)
+;;; pylint.el --- minor mode for running `pylint'
+
+;; Copyright (c) 2009, 2010 Ian Eure <ian.eure@gmail.com>
+
+;; Author: Ian Eure <ian.eure@gmail.com>
+
+;; Keywords: languages python
+;; Version: 1.01
+
+;; pylint.el is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by the Free
+;; Software Foundation; either version 2, or (at your option) any later
+;; version.
;;
-;; Modifications done by Yarosav O. Halchenko (2008):
-;; - enable user-visible variables
-;; distributed under the same copyright/license terms as
-;; pylint itself
+;; It is distributed in the hope that it will be useful, but WITHOUT ANY
+;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+;; details.
;;
-(require 'compile)
+;; You should have received a copy of the GNU General Public License along
+;; with your copy of Emacs; see the file COPYING. If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Commentary:
+;;
+;; Specialized compile mode for pylint. You may want to add the
+;; following to your init.el:
+;;
+;; (autoload 'pylint "pylint")
+;; (add-hook 'python-mode-hook 'pylint-add-menu-items)
+;; (add-hook 'python-mode-hook 'pylint-add-key-bindings)
+
+;;; Code:
-;; user definable variables
-;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
+(require 'compile)
(defgroup pylint nil
- "Emacs support for the Pylint Python checker"
- :group 'languages
- :prefix "pylint-")
+ "Minor mode for running the Pylint Python checker"
+ :prefix "pylint-"
+ :group 'tools
+ :group 'languages)
+
+(defvar pylint-last-buffer nil
+ "The most recent PYLINT buffer.
+A PYLINT buffer becomes most recent when you select PYLINT mode in it.
+Notice that using \\[next-error] or \\[compile-goto-error] modifies
+`complation-last-buffer' rather than `pylint-last-buffer'.")
+
+(defconst pylint-regexp-alist
+ (let ((base "^\\(.*\\):\\([0-9]+\\):\s+\\(\\[%s.*\\)$"))
+ (list
+ (list (format base "[FE]") 1 2)
+ (list (format base "[RWC]") 1 2 nil 1)))
+ "Regexp used to match PYLINT hits. See `compilation-error-regexp-alist'.")
-(defcustom pylint-options "--output-format=parseable"
- "*Command line options to be used with pylint call"
- :type 'string
+(defcustom pylint-options '("--reports=n" "--output-format=parseable")
+ "Options to pass to pylint.py"
+ :type '(repeat string)
:group 'pylint)
+(defcustom pylint-command "pylint"
+ "PYLINT command."
+ :type '(file)
+ :group 'pylint)
+
+(defcustom pylint-ask-about-save nil
+ "Non-nil means \\[pylint] asks which buffers to save before compiling.
+Otherwise, it saves all modified buffers without asking."
+ :type 'boolean
+ :group 'pylint)
+
+(define-compilation-mode pylint-mode "PYLINT"
+ (setq pylint-last-buffer (current-buffer))
+ (set (make-local-variable 'compilation-error-regexp-alist)
+ pylint-regexp-alist)
+ (set (make-local-variable 'compilation-disable-input) t))
+
+(defvar pylint-mode-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map compilation-minor-mode-map)
+ (define-key map " " 'scroll-up)
+ (define-key map "\^?" 'scroll-down)
+ (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
+
+ (define-key map "\r" 'compile-goto-error) ;; ?
+ (define-key map "n" 'next-error-no-select)
+ (define-key map "p" 'previous-error-no-select)
+ (define-key map "{" 'compilation-previous-file)
+ (define-key map "}" 'compilation-next-file)
+ (define-key map "\t" 'compilation-next-error)
+ (define-key map [backtab] 'compilation-previous-error)
+ map)
+ "Keymap for PYLINT buffers.
+`compilation-minor-mode-map' is a cdr of this.")
-;; 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."
+;;;###autoload
+(defun pylint ()
+ "Run PYLINT, and collect output in a buffer, much like `compile'.
- (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)))
+While pylint runs asynchronously, you can use \\[next-error] (M-x next-error),
+or \\<pylint-mode-map>\\[compile-goto-error] in the grep \
+output buffer, to go to the lines where pylint found matches.
- (let ((python-mode-map (cond ((boundp 'py-mode-map) py-mode-map)
- ((boundp 'python-mode-map) python-mode-map))))
+\\{pylint-mode-map}"
+ (interactive)
+
+ (save-some-buffers (not pylint-ask-about-save) nil)
+ (let* ((tramp (tramp-tramp-file-p (buffer-file-name)))
+ (file (or (and tramp
+ (aref (tramp-dissect-file-name (buffer-file-name)) 3))
+ (buffer-file-name)))
+ (command (mapconcat
+ 'identity
+ (list pylint-command
+ (mapconcat 'identity pylint-options " ")
+ (comint-quote-filename file)) " ")))
+
+ (compilation-start command 'pylint-mode)))
+
+;;;###autoload
+(defun pylint-add-key-bindings ()
+ (let ((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)
-
- (let ((map))
- (if(boundp 'py-mode-map)
- (setq map py-mode-map)
- (setq map python-mode-map)
- (define-key
- map
- [menu-bar Python pylint-separator]
- '("--" . pylint-seperator))
- (define-key
- map
- [menu-bar Python next-error]
- '("Next error" . next-error))
- (define-key
- map
- [menu-bar Python prev-error]
- '("Previous error" . previous-error))
- (define-key
- map
- [menu-bar Python lint]
- '("Pylint" . pylint))
- ))
- ))
-
-(add-hook 'python-mode-hook 'pylint-python-hook)
+ (define-key map (kbd "C-c m l") 'pylint)
+ (define-key map (kbd "C-c m p") 'previous-error)
+ (define-key map (kbd "C-c m n") 'next-error)
+ nil))
+
+;;;###autoload
+(defun pylint-add-menu-items ()
+ (let ((map (cond
+ ((boundp 'py-mode-map) py-mode-map)
+ ((boundp 'python-mode-map) python-mode-map))))
+
+ (define-key map [menu-bar Python pylint-separator]
+ '("--" . pylint-seperator))
+ (define-key map [menu-bar Python next-error]
+ '("Next error" . next-error))
+ (define-key map [menu-bar Python prev-error]
+ '("Previous error" . previous-error))
+ (define-key map [menu-bar Python lint]
+ '("Pylint" . pylint))
+ nil))
+
+(provide 'pylint)
+
+;;; pylint.el ends here