Skip to content

Commit 6134e92

Browse files
committed
init.scm(re-export-public-interface): Syntax to re-export all defines.
1 parent 7ddbed7 commit 6134e92

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

guile/spotiqueue/init.scm

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,51 @@
2020
#:declarative? #f)
2121
(module-export-all! (current-module))
2222

23+
;; Syntax transformer to re-export all public defines from a given module from this module. Grabbed
24+
;; from https://www.mail-archive.com/bug-guile@gnu.org/msg10321.html
25+
;;
26+
;; What i want is, whenever someone imports (spotiqueue init), they should get whatever has been
27+
;; defined in (spotiqueue functions), too. The latter is the "phantom module" created in Swift-land
28+
;; when Spotiqueue boots, exporting a few functions which are needed to sensibly be able to interact
29+
;; with the music player.
30+
(define-syntax re-export-public-interface
31+
(syntax-rules ()
32+
"Re-export the public interface of a module or modules. Invoked as
33+
@code{(re-export-public-interface (mod1) (mod2) ...)}."
34+
((_ (m0 m0* ...) (mn mn* ...) ...)
35+
(let ((iface (module-public-interface (current-module))))
36+
(define (r-e-p-i module)
37+
(cond-expand
38+
(guile-3
39+
(module-for-each
40+
(lambda (sym val)
41+
(hashq-set! (module-replacements iface) sym #t)
42+
(module-add! iface sym val))
43+
(resolve-interface module)))
44+
(else
45+
(module-use! iface (resolve-interface module)))))
46+
(r-e-p-i '(m0 m0* ...))
47+
(r-e-p-i '(mn mn* ...))
48+
...))
49+
((_)
50+
(syntax-error "must provide one or more module names"))
51+
((_ m m* ...)
52+
(syntax-error "module names must look like lists"))))
53+
54+
(re-export-public-interface (spotiqueue functions))
55+
56+
;; The re-export thing should presumably be achievable with this snippet, from
57+
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=47084, and it does seem to work, except that i feel
58+
;; like i can't really get my head around it. Notably i don't understand the docstring of
59+
;; `module-use!`, which simply states, "Add interface [the second arg] to the front of the use-list
60+
;; of module [the first arg]. Both arguments should be module objects, and interface should very
61+
;; likely be a module returned by resolve-interface." Also, (current-module) always resolves to
62+
;; (spotiqueue init), and not whatever is importing it...
63+
;;
64+
;; (eval-when (expand load eval)
65+
;; (module-use! (module-public-interface (current-module))
66+
;; (resolve-interface '(spotiqueue functions))))
67+
2368
(format #t "guile ~s: Loading Spotiqueue bootstrap config...~%" (module-name (current-module)))
2469

2570
;; Define the key maps

0 commit comments

Comments
 (0)