2009-08-31 05:59:47 +00:00
|
|
|
;; Fixed bug where py-mode-map is undefined in Gnu Emacs 22 and 23
|
|
|
|
;; Yuen Ho Wong (2009)
|
2008-03-27 11:16:00 +00:00
|
|
|
;;
|
|
|
|
;; 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)
|
|
|
|
|
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
;; adapted from pychecker for pylint
|
2007-07-04 12:06:21 +00:00
|
|
|
(defun pylint-python-hook ()
|
2006-04-26 10:48:09 +00:00
|
|
|
(defun pylint ()
|
|
|
|
"Run pylint against the file behind the current buffer after
|
|
|
|
checking if unsaved buffers should be saved."
|
2009-08-31 05:59:47 +00:00
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
(interactive)
|
|
|
|
(let* ((file (buffer-file-name (current-buffer)))
|
2009-08-31 05:59:47 +00:00
|
|
|
(command (concat "pylint " pylint-options " \"" file "\"")))
|
2006-04-26 10:48:09 +00:00
|
|
|
(save-some-buffers (not compilation-ask-about-save) nil) ; save files.
|
2009-08-31 05:59:47 +00:00
|
|
|
(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)
|
|
|
|
|
2010-03-23 13:36:53 +00:00
|
|
|
(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))
|
|
|
|
))
|
2009-08-31 05:59:47 +00:00
|
|
|
))
|
2006-04-26 10:48:09 +00:00
|
|
|
|
2007-07-04 12:06:21 +00:00
|
|
|
(add-hook 'python-mode-hook 'pylint-python-hook)
|