From: David Kastrup Date: Thu, 17 Oct 2013 10:52:53 +0000 (+0200) Subject: Issue 2067: Give all of \display{LilyMusic,Music,Scheme} optional port arguments. X-Git-Tag: release/2.19.0-1~44 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=285eeff8e02bb07122da0dc36bb9fd34885f4ac3;p=lilypond.git Issue 2067: Give all of \display{LilyMusic,Music,Scheme} optional port arguments. --- diff --git a/Documentation/extending/scheme-tutorial.itely b/Documentation/extending/scheme-tutorial.itely index bad8d261b2..7503306b1f 100644 --- a/Documentation/extending/scheme-tutorial.itely +++ b/Documentation/extending/scheme-tutorial.itely @@ -1134,23 +1134,30 @@ will display By default, LilyPond will print these messages to the console along with all the other messages. To split up these messages and save -the results of @code{\display@{STUFF@}}, redirect the output to -a file. +the results of @code{\display@{STUFF@}}, you can specify an optional +output port to use: @example -lilypond file.ly >display.txt +@{ + \displayMusic #(open-output-file "display.txt") @{ c'4\f @} +@} @end example -With a combined bit of Lilypond and Scheme magic, you can actually -let Lilypond direct just this output to a file of its own: - +This will overwrite a previous output file whenever it is called; if you +need to write more than one expression, you would use a variable for +your port and reuse it: @example @{ - #(with-output-to-file "display.txt" - (lambda () #@{ \displayMusic @{ c'4\f @} #@})) + port = #(open-output-file "display.txt") + \displayMusic \port @{ c'4\f @} + \displayMusic \port @{ d'4 @} + #(close-output-port port) @} @end example +Guile's manual describes ports in detail. Closing the port is actually +only necessary if you need to read the file before Lilypond finishes; in +the first example, we did not bother to do so. A bit of reformatting makes the above information easier to read: diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 83c2535af5..7310b8d0ff 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -344,25 +344,30 @@ in a CueVoice oriented by @var{dir}.") displayLilyMusic = -#(define-music-function (parser location music) (ly:music?) +#(define-music-function (parser location port music) ((output-port?) ly:music?) (_i "Display the LilyPond input representation of @var{music} -to the console.") - (newline) - (display-lily-music music parser) +to @var{port}, defaulting to the console.") + (let ((port (or port (current-output-port)))) + (newline port) + (display-lily-music music parser port)) music) displayMusic = -#(define-music-function (parser location music) (ly:music?) - (_i "Display the internal representation of @var{music} to the console.") - (newline) - (display-scheme-music music) +#(define-music-function (parser location port music) ((output-port?) ly:music?) + (_i "Display the internal representation of @var{music} to +@var{port}, default to the console.") + (let ((port (or port (current-output-port)))) + (newline port) + (display-scheme-music music port)) music) displayScheme = -#(define-scheme-function (parser location expr) (scheme?) - (_i "Display the internal representation of @var{expr} to the console.") - (newline) - (display-scheme-music expr) +#(define-scheme-function (parser location port expr) ((output-port?) scheme?) + (_i "Display the internal representation of @var{expr} to +@var{port}, default to the console.") + (let ((port (or port (current-output-port)))) + (newline port) + (display-scheme-music expr port)) expr)