diff --git a/pmd-emacs/CHANGELOG b/pmd-emacs/CHANGELOG index 3cae7fba15..6c4d9e2b7c 100644 --- a/pmd-emacs/CHANGELOG +++ b/pmd-emacs/CHANGELOG @@ -1,3 +1,6 @@ +Version 0.2 - + +Completely rewritten by John Russell. Version 0.1 - diff --git a/pmd-emacs/src/elisp/pmd.el b/pmd-emacs/src/elisp/pmd.el index 122bc904da..ca6b7ac1f5 100755 --- a/pmd-emacs/src/elisp/pmd.el +++ b/pmd-emacs/src/elisp/pmd.el @@ -1,3 +1,54 @@ +;;; pmd.el --- Major mode for pluging PMD into Emacs. + +;; Author: John Russell +;; Maintainer: John Russell +;; Created: Dec 30 2002 +;; Version: $Revision$ +;; Keywords: PMD major-mode + +;; Copyright (C) 2002 John Russell + +;; This program 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. + +;; This program 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. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: +;; Installation: +;; add this line to your .emacs file: +;; (autoload 'pmd-current-buffer "pmd" "PMD Mode" t) +;; once this is done, you can call the pmd-current-buffer function +;; using C-x or bind it to a key sequence. + +;; NOTE: This requies the xml parser in xml.el. This is distributed +;; with the standard Gnu Emacs 21.x release. + +;; Configuration: +;; Most user variables can be customized through standard +;; customization buffers. Type: +;; M-x pmd-customize +;; --or-- +;; M-x customize-group +;; pmd + +;; Description: +;; This mode is similar to the compilation buffer found in the +;; JDE. When you run pmd-current-buffer on a .java file, it runs +;; the PMD tool (http://pmd.sourceforge.net/) on the file with +;; the rulesets defined in pmd-rulesets. + +;; Type ? in the *PMD* buffer for a list of key bindings for +;; pmd-mode and usage help. +(require 'xml) (defgroup pmd nil "PMD" :group 'emacs) @@ -13,18 +64,202 @@ :group 'pmd) (defcustom pmd-rulesets "rulesets/basic.xml" - "Rulesets to apply" + "A comma delimited list of Rulesets to apply" :type 'string :group 'pmd) +(defcustom pmd-append-output 'nil + "If non-nil, append each output to the end of the *PMD* buffer, +else clear buffer each time." + :type 'boolean + :group 'pmd) + +(defvar pmd-mode-font-lock-keywords + (list ;;fontlock keywords + (list "\\(PMD output for\\) \\(.*$\\)" + '(1 font-lock-type-face append) + '(1 'bold append) + '(2 font-lock-function-name-face append)) + (list "\\(\\)" + '(1 font-lock-variable-name-face append)) + (list "\\(^[^<].*\\)" + '(1 font-lock-warning-face append)) + )) + +;;set up keymap +(if (and nil pmd-mode-map) + () + (setq pmd-mode-map (make-sparse-keymap)) + + (let ((key ?1)) + (while (<= key ?9) + (define-key pmd-mode-map (char-to-string key) +'digit-argument) + (setq key (1+ key)))) + (define-key pmd-mode-map "c" 'pmd-clear-display) + (define-key pmd-mode-map "q" 'pmd-quit) + (define-key pmd-mode-map "Q" 'pmd-quit-kill) + (define-key pmd-mode-map "p" 'pmd-prev-violation) + (define-key pmd-mode-map [up] 'pmd-prev-violation) + (define-key pmd-mode-map [?\C-p] 'pmd-prev-violation) + (define-key pmd-mode-map "n" 'pmd-next-violation) + (define-key pmd-mode-map [down] 'pmd-next-violation) + (define-key pmd-mode-map [?\C-n] 'pmd-next-violation) + (define-key pmd-mode-map "?" 'pmd-help) + (define-key pmd-mode-map [?\C-x ?`] 'pmd-goto-next-violation) + (define-key pmd-mode-map [?\C-m] 'pmd-goto-violation) + ) + +(defun pmd-mode () + "Plugin for PMD (http://pmd.sourceforge.net). Opens a buffer which \ +displays xml output of PMD when run on the Java file in the current buffer. + +Function Description Keybinding +\\[pmd-next-violation] -- Move point to next violation. n | up +\\[pmd-prev-violation] -- Move point to previous violation. p | down +\\[pmd-quit] -- Bury *PMD* buffer. q +\\[pmd-quit-kill] -- Kill *PMD* buffer Q +\\[pmd-goto-violation] -- Go to the source code matching this violation. RET +\\[pmd-goto-next-violation] -- Go to the source code matching violation after point C-x ` +\\[pmd-clear-display] -- Clear *PMD* buffer (for append mode) c" + (interactive) + (kill-all-local-variables) + (use-local-map pmd-mode-map) + (make-local-variable 'font-lock-defaults) + (make-local-variable 'font-lock-verbose) + (setq major-mode 'pmd-mode + mode-name "PMD Mode" + font-lock-defaults '(pmd-mode-font-lock-keywords) + font-lock-verbose nil + ;buffer-read-only t + truncate-lines nil)) + +;;------------------------- +;;Inner workings +;;------------------------- + +(defun pmd-help () + "Help for `pmd-mode'." + (interactive) + (describe-function 'pmd-mode)) + + +(defun pmd-goto-violation () + "Goto the line of the file in which the violation +on the current +line is found." + (interactive) + (block pmd-goto + ;(setq pmd-original-point (point)) + (cond ((not (search-backward "