 (defvar ems-node-process nil)
 (defvar ems-output-buffer nil)
 (defvar ems-request-counter 0)
+(defvar ems-results ())
+
 
 (add-hook
  'inferior-js-mode-hook

        (add-to-list
         'comint-preoutput-filter-functions
         #'(lambda (output)
           (string-match (format "BEGINOUTPUT" ems-request-counter) output))
           (replace-regexp-in-string "[.]*BEGINOUTPUT[0-9]+" "" output)
           (replace-regexp-in-string "ENDOUTPUT[.]*" "" output))))

(defun ems-load-node ()
  (run-js inferior-js-program-command t)

  (setf ems-node-buffer nil))


;; Number: The full buffer output.
;; Return: Cons with call number and result.
(defun ems-parse-output (output)
  (let* ((start (string-match "BEGINOUTPUT[0-9]+: .* :ENDOUTPUT" output)))
    (when start
      (let* ((rest (subseq output (+ start 11)))
             (colon (string-match ": " rest))
             (number (subseq rest 0 colon))
             (rest (subseq rest (+ colon 2)))
             (end (string-match " :ENDOUTPUT" rest))
             (result (subseq rest 0 end)))
        (print result)
        (print number)
        (push (cons (car (read-from-string number)) result) ems-results)
        result))))


;;; API
