   "Get k process's buffer."
   (get-buffer (concat "*" k-program-name "*")))
 
+(defun k-proc-kill ()
+  "Kill the current K process, if any."
+  (interactive)
+  (let ((kp (k-proc)))
+    (when kp (delete-process kp))))
+
 (defun switch-to-k (uarg)
   "Switch to a k process, or spawn a new one if not running.
 Universal argument switches to it in another window."

    (when kbuf
      (with-current-buffer kbuf
        (add-hook 'comint-output-filter-functions
                  'k-comint-output-filter nil t)))
  (unless (equal (current-buffer) kbuf)
    (if uarg
        (switch-to-buffer-other-window kbuf)
        (switch-to-buffer kbuf)))
  kproc))

(defun k-send-str (s)

    (when (and kproc s)
      (comint-send-string kproc s))))
            
(defun k-buffer-is-visible ()
  "Check if the k process buffer is currently visible."
  (let ((b (k-proc-buffer)))
    (when b
      (member b
              (mapcar (lambda (w) (window-buffer w))
                      (window-list))))))

(defun k-comint-output-filter (s)
  "Print output from code sent to k in the minibuffer."
  (unless (k-buffer-is-visible)
    (let ((drop (min (length s)
                     (+ 1 (length k-prompt-string)))))
      (princ (substring s 0 (- drop))))))

(defun k-send-region (start end)
  "Send region to k process."
