 (require 'comint)
 
 (defvar k-program-name "k" "k executable name.")
+
+(defvar k-prompt-string "  "
+  "String printed by interpreter to represent a ready prompt.")
+
+(defvar k-process nil "Current k comint process, if any.")
 
 (defvar k-mode-map
   (let ((m (make-sparse-keymap)))

  "Switch to a k process, or spawn a new one if not running.
Universal argument switches to it in another window."
  (interactive "P")
  (let* ((kbuf (k-proc-buffer))
         (kproc (k-proc)))
    (unless (and kbuf kproc)
      (setq kbuf (make-comint k-program-name k-program-name))
      (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)))))

(defun k-send-str (s)
  "Send string to the k process, if existing."
  ;; TODO: print comint result in minibuf?
  (let ((kproc (k-proc))
        (kbuf (k-proc-buffer)))
    (when (and kproc s)
      (comint-send-string kproc s))))
            
(defun k-comint-output-filter (s)
  "Print output from code sent to k in the minibuffer."
  (princ (substring s 0 -3)))  ; -3 for \n(space space)

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

;; comint
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(print k-process)
(print (k-proc))

(print (process-status k-process))

(defun k-proc ()
  "Get k process."
  (get-process k-program-name))
