Hi,
I'm trying to create a compile hook that executes my java app/applet right
after I compiled it. This is what I came up with:
(defvar auto-run nil "my-jde-save-compile-run sets this to t. The
compilation hook runs the source only if this is true. Therefore, you can
still compile without having the source run automatically.")
(defvar my-java-buffer nil "The java source's buffer name.")
(defun my-jde-save-compile-run ()
"Compile and run the code."
(interactive)
;; If the buffer is modified, save and set my-java-buffer to the
;; current buffer.
(if (buffer-modified-p)
(save-excursion
(setq auto-run t)
(setq my-java-buffer (current-buffer))
(save-buffer)
(jde-compile)
(message "Saved. Compiling... "))
;;Else: if not modified simply run the app/applet.
(save-excursion
(message "Running... ")
(if (is-applet)
(jde-run-applet)
(jde-run))
)))
;; To be used as a hook at the end of a java compilation
(defun end-of-java-compile (bufname msg)
"To be used as a hook at the end of a java compilation"
;; Check my-jde-source-type flag. If it's neither "applet" nor "app"
;; then it wasn't invoked by my-jde-save-compile-run-applet or by
;; my-jde-save-compile-run-app, that is, the user did a very basic
;; compile. In this case don't do anything!
(if auto-run
(progn
(setq auto-run nil)
(if (not (eq (string-match "finished" msg) nil))
(save-excursion
(switch-to-buffer my-java-buffer)
(message "Running... ")
(if (is-applet) (jde-run-applet)
(jde-run)))))))
;; Set function to be called at end of java compilation
(setq jde-compile-finish-hook 'end-of-java-compile)
is-applet is a simple function that returns t if it finds "extends applet"
or "extends applet.Applet" and nil otherwise. For testing purposes here it
is:
(defun is-applet ()
"search for 'extends Applet' and 'extends applet.Applet' and 'extends
java.applet.Applet'. If it finds any of the above it should return t"
(save-excursion
(goto-char (point-min))
(let ((case-fold-search t))
(if (re-search-forward "extends \\(java.\\)?applet" nil t)
t ;
Found string
nil)))) ; Didn't find
string
This sometimes works, but often it doesn't. Even when it doesn't want to
automatically run after a my-jde-save-compile-run I check auto-run and it is
correctly set to t. So, what's the problem? Is it the
jde-compile-finish-hook maybe?
Does anybody know what the problem might be?
Thanks,
Daniel
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.