     [[:edit xy] :key-down 13]
     [[(display-mode xy)
       (display-mode (:source state))
-      [[:display xy] :value (get-in state [:cells (:focus state) :value])]]
+      [[:display xy] :value (cell-value (:focus state) state)]]
      (assoc state :mode :done)]
     
     :else [[] state]))

(def source-mode  (cell-mode "source-mode"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers

(defn- formula? [s]
  (string? (first (re-matches #"^=.*" s))))

(defn- write-formula [s state]
  (let [formula (get-in state [:cells (:focus state) :formula])]
    (str formula " " s)))

(defn- cell-value [xy state]
  (let [cell (get-in state [:cells xy])]
    (if (:formula cell)
      (read-formula (:formula cell) state)
      (:value cell))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The Brain

(defn behavior [message state]
  (match message

    [[:display xy] :click _]

            [om-tools.dom :as dom :include-macros true]
            [om.core :as om :include-macros true]
            [clojure.string :as string]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers

(defn- formula? [s]
  (string? (first (re-matches #"^=.*" s))))

(defn- write-formula [s state]
  (let [formula (get-in state [:cells (:focus state) :formula])]
    (str formula " " s)))

(defn- cell-value [xy state]
  (let [cell (get-in state [:cells xy])]
    (if (:formula cell)
      (read-formula (:formula cell) state)
      (:value cell))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Formula interpreter
