Am 23.07.2014 21:54, schrieb Urs Liska:
Am 23.07.2014 18:52, schrieb David Kastrup:
Urs Liska <u...@openlilylib.org> writes:
is it possible to take a music expression and print out its literal
input?
Sort of.
In other words: Could I write a function "\example" that takes a music
expression as an argument and that first outputs the input code as
text and then as a score?
So that
\example {
\relative c' {
c8 d e
}
}
Well, if you write
example =
#(make-scheme-function (parser location music) (ly:music)
...
then (ly:input-both-locations location)
will return
-- Function: ly:input-both-locations sip
Return input location in SIP as ‘(file-name first-line first-column
last-line last-column)’.
So you'll be able to take the input location information and read the
corresponding source from the file.
So you mean I should parse this (example result):
(/tmp/frescobaldi-4Orug3/tmp8Y5V5X/document.ly 8 0 16 1)
open the file (separately) from Scheme and read the given range?
You're right, that looks somewhat awkward but whould give me a start.
Thanks
Urs
I think "give me a start" was quite right.
Scheme so often makes me feel stupid. Now I manage to open the file but
I don't have any clue as to how to make its content available for
processing. I'd think I'd read it line by line, discarding the leading
and trailing lines outside the range, but I didn't manage to do anything
so far.
Attached is a funny by-product. Just include "display-input-file" in a
main file (or use the attached "show-file.ly") and watch the console
output ;-) .
Best
Urs
\version "2.19.6"
\include "display-input-file.ily"
%{
The included file will execute a function
which displays the content of the main input file
on the console output
%}
\relative c' {
c d e f g1
}
\version "2.19.6"
#(use-modules (ice-9 rdelim))
#(define (display-file port)
(let* ((line (read-line port 'split))
(linestr (car line))
(del (cdr line)))
(if (eof-object? del)
'()
(begin
(display linestr)(newline)
(display-file port)))))
displayFile =
#(define-void-function (parser location)()
(call-with-input-file
(string-append (ly:parser-output-name parser) ".ly")
display-file))
\displayFile
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user