Include a file only once, new version: Difference between revisions
Appearance
Import snippet from LSR |
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series |
||
| Line 3: | Line 3: | ||
Compliments? Complaints? Contact Marnen Laibow-Koser, marnen AT marnen DOT org. Enjoy! | Compliments? Complaints? Contact Marnen Laibow-Koser, marnen AT marnen DOT org. Enjoy! | ||
<lilypond version="2.24 | <lilypond version="2.24"> | ||
%%http://lsr.di.unimi.it/LSR/Item?id=894 | %%http://lsr.di.unimi.it/LSR/Item?id=894 | ||
Revision as of 18:49, 16 November 2025
This snippet lets you include a file only once, which is great for breaking circular dependency issues. Inspired by code from snippet 657 this thread.
Compliments? Complaints? Contact Marnen Laibow-Koser, marnen AT marnen DOT org. Enjoy!
\version "2.24"
%%http://lsr.di.unimi.it/LSR/Item?id=894
% includeOnce: include a file only if it hasn't already been included.
% Usage: \includeOnce "my_file.ily"
% By Marnen Laibow-Koser <marnen@marnen.org>
% Based on http://lsr.di.unimi.it/LSR/Snippet?id=657
% and
% http://lilypond.1069038.n5.nabble.com/conditional-include-td140471.html
includeOnce =
#(define-void-function (filename) (string?)
(if
(not (defined? (string->symbol filename)))
(begin
(ly:parser-include-string
(string-concatenate
(list "\\include \"" filename "\"")))
(primitive-eval (list 'define (string->symbol filename) #t)))))
\markup { "Dummy output so that the database doesn't complain." }