         start-idx (form-start source pos)]
     (calc-highlight-coords lines start-idx pos)))
 
-(defn make-eval-opts []
-  (let [{:keys [verbose static-fns]} @app-opts]
-    {:ns            @current-ns
-     :verbose       verbose
-     :static-fns    static-fns}))
+;; --------------------
+;; Error handling
 
 (defn- ^:boolean could-not-eval? [msg]
   (boolean (re-find could-not-eval-regex msg)))

  (load-core-analysis-caches repl?)
  (deps/index-upstream-foreign-libs))

;; =============================================================================
;; Autocompletion

(defn- drop-macros-suffix


(defn- repl-special? [form]
  (and (seq? form) (contains? repl-special-fns (first form))))

(defn make-eval-opts []
  (let [{:keys [verbose static-fns]} @app-opts]
    {:ns            @current-ns
     :verbose       verbose
     :static-fns    static-fns}))

(defn- current-alias-map []
  (let [cur-ns @current-ns]
    (into {} (remove (fn [[k v]] (= k v)))
      (merge (get-in @st [::ana/namespaces cur-ns :requires])
        (get-in @st [::ana/namespaces cur-ns :require-macros])))))

(defn- reader-eof? [msg]
  (or
    (= "EOF while reading" msg)
    (= "EOF while reading string" msg)))

(defn- read-chars
  [reader]
  (let [sb (StringBuffer.)]
    (loop [c (rt/read-char reader)]
      (if-not (nil? c)
        (do
          (.append sb c)
          (recur (rt/read-char reader)))
        (str sb)))))

(defn- repl-read-string
  "Returns a vector of the first read form, and any balance text."
  [source]
  (let [reader (rt/string-push-back-reader source)
        cur-ns @current-ns]
    (binding [ana/*cljs-ns* cur-ns
              *ns* (create-ns cur-ns)
              env/*compiler* st
              r/*data-readers* tags/*cljs-data-readers*
              r/resolve-symbol ana/resolve-symbol
              r/*alias-map* (current-alias-map)]
      [(r/read {:read-cond :allow :features #{:cljs}} reader) (read-chars reader)])))

(declare execute-source)

(defn- execute-path [filename opts]
  (load {:file filename}
    (fn [{:keys [lang source cache]}]
      (if source
        (execute-source source (merge opts
                                 {:type "text"
                                  :filename filename
                                  :expression? false}))
        (handle-repl-error (ex-info (str "Could not load file " filename) {}))))))

(defn- execute-text
  [source {:keys [expression? filename] :as opts}]
