     (set (make-local-variable 'live-py-version) "python")
     (set (make-local-variable 'live-py-window-start-pos) -1)
     (set (make-local-variable 'live-py-point-line-nr) -1)
+    (add-hook 'kill-buffer-hook 'live-py-mode-off nil t)
     (add-hook 'after-change-functions 'live-py-after-change-function nil t)
     (live-py-show-output-window)
     (live-py-after-change-function 0 0 0)

  (interactive)
  (setq live-py-path (read-string "PYTHONPATH:")))

;;;###autoload
(define-minor-mode live-py-mode
  "Minor mode to do on-the-fly Python tracing.

   (t
    (remove-hook 'after-change-functions 'live-py-after-change-function t)
    (remove-hook 'post-command-hook 'live-py-check-to-scroll t)
    (remove-hook 'kill-buffer-hook 'live-py-mode-off t)
    (ignore-errors (kill-buffer live-py-output-buffer))
    (when (window-valid-p live-py-output-window)
      (delete-window live-py-output-window))
