   (interactive)
   (interrupt-process))
 
-(defun kill-current-buffer ()
+(defun rosemacs/kill-process-buffer ()
   (interactive)
   (let ((process (get-buffer-process (current-buffer))))
     (when (and process (eq (process-status process) 'run))
-      (interrupt-process)))
-  (kill-buffer nil))
+      (interrupt-process))
+    ;; Give it time to shutdown cleanly
+    (set-process-sentinel process '(lambda (proc event)
+                                     (let ((buf (process-buffer proc)))
+                                       (message "Killing %s in response to process event %s" buf event)
+                                       (kill-buffer buf))))
+    ))
 
 (defvar ros-topic-echo-keymap (make-sparse-keymap))
 (define-key ros-topic-echo-keymap "k" 'rosemacs/interrupt-process)
-(define-key ros-topic-echo-keymap "q" 'kill-current-buffer)
+(define-key ros-topic-echo-keymap "q" 'rosemacs/kill-process-buffer)
 
 (define-minor-mode ros-topic-echo-mode 
   "Mode used for rostopic echo.  


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





(defvar ros-topic-list-keymap (make-sparse-keymap))
(define-key ros-topic-list-keymap [?q] 'rosemacs/kill-process-buffer)
(define-key ros-topic-list-keymap [?\r] 'echo-current-topic)
(define-key ros-topic-list-keymap [?h] 'hz-current-topic)
(define-key ros-topic-list-keymap [?H] 'unhz-current-topic)
