aboutsummaryrefslogtreecommitdiff
path: root/src/guile/skribilo/module.scm
diff options
context:
space:
mode:
Diffstat (limited to 'src/guile/skribilo/module.scm')
-rw-r--r--src/guile/skribilo/module.scm105
1 files changed, 66 insertions, 39 deletions
diff --git a/src/guile/skribilo/module.scm b/src/guile/skribilo/module.scm
index 50c7b23..854c50d 100644
--- a/src/guile/skribilo/module.scm
+++ b/src/guile/skribilo/module.scm
@@ -22,6 +22,7 @@
:use-module (skribilo reader)
:use-module (skribilo evaluator)
:use-module (skribilo debug)
+ :use-module (srfi srfi-1)
:use-module (ice-9 optargs))
;;; Author: Ludovic Courtès
@@ -36,47 +37,47 @@
;;;
;;; Code:
-(define-macro (define-skribe-module name)
+(define *skribilo-user-imports*
+ ;; List of modules that should be imported by any good Skribilo module.
+ '((srfi srfi-1) ;; lists
+ (srfi srfi-13) ;; strings
+ ;(srfi srfi-19) ;; date and time
+ (oop goops) ;; `make'
+ (ice-9 optargs) ;; `define*'
+
+ (skribilo module)
+ (skribilo types) ;; `<document>', `document?', etc.
+ (skribilo config)
+ (skribilo vars)
+ (skribilo runtime) ;; `the-options', `the-body'
+ (skribilo biblio)
+ (skribilo lib) ;; `define-markup', `unwind-protect', etc.
+ (skribilo resolve)
+ (skribilo engine)
+ (skribilo writer)
+ (skribilo output)
+ (skribilo evaluator)))
+
+(define *skribe-core-modules*
+ '("utils" "api" "bib" "index" "param" "sui"))
+
+(define-macro (define-skribe-module name . options)
`(begin
- (define-module ,name)
+ (define-module ,name
+ #:reader (make-reader 'skribe)
+ #:use-module (skribilo reader)
+ ,@options)
;; Pull all the bindings that Skribe code may expect, plus those needed
;; to actually create and read the module.
- (use-modules (skribilo module)
- (skribilo reader)
- (skribilo evaluator) ;; `run-time-module'
- (skribilo engine)
- (skribilo writer)
- (skribilo types)
-
- (srfi srfi-1)
- (ice-9 optargs)
-
- (skribilo lib) ;; `define-markup', `unwind-protect', etc.
- (skribilo runtime)
- (skribilo vars)
- (skribilo config))
-
-
- ;; The `define' below results in a module-local definition. So the
- ;; definition of `read' in the `(guile-user)' module is left untouched.
- ;(define read ,(make-reader 'skribe))
-
- ;; Everything is exported.
-; (define-macro (define . things)
-; (let* ((first (car things))
-; (binding (cond ((symbol? first) first)
-; ((list? first) (car first))
-; ((pair? first) (car first))
-; (else
-; (error "define/skribe: bad formals" first)))))
-; `(begin
-; (define-public ,@things)
-; ;; Automatically push it to the run-time user module.
-; ; (module-define! ,(run-time-module)
-; ; (quote ,binding) ,binding)
-; )))
- ))
+ ,(cons 'use-modules
+ (append *skribilo-user-imports*
+ (filter-map (lambda (mod)
+ (let ((m `(skribilo skribe
+ ,(string->symbol
+ mod))))
+ (and (not (equal? m name)) m)))
+ *skribe-core-modules*)))))
;; Make it available to the top-level module.
@@ -84,9 +85,35 @@
'define-skribe-module define-skribe-module)
-(define-public *skribe-core-modules*
- '("utils" "api" "bib" "index" "param" "sui"))
+
+(define *skribilo-user-module* #f)
+
+;;;
+;;; MAKE-RUN-TIME-MODULE
+;;;
+(define-public (make-run-time-module)
+ "Return a new module that imports all the necessary bindings required for
+execution of Skribilo/Skribe code."
+ (let ((the-module (make-module)))
+ (for-each (lambda (iface)
+ (module-use! the-module (resolve-module iface)))
+ (append *skribilo-user-imports*
+ (map (lambda (mod)
+ `(skribilo skribe
+ ,(string->symbol mod)))
+ *skribe-core-modules*)))
+ (set-module-name! the-module '(skribilo-user))
+ the-module))
+
+;;;
+;;; RUN-TIME-MODULE
+;;;
+(define-public (run-time-module)
+ "Return the default instance of a Skribilo/Skribe run-time module."
+ (if (not *skribilo-user-module*)
+ (set! *skribilo-user-module* (make-run-time-module)))
+ *skribilo-user-module*)
;; FIXME: This will eventually be replaced by the per-module reader thing in