                   :browser.url-bar.focus
                   [:browser.url-bar.navigate! url]
                   :browser.focus-content]))
+
+(defn tempfile [seed suffix]
+  (let [dir (.tmpdir (js/require "os"))]
+    (files/join dir (str seed "-" (js/Date.now) suffix))))
 
 ;; Open pages
 ;; ==========

            [clojure.string :as s]
            [lt.objs.editor.pool :as pool]
            [lt.plugins.clojure :as clojure]
            [lt.objs.tabs :as tabs]
            [lt.objs.notifos :as notifos]
            [lt.objs.command :as cmd])
  (:require-macros [lt.macros :refer [defui behavior]]))

    (.on req "error" (fn [err]
                       (println "Request" url "failed with:" (.-message err))))))

(def ->grimoire-examples-url (comp #(str % "/examples") ->grimoire-url))

(defn fetch-and-open-grimoire-examples* [{:keys [ns var url]}]
  (notifos/working)
  (GET url (fn [body]
             (let [path (tempfile (str ns "-" var) ".clj")]
               (files/save path body)
               (cmd/exec! :open-path path))
             (notifos/done-working))))

(def fetch-and-open-grimoire-examples
  (partial for-resolved-var
           (fn [ns var]
             (fetch-and-open-grimoire-examples*
              {:ns ns :var var :url (->grimoire-examples-url ns var)}))))

(cmd/command {:command :inc-clojure.open-grimoire-examples
              :desc "IncClojure: Open grimoire examples locally for current symbol"
              :exec (fn []
                      (let [ed (pool/last-active)]
                        (eval-code ed
                                   (str "(resolve '" (current-word ed) ")")
                                   :fetch-and-open-grimoire-examples)))})

(comment
  (object/raise editor :editor.eval.clj.result.callback "OK?")
  (-> @editor :client :default deref)
