>>>>> "Karr" == Karr, David <[EMAIL PROTECTED]> writes:

  Karr> If I have an instance of the debugger running and I execute
  Karr> "jde-db", it currently gives me a message to the point that I
  Karr> already have a debugger instance running.  I end up doing this
  Karr> very often.  It would be much more convenient if it would just
  Karr> abort the current one before starting the new one, instead of
  Karr> forcing me to do it manually.


        Whilst I dont user the jde-db that often, I have the same
problem with jde-run, which does the same thing. Its been annoying me
for ages, so I decided to work around it. Ive included below lisp
which changes this behaviour. It doesnt kill the buffer automatically
but asks you whether you want to or not first (I consider this to
be the most sensible behaviour. Ive put the alternate lisp into the
comments of the first function if you want it to be automatic). 

        This code works by over-writing two functions in JDE, so you
need to load these AFTER you have loaded JDE otherwise the wrong one
will get over-written. I have a standard package (called jde-advise)
precisely for this purpose. 

          The change to the JDE functions is trivial (swapping a call 
to comint-check-proc, for a call to jde-run-kill-existing-process-query)
so if you want to do the same thing for the applet run and debug
functions it shouldnt be hard.

;;This is a new function
(defun jde-run-kill-existing-process-query( run-buf-name )
  "*If a process is running, ask the user if it should be killed"
  (let ((retval nil))
    (if (comint-check-proc run-buf-name)
        ;;A process is running of this name is running
        ;;therefore show this buffer
        (progn(pop-to-buffer run-buf-name)
              ;;ask whether to kill it or not
              ;;Use the next line and comment out the one after if you
              ;;want this automated
              ;;(setq retval t)
              (setq retval (not (y-or-n-p "Kill existing instance? ")))
              (if (not retval)
                  (progn(message "Restarting %s" run-buf-name )
                        (delete-process run-buf-name)))))
    retval))
         
    

;;This is a standard JDE function, slightly fiddled
(defun jde-run-internal(app-class)
  (let ((run-buf-name (concat "*" app-class "*"))
        (source-directory default-directory)
        (working-directory (if (string= jde-run-working-directory "")
                               default-directory
                             jde-run-working-directory)))
    (if (not (jde-run-kill-existing-process-query run-buf-name))
        (let* ((run-buffer (get-buffer-create run-buf-name))
               (win32-p (eq system-type 'windows-nt))
               (prog (if (and
                          win32-p
                          (string= jde-run-java-vm "java"))
                         jde-run-java-vm-w
                       jde-run-java-vm))
               (prog-args (append
                           (jde-run-get-vm-args)
                           (if jde-run-read-vm-args
                               (jde-run-parse-args
                                (read-from-minibuffer
                                 "Vm args: "
                                 jde-run-interactive-vm-args
                                 nil nil
                                 '(jde-run-interactive-vm-arg-history . 1))))
                           (list app-class)
                           jde-run-option-application-args
                           (if jde-run-read-app-args
                               (jde-run-parse-args
                                (read-from-minibuffer
                                 "Application args: "
                                 jde-run-interactive-app-args
                                 nil nil
                                 '(jde-run-interactive-app-arg-history . 1))))
                           ))
               (command-string (concat prog " " 
                                       (jde-run-make-arg-string
                                        prog-args)
                                       "\n\n")))
          (save-excursion
            (set-buffer run-buffer)
            (erase-buffer)
            (cd working-directory)
            (insert (concat "cd " working-directory "\n"))
            (insert command-string)
            (jde-run-mode))
          (save-w32-show-window
           (comint-exec run-buffer app-class prog nil prog-args))
          (pop-to-buffer run-buffer)
          (cd source-directory))
      (message "An instance of %s is running." app-class)
      (pop-to-buffer run-buf-name))))



;;The same thing for jde-db which I might as well do even though
;;I dont use it.
(defun jde-db-init(app-class marker-filter find-file)
  (let ((debug-buf-name (concat "*debug" app-class "*"))
        (source-directory default-directory)
        (working-directory (if (string= jde-run-working-directory "")
                               default-directory
                             jde-run-working-directory)))
    (if (not (jde-run-kill-existing-process-query debug-buf-name))
        (let* ((debug-buffer (get-buffer-create debug-buf-name))
               (program (if (string= (cdr jde-db-debugger) "Executable")
                           (car jde-db-debugger)
                         jde-run-java-vm))
               (prog-args (if (string= (cdr jde-db-debugger) "Executable")
                              (append 
                               (jde-db-get-vm-args)
                               (jde-db-get-vm-args-from-user)
                               (list app-class)
                               jde-db-option-application-args
                               (jde-db-get-app-args-from-user))
                            (append
                             (list (car jde-db-debugger))
                             (jde-db-get-vm-args)
                             (jde-db-get-vm-args-from-user)
                             (list app-class)
                             jde-db-option-application-args
                             (jde-db-get-app-args-from-user))))
               (command-string (concat
                                program " "
                                (jde-run-make-arg-string prog-args) "\n\n")))
          (save-excursion
            (set-buffer debug-buffer)
            (erase-buffer)
            (cd working-directory)
            (insert (concat "cd " working-directory "\n"))
            (insert command-string)
            (comint-mode))
          (comint-exec debug-buffer app-class program nil prog-args)
          (pop-to-buffer debug-buffer)
          (cd source-directory)
          (gud-mode)
          (make-local-variable 'gud-marker-filter)
          (setq gud-marker-filter marker-filter)
          (make-local-variable 'gud-find-file)
          (setq gud-find-file find-file)
          (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
          (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
          (gud-set-buffer)
          (if jde-db-startup-commands
            (mapc 'gud-basic-call jde-db-startup-commands)
           (when jde-db-set-initial-breakpoint
            (gud-basic-call (concat "stop in " app-class ".main"))
            (gud-basic-call "run")))
          )
      (message "An instance of %s is running." app-class)                       
      (pop-to-buffer debug-buf-name))))                    
          

Reply via email to