-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
config.clj
56 lines (49 loc) · 1.64 KB
/
config.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(ns nrepl.config
"Server configuration utilities.
Some server options can be configured via configuration
files (local or global). This namespace provides
convenient API to work with them.
The config resolution algorithm is the following:
The global config file .nrepl/nrepl.edn is merged with
any local config file (.nrepl.edn) if present.
The values in the local config file take precedence."
{:author "Bozhidar Batsov"
:added "0.5"}
(:require
[clojure.java.io :as io]
[clojure.edn :as edn]))
(def ^:private home-dir
"The user's home directory."
(System/getProperty "user.home"))
(def config-dir
"nREPL's configuration directory.
By default it's ~/.nrepl, but this can be overridden
with the NREPL_CONFIG_DIR env variable."
(or (System/getenv "NREPL_CONFIG_DIR")
(str home-dir java.io.File/separator ".nrepl")))
(def config-file
"nREPL's config file."
(str config-dir java.io.File/separator "nrepl.edn"))
(defn- load-edn
"Load edn from an io/reader source (filename or io/resource)."
[source]
(with-open [r (io/reader source)]
(edn/read (java.io.PushbackReader. r))))
(defn- load-config
"Load the configuration file identified by `filename`.
Return its contents as EDN if the file exists,
or an empty map otherwise."
[filename]
(let [file (io/file filename)]
(if (.exists file)
(load-edn file)
{})))
(def config
"Configuration map.
It's created by merging the global configuration file
with a local configuration file that would normally
the placed in the directory in which you're running
nREPL."
(merge
(load-config config-file)
(load-config ".nrepl.edn")))