On 2021-08-07 11:52 am, R. Padraic Springuel wrote:
Is there a way for Lilypond to differentiate between a file which is
being compiled directly and it being included in the compilation of
another file? Something equivalent to `if __name__ == “__main__”`
from python? I’d like to add simple examples to my various tools that
I can use to test it (both during original development and after an
update which breaks something) and remind me of what the tool does
when I haven’t used it in a while. Ideally, I’d hide these examples
inside a construction like this so that the example output is only
produced when the tool file is compiled directly.
Perhaps something like this:
%%%%
\version "2.22.0"
ifCompiledDirectly =
#(define-scheme-function (scm) (scheme?)
(let ((file (car (ly:input-file-line-char-column (*location*)))))
(if (member file (command-line)) scm)))
\ifCompiledDirectly \markup "Compiled directly..."
\ifCompiledDirectly \score { { b'4 4 2 } }
%%%%
The logic is simple: check to see if the command-line arguments contain
the name of the file being processed.
-- Aaron Hill