lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "include" music-function


From: Jan-Peter Voigt
Subject: Re: "include" music-function
Date: Fri, 06 Jan 2012 09:35:56 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111108 Lightning/1.0b2 Thunderbird/3.1.16

Hello David,

the \sourcefilename hint is helpful! Thank you!
If I use this in my function and do a ly:parser-clone, the location is up to date:

--snip--
#(define-public showloc (define-music-function (parser location)()
    (format #t ">>> ~A\n" (ly:input-file-line-char-column location))
    (make-music 'SequentialMusic 'void #t)))

#(define-public includeLocal (define-music-function (parser location file)(string?)
    (let ((outname (format "~A.ly" (ly:parser-output-name parser)))
          (locname (car (ly:input-file-line-char-column location))))
(if (or (string=? outname locname)(string-suffix? outname locname))
             (ly:parser-parse-string (ly:parser-clone parser)
(format "\\sourcefilename \"~A\"\n\\sourcefileline ~A\n~A" file 0 (ly:gulp-file file))))
         (make-music 'SequentialMusic 'void #t))))
--snip--

Now I will look, if this is working also with ly:parser-include-string while resetting filename and fileline at the end, so that definitions in the included file get into the current parser.

Cheers,
Jan-Peter

Am 05.01.2012 17:14, schrieb David Kastrup:
Jan-Peter Voigt<address@hidden>  writes:

#(define-public includeLocal (define-music-function (parser location
file)(string?)
     (let ((outname (format "~A.ly" (ly:parser-output-name parser)))
           (locname (car (ly:input-file-line-char-column location))))
          (if (or (string=? outname locname)(string-suffix? outname
locname))
              (let ((content (ly:gulp-file file)))
                   (ly:parser-include-string parser content)))
          (make-music 'SequentialMusic 'void #t))))

\includeLocal "test.ly"
--snip--
This function first compares the outname with the location name and
only includes the file if they match. (This should not work, if you
have set some output-suffix!)

This is a usable solution to me. But I would like to have the correct
location info available, while parsing the included file.
Is it possible to create an arbitrary "include"-music-function? This
would make it possible, to (for example) include all files in a
directory or matching a specific pattern.
You can start your string with \sourcefilename and \sourcefileline.
ly:parser-parse-expression has optional arguments for that purpose.  If
you would consider this helpful, I might try fudging this into
parser-include-string as well.

I have not followed the reasons why we would not have
parser-include-file.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]