 ;; Best try on filling "column" of l subsequent ones with one or more tokens
 (defn fill-column [ts l]
   (let [f (fn [terms-so-far term]
-            (if (>= (apply + (map #(+ 1 (count %)) terms-so-far)) l)
+            (if (>= (apply + (map count terms-so-far)) l)
               (reduced terms-so-far)
               (conj terms-so-far term)))
         terms-that-fit (reduce f [(first ts)] (rest ts))

;; w    -- int, width of output, in chars
(defn harnify [code img w]
  (let [tokens (js->clj (js/esprima.tokenize code) :keywordize-keys true)
        ts (map :value tokens)]
    (comment apply str (interleave ts (repeat " ")))
    (string/join "\n" (reverse (arrange-tokens ts img)))              ; img must be resized by now, no need in w
    ))
    

(let [code      "function skipComment() {
        var ch, start;

;; Insert spaces between terms so they occupy exactly l chars
;; TODO: make spacing more even
(defn insert-spaces [terms l]
  (let [terms-interleaved terms ;; TODO: need better interleave that would work as string.join (without last space)
        spaces-needed (- l (apply + (map count terms-interleaved)))
        f (fn [terms _] (insert terms (inc (rand-int (- (count terms) 1))) " "))]
    (string/join (reduce f terms-interleaved (range spaces-needed)))))
