Skip to content

Commit 74c9618

Browse files
committedDec 23, 2023
Refactor configuration out to dedicated module
Add missing gloa configuration module to Automake sources list
1 parent 2ae5a0e commit 74c9618

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed
 

‎Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
## along with Gloa. If not, see <http://www.gnu.org/licenses/>.
1818

1919
SOURCES = \
20+
gloa/config.scm \
2021
gloa/hello.scm \
2122
gloa/utils.scm \
2223
gloa/article.scm \

‎gloa.scm

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,16 @@
11
(define-module (gloa)
2+
#:use-module (gloa config)
23
#:use-module (gloa hello)
34
#:use-module (system repl repl)
45
#:declarative? #f
56
#:export (gloa-main))
67

7-
(define guile-user-config
8-
;; The user's personal Guile REPL configuration.
9-
(and=> (getenv "HOME")
10-
(lambda (home)
11-
(string-append home "/.guile"))))
12-
138
(define (set-user-module)
149
(when (and ;; (not (assoc-ref opts 'ignore-dot-guile?)) ;; TODO: CLI flag for ignoring .guile
1510
guile-user-config
1611
(file-exists? guile-user-config))
1712
(load guile-user-config)))
1813

19-
(define (%default-db-location)
20-
"The default location of Gloa's tracking database."
21-
(string-append
22-
(or (getenv "XDG_CACHE_HOME")
23-
(format #f "~a/.cache" (getenv "HOME")))
24-
"/gloa/gloa.sqlite"))
25-
26-
(define (%default-storage-directory)
27-
"The default location of Gloa's tracked documents."
28-
(string-append
29-
(or (getenv "XDG_DATA_HOME")
30-
(format #f "~a/.local" (getenv "HOME")))
31-
"/gloa/"))
32-
33-
(define (%default-user-config-location)
34-
"Location of user's configuration of Gloa.
35-
Searches for @code{$XDG_CONFIG_HOME/gloa/init.scm} first, if that is not found,
36-
Gloa falls back to @code{$HOME/.gloa.d/init.scm}, and if that fails,
37-
@code{$HOME/.gloa.scm} is searched for.
38-
If none of those are found, no configuration changes to Gloa occur."
39-
(let ((config-dot-d (format #f "~a/.gloa.d" (getenv "HOME")))
40-
(dot-config (format #f "~a/.gloa.scm" (getenv "HOME"))))
41-
(cond ((getenv "XDG_CONFIG_HOME")
42-
(string-append (getenv "XDG_CONFIG_HOME") "/gloa/init.scm"))
43-
((and (file-exists? config-dot-d) (file-is-directory? config-dot-d))
44-
(format #f "~a/init.scm" config-dot-d))
45-
(#t dot-config))))
46-
4714
(define* (gloa-main arg0 . args)
4815
;; Add gloa site directory to Guile's load path so that user's can
4916
;; easily import their own modules.

‎gloa/config.scm

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(define-module (gloa config)
2+
#:export (guile-user-config
3+
%default-db-location
4+
%default-storage-directory
5+
%default-user-config-location))
6+
7+
(define guile-user-config
8+
;; The user's personal Guile REPL configuration.
9+
(and=> (getenv "HOME")
10+
(lambda (home)
11+
(string-append home "/.guile"))))
12+
13+
(define (%default-db-location)
14+
"The default location of Gloa's tracking database."
15+
(string-append
16+
(or (getenv "XDG_CACHE_HOME")
17+
(format #f "~a/.cache" (getenv "HOME")))
18+
"/gloa/gloa.sqlite"))
19+
20+
(define (%default-storage-directory)
21+
"The default location of Gloa's tracked documents."
22+
(string-append
23+
(or (getenv "XDG_DATA_HOME")
24+
(format #f "~a/.local" (getenv "HOME")))
25+
"/gloa/"))
26+
27+
(define (%default-user-config-location)
28+
"Location of user's configuration of Gloa.
29+
Searches for @code{$XDG_CONFIG_HOME/gloa/init.scm} first, if that is not found,
30+
Gloa falls back to @code{$HOME/.gloa.d/init.scm}, and if that fails,
31+
@code{$HOME/.gloa.scm} is searched for.
32+
If none of those are found, no configuration changes to Gloa occur."
33+
(let ((config-dot-d (format #f "~a/.gloa.d" (getenv "HOME")))
34+
(dot-config (format #f "~a/.gloa.scm" (getenv "HOME"))))
35+
(cond ((getenv "XDG_CONFIG_HOME")
36+
(string-append (getenv "XDG_CONFIG_HOME") "/gloa/init.scm"))
37+
((and (file-exists? config-dot-d) (file-is-directory? config-dot-d))
38+
(format #f "~a/init.scm" config-dot-d))
39+
(#t dot-config))))

0 commit comments

Comments
 (0)