LEFT | RIGHT |
1 ;;;; This file is part of LilyPond, the GNU music typesetter. | 1 ;;;; This file is part of LilyPond, the GNU music typesetter. |
2 ;;;; | 2 ;;;; |
3 ;;;; Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org> | 3 ;;;; Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org> |
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 ;;;; | 5 ;;;; |
6 ;;;; LilyPond is free software: you can redistribute it and/or modify | 6 ;;;; LilyPond is free software: you can redistribute it and/or modify |
7 ;;;; it under the terms of the GNU General Public License as published by | 7 ;;;; it under the terms of the GNU General Public License as published by |
8 ;;;; the Free Software Foundation, either version 3 of the License, or | 8 ;;;; the Free Software Foundation, either version 3 of the License, or |
9 ;;;; (at your option) any later version. | 9 ;;;; (at your option) any later version. |
10 ;;;; | 10 ;;;; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 (define lilypond-declarations '()) | 88 (define lilypond-declarations '()) |
89 (define lilypond-exports '()) | 89 (define lilypond-exports '()) |
90 (define after-session-hook (make-hook)) | 90 (define after-session-hook (make-hook)) |
91 | 91 |
92 (define-public (call-after-session thunk) | 92 (define-public (call-after-session thunk) |
93 (if (ly:undead? lilypond-declarations) | 93 (if (ly:undead? lilypond-declarations) |
94 (ly:error (_ "call-after-session used after session start"))) | 94 (ly:error (_ "call-after-session used after session start"))) |
95 (add-hook! after-session-hook thunk #t)) | 95 (add-hook! after-session-hook thunk #t)) |
96 | 96 |
| 97 (define (make-session-variable name value) |
| 98 (if (ly:undead? lilypond-declarations) |
| 99 (ly:error (_ "define-session used after session start"))) |
| 100 (let ((var (module-make-local-var! (current-module) name))) |
| 101 (if (variable-bound? var) |
| 102 (ly:error (_ "symbol ~S redefined") name)) |
| 103 (variable-set! var value) |
| 104 var)) |
| 105 |
97 (defmacro-public define-session (name value) | 106 (defmacro-public define-session (name value) |
98 "This defines a variable @var{name} with the starting value | 107 "This defines a variable @var{name} with the starting value |
99 @var{value} that is reinitialized at the start of each session. | 108 @var{value} that is reinitialized at the start of each session. |
100 A@tie{}session basically corresponds to one LilyPond file on the | 109 A@tie{}session basically corresponds to one LilyPond file on the |
101 command line. The value is recorded at the start of the first session | 110 command line. The value is recorded at the start of the first session |
102 after loading all initialization files and before loading the user | 111 after loading all initialization files and before loading the user |
103 file and is reinstated for all of the following sessions. This | 112 file and is reinstated for all of the following sessions. This |
104 happens just by replacing the value, not by copying structures, so you | 113 happens just by replacing the value, not by copying structures, so you |
105 should not destructively modify them. For example, lists defined in | 114 should not destructively modify them. For example, lists defined in |
106 this manner should be changed within a session only be adding material | 115 this manner should be changed within a session only be adding material |
107 to their front or replacing them altogether, not by modifying parts of | 116 to their front or replacing them altogether, not by modifying parts of |
108 them. It is an error to call @code{define-session} after the first | 117 them. It is an error to call @code{define-session} after the first |
109 session has started." | 118 session has started." |
110 (define (add-session-variable name value) | 119 (define (add-session-variable name value) |
111 (if (ly:undead? lilypond-declarations) | 120 (set! lilypond-declarations |
112 (ly:error (_ "define-session used after session start"))) | 121 (cons (make-session-variable name value) lilypond-declarations))) |
113 (let ((var (module-make-local-var! (current-module) name))) | |
114 (variable-set! var value) | |
115 (set! lilypond-declarations (cons var lilypond-declarations)))) | |
116 `(,add-session-variable ',name ,value)) | 122 `(,add-session-variable ',name ,value)) |
117 | 123 |
118 (defmacro-public define-session-public (name value) | 124 (defmacro-public define-session-public (name value) |
119 "Like @code{define-session}, but also exports @var{name} into parser modules." | 125 "Like @code{define-session}, but also exports @var{name} into parser modules." |
120 (define (add-session-variable name value) | 126 (define (add-session-variable name value) |
121 (if (ly:undead? lilypond-declarations) | 127 (set! lilypond-exports |
122 (ly:error (_ "define-session-public used after session start"))) | 128 (acons name (make-session-variable name value) lilypond-exports))) |
123 (let ((var (module-make-local-var! (current-module) name))) | 129 `(begin |
124 (variable-set! var value) | 130 ;; this is a bit icky: we place the variable right into every |
125 (set! lilypond-exports (acons name var lilypond-exports)))) | 131 ;; parser module so that both set! and define will affect the |
126 `(,add-session-variable ',name ,value)) | 132 ;; original variable in the (lily) module. However, we _also_ |
| 133 ;; export it normally from (lily) for the sake of other modules |
| 134 ;; not sharing the name space of the parser. |
| 135 (,add-session-variable ',name ,value) |
| 136 (export ,name))) |
127 | 137 |
128 (define (session-terminate) | 138 (define (session-terminate) |
129 (if (ly:undead? lilypond-declarations) | 139 (if (ly:undead? lilypond-declarations) |
130 (begin | 140 (begin |
131 (for-each | 141 (for-each |
132 (lambda (p) (variable-set! (cadr p) (cddr p))) | 142 (lambda (p) (variable-set! (cadr p) (cddr p))) |
133 (ly:get-undead lilypond-declarations)) | 143 (ly:get-undead lilypond-declarations)) |
134 (run-hook after-session-hook)))) | 144 (run-hook after-session-hook)))) |
135 | 145 |
136 (define lilypond-interfaces #f) | 146 (define lilypond-interfaces #f) |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 (ly:exit 0 #f))))) | 1113 (ly:exit 0 #f))))) |
1104 | 1114 |
1105 (define (gui-no-files-handler) | 1115 (define (gui-no-files-handler) |
1106 (let* ((ly (string-append (ly:effective-prefix) "/ly/")) | 1116 (let* ((ly (string-append (ly:effective-prefix) "/ly/")) |
1107 ;; FIXME: soft-code, localize | 1117 ;; FIXME: soft-code, localize |
1108 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly")) | 1118 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly")) |
1109 (cmd (get-editor-command welcome-ly 0 0 0))) | 1119 (cmd (get-editor-command welcome-ly 0 0 0))) |
1110 (ly:message (_ "Invoking `~a'...\n") cmd) | 1120 (ly:message (_ "Invoking `~a'...\n") cmd) |
1111 (system cmd) | 1121 (system cmd) |
1112 (ly:exit 1 #f))) | 1122 (ly:exit 1 #f))) |
LEFT | RIGHT |