summaryrefslogtreecommitdiff
path: root/scm
diff options
context:
space:
mode:
authorDavid Kastrup <dak@gnu.org>2016-05-22 13:54:40 +0200
committerDavid Kastrup <dak@gnu.org>2016-05-31 21:50:18 +0200
commit5c2114fbd182303f4759f31aad6c662524a5d43e (patch)
tree0f95083be7cdfb2f4c77a292887e669afba07c51 /scm
parent1b6d6de94a26c3e8b75e1f78f6d0cfc9eec96a89 (diff)
Issue 4858: Let define-session-public place variables natively into parser
Putting them as native variables in the parser module (rather than using export/import) makes `set!' and `define' equivalent rather than having `define' create a shadowing definition of the session variable. That is important in order to avoid the values of the variable diverging between parser module and `lily'.
Diffstat (limited to 'scm')
-rw-r--r--scm/lily.scm22
1 files changed, 18 insertions, 4 deletions
diff --git a/scm/lily.scm b/scm/lily.scm
index 5ead4e6c9c..ce3486cf3f 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -86,6 +86,7 @@
;;
(define lilypond-declarations '())
+(define lilypond-exports '())
(define after-session-hook (make-hook))
(define-public (call-after-session thunk)
@@ -115,10 +116,14 @@ session has started."
`(,add-session-variable ',name ,value))
(defmacro-public define-session-public (name value)
- "Like @code{define-session}, but also exports @var{name}."
- `(begin
- (define-session ,name ,value)
- (export ,name)))
+ "Like @code{define-session}, but also exports @var{name} into parser modules."
+ (define (add-session-variable name value)
+ (if (ly:undead? lilypond-declarations)
+ (ly:error (_ "define-session-public used after session start")))
+ (let ((var (make-variable value)))
+ (module-add! (current-module) name var)
+ (set! lilypond-exports (acons name var lilypond-exports))))
+ `(,add-session-variable ',name ,value))
(define (session-terminate)
(if (ly:undead? lilypond-declarations)
@@ -158,7 +163,16 @@ variables to their value after the initial call of @var{thunk}."
(module-add! (current-module) (car p) var))))
(ly:get-undead lilypond-declarations)))
(begin
+ ;; import all public session variables natively into parser
+ ;; module. That makes them behave identically under define/set!
+ (for-each (lambda (v)
+ (module-add! (current-module) (car v) (cdr v)))
+ lilypond-exports)
+ ;; Initialize first session
(thunk)
+ ;; lilypond-exports is no longer needed since we will grab its
+ ;; values from (current-module).
+ (set! lilypond-exports #f)
(set! lilypond-interfaces
(filter (lambda (m) (eq? 'interface (module-kind m)))
(module-uses (current-module))))