OLD | NEW |
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) 2003--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 3 ;;;; Copyright (C) 2003--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
4 ;;;; | 4 ;;;; |
5 ;;;; LilyPond is free software: you can redistribute it and/or modify | 5 ;;;; LilyPond is free software: you can redistribute it and/or modify |
6 ;;;; it under the terms of the GNU General Public License as published by | 6 ;;;; it under the terms of the GNU General Public License as published by |
7 ;;;; the Free Software Foundation, either version 3 of the License, or | 7 ;;;; the Free Software Foundation, either version 3 of the License, or |
8 ;;;; (at your option) any later version. | 8 ;;;; (at your option) any later version. |
9 ;;;; | 9 ;;;; |
10 ;;;; LilyPond is distributed in the hope that it will be useful, | 10 ;;;; LilyPond is distributed in the hope that it will be useful, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 command. There is no protection against circular definitions. | 97 command. There is no protection against circular definitions. |
98 " | 98 " |
99 (let* ((command (if (pair? command-and-args) | 99 (let* ((command (if (pair? command-and-args) |
100 (car command-and-args) | 100 (car command-and-args) |
101 command-and-args)) | 101 command-and-args)) |
102 (args (and (pair? command-and-args) (cdr command-and-args)))) | 102 (args (and (pair? command-and-args) (cdr command-and-args)))) |
103 (if args | 103 (if args |
104 `(,define-markup-command-internal | 104 `(,define-markup-command-internal |
105 ',command (markup-lambda ,args ,@definition) #f) | 105 ',command (markup-lambda ,args ,@definition) #f) |
106 `(,define-markup-command-internal | 106 `(,define-markup-command-internal |
107 ',command ,@definition #f)))) | 107 - ',command ,@definition #f)))) |
| 108 |
| 109 (defmacro-public define-markup-command-compilable (command-and-args . definition
) |
| 110 "Like define-markup-command, but for use in LilyPond .scm files. We |
| 111 generate define-public statements, so the .scm files can be compiled" |
| 112 (let* |
| 113 ((command (car command-and-args)) |
| 114 (args (cdr command-and-args)) |
| 115 (command-name (string->symbol (format #f "~a-markup" command))) |
| 116 (make-markup-name-str (format #f "make-~a" command-name)) |
| 117 (make-markup-name (string->symbol make-markup-name-str))) |
| 118 |
| 119 `(begin |
| 120 (define-public ,command-name |
| 121 (markup-lambda ,args ,@definition)) |
| 122 (define-public ,make-markup-name |
| 123 (lambda markup-args (make-markup ,command-name ,make-markup-name-str ma
rkup-args))) |
| 124 |
| 125 (if (not (procedure-name ,command-name)) |
| 126 (set-procedure-property! ,command-name 'name (quote ,command-name))) |
| 127 ))) |
108 | 128 |
109 (defmacro*-public markup-lambda | 129 (defmacro*-public markup-lambda |
110 (args signature | 130 (args signature |
111 #:key (category '()) (properties '()) | 131 #:key (category '()) (properties '()) |
112 #:rest body) | 132 #:rest body) |
113 "Defines and returns an anonymous markup command. Other than | 133 "Defines and returns an anonymous markup command. Other than |
114 not registering the markup command, this is identical to | 134 not registering the markup command, this is identical to |
115 `define-markup-command`" | 135 `define-markup-command`" |
116 (while (and (pair? body) (keyword? (car body))) | 136 (while (and (pair? body) (keyword? (car body))) |
117 (set! body (cddr body))) | 137 (set! body (cddr body))) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 (let* ((command (if (pair? command-and-args) | 180 (let* ((command (if (pair? command-and-args) |
161 (car command-and-args) | 181 (car command-and-args) |
162 command-and-args)) | 182 command-and-args)) |
163 (args (and (pair? command-and-args) (cdr command-and-args)))) | 183 (args (and (pair? command-and-args) (cdr command-and-args)))) |
164 (if args | 184 (if args |
165 `(,define-markup-command-internal | 185 `(,define-markup-command-internal |
166 ',command (markup-list-lambda ,args ,@definition) #t) | 186 ',command (markup-list-lambda ,args ,@definition) #t) |
167 `(,define-markup-command-internal | 187 `(,define-markup-command-internal |
168 ',command ,@definition #t)))) | 188 ',command ,@definition #t)))) |
169 | 189 |
| 190 (defmacro-public define-markup-list-command-compilable |
| 191 (command-and-args . definition) |
| 192 "Like `define-markup-list-command`, but using define-public, so it |
| 193 can be compiled." |
| 194 (let* ((command (car command-and-args)) |
| 195 (args (cdr command-and-args)) |
| 196 (command-name-str (format #f "~a-markup-list" command)) |
| 197 (command-name (string->symbol command-name-str)) |
| 198 (make-markup-name-str (format #f "make-~a-markup-list" command)) |
| 199 (make-markup-name (string->symbol make-markup-name-str))) |
| 200 |
| 201 `(begin |
| 202 (define-public ,command-name |
| 203 (markup-list-lambda ,args ,@definition)) |
| 204 (define-public ,make-markup-name |
| 205 (lambda markup-args |
| 206 (list (make-markup ,command-name ,make-markup-name-str markup-args)) |
| 207 ))) |
| 208 )) |
| 209 |
170 (define (define-markup-command-internal command definition is-list) | 210 (define (define-markup-command-internal command definition is-list) |
171 (let* ((suffix (if is-list "-list" "")) | 211 """Define a markup command at runtime. Called from the parser.""" |
| 212 (let* ( |
| 213 (suffix (if is-list "-list" "")) |
172 (command-name (string->symbol (format #f "~a-markup~a" command suffix))
) | 214 (command-name (string->symbol (format #f "~a-markup~a" command suffix))
) |
173 (make-markup-name (string->symbol (format #f "make-~a-markup~a" command
suffix)))) | 215 (make-markup-name (string->symbol (format #f "make-~a-markup~a" command
suffix)))) |
| 216 |
174 (if (not (procedure-name definition)) | 217 (if (not (procedure-name definition)) |
175 (set-procedure-property! definition 'name command-name)) | 218 (set-procedure-property! definition 'name command-name)) |
176 (module-define! (current-module) command-name definition) | 219 (module-define! (current-module) command-name definition) |
177 (module-define! (current-module) make-markup-name | 220 (module-define! (current-module) make-markup-name |
178 (lambda args | 221 (lambda args |
179 (if is-list | 222 (if is-list |
180 (list (make-markup definition make-markup-name args)) | 223 (list (make-markup definition make-markup-name args)) |
181 (make-markup definition make-markup-name args)))) | 224 (make-markup definition make-markup-name args)))) |
182 (module-export! (current-module) | 225 (module-export! (current-module) |
183 (list command-name make-markup-name)))) | 226 (list command-name make-markup-name)))) |
184 | 227 |
185 (defmacro*-public markup-list-lambda | 228 (defmacro*-public markup-list-lambda |
186 (arg signature #:key (properties '()) #:rest body) | 229 (arg signature #:key (properties '()) #:rest body) |
187 "Same as `markup-lambda' but defines a markup list command that, when | 230 "Same as `markup-lambda' but defines a markup list command that, when |
188 interpreted, returns a list of stencils instead of a single one" | 231 interpreted, returns a list of stencils instead of a single one" |
189 (let () ; Guile 1.8 defmacro* workaround | 232 (let () ; Guile 1.8 defmacro* workaround |
190 (define (markup-lambda-listify fun) | 233 (define (markup-lambda-listify fun) |
191 (set! (markup-list-function? fun) #t) | 234 (set! (markup-list-function? fun) #t) |
192 fun) | 235 fun) |
193 (list markup-lambda-listify (cons* 'markup-lambda arg signature body)))) | 236 (list markup-lambda-listify (cons* 'markup-lambda arg signature body)))) |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 (let ((proc (lookup-markup-command-aux | 462 (let ((proc (lookup-markup-command-aux |
420 (string->symbol (format #f "~a-markup" code))))) | 463 (string->symbol (format #f "~a-markup" code))))) |
421 (and proc (markup-function? proc) | 464 (and proc (markup-function? proc) |
422 (cons proc (markup-command-signature proc))))) | 465 (cons proc (markup-command-signature proc))))) |
423 | 466 |
424 (define-public (lookup-markup-list-command code) | 467 (define-public (lookup-markup-list-command code) |
425 (let ((proc (lookup-markup-command-aux | 468 (let ((proc (lookup-markup-command-aux |
426 (string->symbol (format #f "~a-markup-list" code))))) | 469 (string->symbol (format #f "~a-markup-list" code))))) |
427 (and proc (markup-list-function? proc) | 470 (and proc (markup-list-function? proc) |
428 (cons proc (markup-command-signature proc))))) | 471 (cons proc (markup-command-signature proc))))) |
OLD | NEW |