<commit_before>(ns nightcode.builders
  (:require [clojure.java.io :as io]
            [nightcode.editors :as editors]
            [nightcode.lein :as lein]
            [nightcode.shortcuts :as shortcuts]
            [nightcode.ui :as ui]
            [nightcode.utils :as utils]
            [seesaw.chooser :as chooser]
            [seesaw.color :as color]
            [seesaw.core :as s]))

(declare show-builder!)

; keep track of open builders

(def builders (atom {}))

(defn get-builder
  [path]
  (when (contains? @builders path)
    (->> [:#build-console]
         (s/select (get-in @builders [path :view]))
         first)))

; actions for builder buttons

(defn set-android-sdk!
  [_]
  (when-let [dir (chooser/choose-file :dir (utils/read-pref :android-sdk)
                                      :selection-mode :dirs-only
                                      :remember-directory? false)]
    (utils/write-pref! :android-sdk (.getCanonicalPath dir))
    (show-builder! (ui/get-selected-path))))

(defn set-robovm!
  [_]
  (when-let [dir (chooser/choose-file :dir (utils/read-pref :robovm)
                                      :selection-mode :dirs-only
                                      :remember-directory? false)]
    (utils/write-pref! :robovm (.getCanonicalPath dir))
    (show-builder! (ui/get-selected-path))))

(defn eval-in-repl!
  [console path timestamp]
  (let [source-paths (-> (lein/read-project-clj path)
                         (lein/stale-clojure-sources timestamp))
        contents (for [source-path source-paths]
                   (slurp source-path))
        names (for [source-path source-paths]
                (.getName (io/file source-path)))]
    (->> (format "(do %s\n\"%s\")"
                 (clojure.string/join "\n" contents)
                 (clojure.string/join ", " names))
         read-string
         pr-str
         (.enterLine console)
         (binding [*read-eval* false]))))

; button toggling functions<commit_msg>Use a better way to reload namespaces<commit_after>(ns nightcode.builders
  (:require [clojure.java.io :as io]
            [nightcode.editors :as editors]
            [nightcode.lein :as lein]
            [nightcode.shortcuts :as shortcuts]
            [nightcode.ui :as ui]
            [nightcode.utils :as utils]
            [seesaw.chooser :as chooser]
            [seesaw.color :as color]
            [seesaw.core :as s]))

(declare show-builder!)

; keep track of open builders

(def builders (atom {}))

(defn get-builder
  [path]
  (when (contains? @builders path)
    (->> [:#build-console]
         (s/select (get-in @builders [path :view]))
         first)))

; actions for builder buttons

(defn set-android-sdk!
  [_]
  (when-let [dir (chooser/choose-file :dir (utils/read-pref :android-sdk)
                                      :selection-mode :dirs-only
                                      :remember-directory? false)]
    (utils/write-pref! :android-sdk (.getCanonicalPath dir))
    (show-builder! (ui/get-selected-path))))

(defn set-robovm!
  [_]
  (when-let [dir (chooser/choose-file :dir (utils/read-pref :robovm)
                                      :selection-mode :dirs-only
                                      :remember-directory? false)]
    (utils/write-pref! :robovm (.getCanonicalPath dir))
    (show-builder! (ui/get-selected-path))))

(defn eval-in-repl!
  [console path timestamp]
  (let [source-paths (-> (lein/read-project-clj path)
                         (lein/stale-clojure-sources timestamp))
        commands (map #(format "(load-file \"%s\")" %) source-paths)
        names (map #(.getName (io/file %)) source-paths)]
    (->> (format "(do %s \"%s\")"
                 (clojure.string/join " " commands)
                 (clojure.string/join ", " names))
         (.enterLine console)
         (binding [*read-eval* false]))))

; button toggling functions
{'fraction_non_alphanumeric': 0.14352090862157976, 'fraction_numerical': 0.0, 'mean_word_length': 1.9069767441860466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6796120', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1204, 'n_words': 273}