Advertisement
Guest User

python-pylint.el

a guest
Apr 4th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. ;;; python-pylint.el --- minor mode for running `pylint'
  2.  
  3. ;; Copyright (c) 2009, 2010 Ian Eure <ian.eure@gmail.com>
  4.  
  5. ;; Author: Ian Eure <ian.eure@gmail.com>
  6.  
  7. ;; Keywords: languages python
  8. ;; Last edit: 2010-02-12
  9. ;; Version: 1.01
  10.  
  11. ;; python-pylint.el is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by the Free
  13. ;; Software Foundation; either version 2, or (at your option) any later
  14. ;; version.
  15. ;;
  16. ;; It is distributed in the hope that it will be useful, but WITHOUT ANY
  17. ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  19. ;; details.
  20. ;;
  21. ;; You should have received a copy of the GNU General Public License along
  22. ;; with your copy of Emacs; see the file COPYING. If not, write to the Free
  23. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. ;; 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27. ;;
  28. ;; (autoload 'python-pylint "python-pylint")
  29. ;; (autoload 'pylint "python-pylint")
  30. ;;
  31. ;;; Code:
  32.  
  33. (defgroup python-pylint nil
  34. "Minor mode for running pylint"
  35. :prefix "python-pylint-"
  36. :group 'tools)
  37.  
  38. (defvar python-pylint-last-buffer nil
  39. "The most recent PYLINT buffer.
  40. A PYLINT buffer becomes most recent when you select PYLINT mode in it.
  41. Notice that using \\[next-error] or \\[compile-goto-error] modifies
  42. `complation-last-buffer' rather than `python-pylint-last-buffer'.")
  43.  
  44. (defconst python-pylint-regexp-alist
  45. (let ((base "^\\(.*\\):\\([0-9]+\\):\s+\\(\\[%s.*\\)$"))
  46. (list
  47. (list (format base "[FE]") 1 2)
  48. (list (format base "[RWC]") 1 2 nil 1)))
  49. "Regexp used to match PYLINT hits. See `compilation-error-regexp-alist'.")
  50.  
  51. (defcustom python-pylint-options '("-rn" "-f parseable")
  52. "Options to pass to pylint.py"
  53. :type '(repeat string)
  54. :group 'python-pylint)
  55.  
  56. (defcustom python-pylint-command "pylint"
  57. "PYLINT command."
  58. :type '(file)
  59. :group 'python-pylint)
  60.  
  61. (defcustom python-pylint-ask-about-save nil
  62. "Non-nil means \\[python-pylint] asks which buffers to save before compiling.
  63. Otherwise, it saves all modified buffers without asking."
  64. :type 'boolean
  65. :group 'python-pylint)
  66.  
  67. (define-compilation-mode python-pylint-mode "PYLINT"
  68. (setq python-pylint-last-buffer (current-buffer))
  69. (set (make-local-variable 'compilation-error-regexp-alist)
  70. python-pylint-regexp-alist)
  71. (set (make-local-variable 'compilation-disable-input) t))
  72.  
  73. (defvar python-pylint-mode-map
  74. (let ((map (make-sparse-keymap)))
  75. (set-keymap-parent map compilation-minor-mode-map)
  76. (define-key map " " 'scroll-up)
  77. (define-key map "\^?" 'scroll-down)
  78. (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
  79.  
  80. (define-key map "\r" 'compile-goto-error) ;; ?
  81. (define-key map "n" 'next-error-no-select)
  82. (define-key map "p" 'previous-error-no-select)
  83. (define-key map "{" 'compilation-previous-file)
  84. (define-key map "}" 'compilation-next-file)
  85. (define-key map "\t" 'compilation-next-error)
  86. (define-key map [backtab] 'compilation-previous-error)
  87. map)
  88. "Keymap for PYLINT buffers.
  89. `compilation-minor-mode-map' is a cdr of this.")
  90.  
  91. ;;;###autoload
  92. (defun python-pylint ()
  93. "Run PYLINT, and collect output in a buffer.
  94. While pylint runs asynchronously, you can use \\[next-error] (M-x next-error),
  95. or \\<python-pylint-mode-map>\\[compile-goto-error] in the grep \
  96. output buffer, to go to the lines where pylint found matches."
  97. (interactive)
  98.  
  99. (save-some-buffers (not python-pylint-ask-about-save) nil)
  100. (let* ((tramp (tramp-tramp-file-p (buffer-file-name)))
  101. (file (or (and tramp
  102. (aref (tramp-dissect-file-name (buffer-file-name)) 3))
  103. (buffer-file-name)))
  104. (command (mapconcat
  105. 'identity
  106. (list python-pylint-command
  107. (mapconcat 'identity python-pylint-options " ")
  108. (comint-quote-filename file)) " ")))
  109.  
  110. (compilation-start command 'python-pylint-mode)))
  111.  
  112. ;;;###autoload
  113. (defun python-pylint-all ()
  114. "Run PYLINT, and collect output in a buffer.
  115. While pylint runs asynchronously, you can use \\[next-error] (M-x next-error),
  116. or \\<python-pylint-mode-map>\\[compile-goto-error] in the grep \
  117. output buffer, to go to the lines where pylint found matches."
  118. (interactive)
  119.  
  120. (let* ((command (mapconcat
  121. 'identity
  122. (list python-pylint-command
  123. (mapconcat 'identity python-pylint-options " ")
  124. ) " ")))
  125.  
  126. (compilation-start command 'python-pylint-mode)))
  127.  
  128.  
  129. ;;;###autoload
  130. (defalias 'pylint 'python-pylint)
  131.  
  132. (provide 'python-pylint)
  133.  
  134. ;;; python-pylint.el ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement