Hi Paul,

I just got around to trying out checkstyle from within emacs (usually
I run it from the command line). It works just great. I noticed that
it doesn't have the usual hooks to allow invoking a function after
it's finished (e.g. to automatically jump to the first error, or close
the window if there were no problems).

I've attached a patch that adds a jde-checkstyle-finish-hook. I've
made the default use jde-compile-finish-kill-buffer (although in
practise I use the following function which handles warnings and grep
output from my-grep-find too).


(defun my-jde-compile-finish-hook (buf str)
  "Removes the jde-compile window after a few seconds if there are no errors or
warnings. This function also handles grep output (see my-grep-find)."
  (save-excursion
    (set-buffer buf)
    (if (null (or (string-match ".*\([0-9]\+ matches found.*" (buffer-string))
                  (string-match ".*exited abnormally.*" str)
                  (string-match ".*error.*" (buffer-string)) 
                  (string-match ".*warning.*" (buffer-string)) 
                  (string-match ".*BUILD FAILED.*" (buffer-string))))
        ;;no errors, make the window go away in a few seconds
        (progn
          (run-at-time "1 sec" nil 'jde-compile-kill-buffer buf)
          (message "No messages"))
      ;;there were errors, so jump to the first error
      (next-error))))

;; Make grep-find act like the compilation regarding closing if no errors else jump to 
first match.
;; Uses my-jde-compile-finish-hook
(defun my-grep-find (&optional command-args)
  "Just like grep-find except the grep window closes if there were no matches.
If there are matches, jump to the first match."
  (interactive
   (list (read-shell-command "Run find (like this): "
                               grep-find-command 'grep-find-history)))
  (setq compilation-finish-function 
        (lambda (buf msg) 
          (my-jde-compile-finish-hook buf msg)
          (setq compilation-finish-function nil)))
  (grep-find command-args))


Cheers,
Len.


Attachment: checkstyle-finish.patch
Description: Binary data

Reply via email to