-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser.rkt
43 lines (36 loc) · 1.47 KB
/
user.rkt
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
#lang racket/base
(require rwind/base
rwind/util
rwind/doc-string
racket/file
)
(define* cmd-line-config-file (make-fun-box #f))
(define* rwind-uds-socket (make-fun-box (find-user-config-file rwind-dir-name "rwind-socket")))
(define* (rwind-user-config-file)
"Returns the configuration-file path for rwind (and may create the directory)."
(or (cmd-line-config-file)
(find-user-config-file rwind-dir-name rwind-user-config-file-name)))
(define* (open-user-config-file)
"Tries to open the user configuration file for edition, using the system default editor."
(define f (rwind-user-config-file))
(unless (file-exists? f)
(display-to-file
"#lang racket/base
;;; User configuration file
(require rwind/keymap rwind/base rwind/util rwind/window)
"
f #:mode 'text))
(open-file f))
;; TODO:
;; - If loading the user file fails, fall back to a default configuration (file)?
;; - replace the `printf' by `log-error'
(define* (init-user)
;; Read user configuration file
;; It would be useless to thread it, as one would still need to call XLockDisplay
(let ([user-f (rwind-user-config-file)])
(when (file-exists? user-f)
(with-handlers ([exn:fail? #;error-message-box
(λ(e)(printf "Error while loading user config file ~a:\n~a\n"
user-f
(exn-message e)))])
(dynamic-require user-f #f)))))