On 16/03/2025 1:08, Saul Tobin wrote:
These are questions I've had to consider as I work on Emacs
lilypond-ts-mode, and I suspect are relevant to lots of tooling projects.
Since output file names and locations are potentially set via
arbitrary Scheme code, it's not feasible to do this reliably without
actually running the LilyPond binary itself to parse the input file.
It's certainly possible to do that without actually running
translation. The easiest way would be to make a custom init file that
defines `default-toplevel-book-handler` to a function that just calls
`get-current-filename` but doesn't actually call into ly:book-process,
then pass the custom init file to LilyPond via `-i`. For reference,
look at the definitions of the built-in toplevel handlers in
lily-library.scm. Note that `get-current-filename` is not exported
from `lily` into the session module. Also note that this will only
give you the filename, not the output directory if one was set via
`-o`. I believe you can get that by simply checking the current Guile
working directory.
I got a basic version of this working using a custom init file and using
@@ to force my way through to the get-outfile-name function. Now there
are two new problems:
1. get-outfile-name returns the base name, with no file extension. I
need to retrieve the output format set by the command line options
(--format).
2. This doesn't handle MIDI properly. MIDI scores, even when in the
same book, are output to different files, and the above system can't
predict that. I could leave this unsupported (which is reasonable),
but in any case I need some way to look "inside" the score to see if
it has a MIDI block.