   (with-current-buffer factor--listener-buffer
     (factor-listener-mode)))
 
-(defun factor--listener-process ()
+(defun factor--listener-process (&optional start)
   (or (and (buffer-live-p factor--listener-buffer)
            (get-buffer-process factor--listener-buffer))
-      (progn (factor--listener-start-process)
-             (factor--listener-process))))
+      (when start
+        (factor--listener-start-process)
+        (factor--listener-process t))))
 
 ;;;###autoload
 (defalias 'switch-to-factor 'run-factor)

;;; Factor listener interaction:

(defun factor--listener-send-cmd (cmd)
  (let* ((out (get-buffer-create "*factor messages*"))
         (beg (with-current-buffer out (goto-char (point-max))))
         (proc (factor--listener-process)))
    (comint-redirect-send-command-to-process cmd out proc nil t)
    (with-current-buffer factor--listener-buffer
      (while (not comint-redirect-completed) (sleep-for 0 1)))
    (with-current-buffer out
      (split-string (buffer-substring-no-properties beg (point-max))
                    "[\"\f\n\r\v]+" t))))

;;;;; Current vocabulary:
(make-variable-buffer-local


;;;;; Synchronous interaction:

(defsubst factor--listener-vocab-cmds (cmds &optional vocab)
  (factor--with-vocab vocab
    (mapcar #'factor--listener-send-cmd cmds)))

(defsubst factor--listener-vocab-cmd (cmd &optional vocab)
  (factor--with-vocab vocab
    (factor--listener-send-cmd cmd)))

;;;;; Interface: see

