         )
       )))
 
+(defun rosemacs/kill-and-relaunch ()
+  "Interrupt the current roslaunch process, and when it has terminated, relaunch."
+  (interactive)
+  (let ((process (get-buffer-process (current-buffer))))
+    (if (and process (eq (process-status process) 'run))
+        (progn
+          (interrupt-process)
+          (set-process-sentinel process
+                                '(lambda (proc event)
+                                   (message "Roslaunch has terminated; relaunching")
+                                   (rosemacs/relaunch (process-buffer proc))
+                                   )))
+      (error "Buffer doesn't contain a running process"))))
+
+
 (defun rosemacs/relaunch-current-process ()
   (interactive)
   (rosemacs/relaunch (current-buffer)))

(defun rosrun/restart-current ()
  (interactive)
  (rosrun/restart (current-buffer)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; roslaunch

(define-key ros-launch-keymap "k" 'rosemacs/interrupt-process)
(define-key ros-launch-keymap "q" 'rosemacs/kill-process-buffer)
(define-key ros-launch-keymap "r" 'rosemacs/relaunch-current-process)
(define-key ros-launch-keymap "x" 'rosemacs/kill-and-relaunch)



