(defun my-jde ()
    (interactive)
    (cd global-jde-run-dir)
    (my-jde-bindings)
    (jde-debug)
    (my-jde-bindings)
)

(defun jde ()
    (interactive)
;   (jde-init)
;   (call-interactively 'jde-set-parms)
    (my-jde)
)

(defun jde-init ()
    (interactive)
    (setq load-path (append load-path
        (list (concat HOME "/emacs/lib/jde/lisp")
              (concat HOME "/emacs/lib/elib")
              (concat HOME "/emacs/lib/semantic")
              (concat HOME "/emacs/lib/eieio")
              (concat HOME "/emacs/lib/speedbar")
              (concat HOME "/emacs/lib/ecb"))))
    (require 'jde)
    (require 'ecb)
)

(defun jde-set-parms (sourcepath run-dir app-class app-args)
"Input sourcepath, run-dir, app-class, and app-args for jde."
    (interactive "fSourcepath: 
fRun dir: 
FApplication Class (e.g., app.Main): 
FApplication Command-Line Args: "
)

    (setq jde-sourcepath (list sourcepath))
    (setq global-jde-run-dir run-dir)
    (setq global-jde-run-application-class app-class)
    (setq jde-db-option-application-args (list app-args))
)

(defun my-jde-bindings ()
    (interactive)

    (local-set-key "u" 'my-jde-debug-up)
    (local-set-key "d" 'my-jde-debug-down)
    (local-set-key "n" 'my-jde-debug-step-over)
    (local-set-key "s" 'my-jde-debug-step-into)
    (local-set-key "c" 'my-jde-debug-cont)
    (local-set-key "w" 'jde-debug-where)

    (local-set-key "" 'comint-previous-input)
    (local-set-key "" 'comint-next-input)

    (global-set-key " " 'jde-debug-set-breakpoint)
    (global-set-key "�" 'jde-debug-clear-breakpoint)
)

(defun my-jde-debug-up () (interactive)
  (my-jde-debug-command-with-twiddling 'jde-debug-up))
(defun my-jde-debug-down () (interactive)
  (my-jde-debug-command-with-twiddling 'jde-debug-down))
(defun my-jde-debug-step-over () (interactive)
  (my-jde-debug-command-with-twiddling 'jde-debug-step-over))
(defun my-jde-debug-step-into () (interactive)
  (my-jde-debug-command-with-twiddling 'jde-debug-step-into))
(defun my-jde-debug-cont () (interactive)
  (my-jde-debug-command-with-twiddling 'jde-debug-cont))

(defun my-jde-debug-command-with-twiddling (jde-debug-command)
    (interactive)
;   (setq jde-sourcepath '("~/work/calendar/implementation/source/java"))
    (setq bname (buffer-name))
;   (other-window 1)
    (eval (list jde-debug-command))
;   (other-window 1)
;   (switch-to-buffer bname)
;   (other-window 1)
    (end-of-buffer)
;   (insert "fuck")
)

(defun jde-twiddle-1 () (interactive) (other-window 1) (end-of-buffer))
(defun jde-twiddle-2 () (interactive)
  (switch-to-buffer "*debugcaltool.Main*") (end-of-buffer))