 ;; Number.
 ;; Return: The relevant output in the buffer.
 (defun ems-parse-output-buffer (counter)
+  (accept-process-output ems-node-process 1)
   (with-current-buffer ems-output-buffer
     (let* ((str (buffer-string))
-           (result nil))
-      ;; (do* ((start (string-match (format "BEGINOUTPUT%d" counter) str))
-      ;;       (end (string-match (format "ENDOUTPUT%d" counter) str)))
-      ;;     ((and start end) (setq result (subseq str (+ start 12) end)))
-      (print (process-sentinel (get-buffer-process "*js*"))))))
+           (start (string-match (format "BEGINOUTPUT%d" counter) str))
+           (end (string-match (format "ENDOUTPUT%d" counter) str)))
+      (if (and start end) (subseq str (+ start 12) end))
+      )))
 
 
 ;;; API

(defun ems-stop ()
  (ems-teardown-bridge))

(defun msg-me (process event)
   (princ
     (format "Process: %s had the event `%s'" process event)))

(set-process-sentinel (get-buffer-process "*js*") 'msg-me)


;;; Currently testing!

(defvar ems-node-buffer nil)
(defvar ems-node-process nil)
(defvar ems-output-buffer nil)
(defvar ems-request-counter 0)

(setq inferior-js-mode-hook
      (lambda ()
        (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)
  (setq ems-node-buffer (get-buffer "*js*"))
  (setq ems-node-process (get-buffer-process "*js*"))
  (let ((output-buffer (get-buffer "*ems-output*")))
    (if output-buffer
        (setq ems-output-buffer output-buffer)
      (setq ems-output-buffer (generate-new-buffer "*ems-output*"))
      )))

(defun ems-load-mathjax ()
  (comint-redirect-send-command-to-process
