Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created June 28, 2014 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/5a5a7640fc2c05d00c42 to your computer and use it in GitHub Desktop.
Save alandipert/5a5a7640fc2c05d00c42 to your computer and use it in GitHub Desktop.
(defn make-page
[text form-zippers]
(flow/build-dataflow
[(flow/cell :source cursor 0)
(flow/cell :source zippers form-zippers)
(flow/cell current-zipper (get ?zippers ?cursor))
(flow/cell printed-zippers (mapv (comp print-clojure z/root) ?zippers))
(flow/cell strings (mapv str ?printed-zippers))
(flow/cell offsets (vec (cons 0 (reductions + (map (comp inc count) ?strings)))))
(flow/cell current-printed (?printed-zippers ?cursor))
(flow/cell highlight-bounds
(->> (z/node ?current-zipper)
(bounds ?current-printed)
((juxt :start :end))
(mapv (partial + (get ?offsets ?cursor)))))
(flow/cell top? (identical? (z/root ?current-zipper) (z/node ?current-zipper)))
(flow/cell insert! (.setText text (apply str (interpose \newline ?strings))))
(flow/cell highlight! (apply highlight! text ?highlight-bounds))
(flow/cell debug! (pp/pprint
(hash-map :node (z/node ?current-zipper)
:bounds ?highlight-bounds)))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment