lilypond-user
[Top][All Lists]
Advanced

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

Re: Differentiate between including and direct compiling a file


From: Aaron Hill
Subject: Re: Differentiate between including and direct compiling a file
Date: Sat, 07 Aug 2021 12:54:27 -0700
User-agent: Roundcube Webmail/1.4.9

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



reply via email to

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