]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-markup-commands.scm
Issue 4191: Add a \first-visible markup command which uses the first
[lilypond.git] / scm / define-markup-commands.scm
index dbede18018b139fe374ca528b9e5763d9827c540..f92cf84f053340c99189ed91e0c5be72a7b6f5f4 100644 (file)
@@ -1157,6 +1157,31 @@ the use of @code{\\simple} is unnecessary.
 @end lilypond"
   (interpret-markup layout props str))
 
+(define-markup-command (first-visible layout props args)
+  (markup-list?)
+  #:category other
+  "Use the first markup in @var{args} that yields a non-empty stencil
+and ignore the rest.
+
+@lilypond[verbatim,quote]
+\\markup {
+  \\first-visible {
+    \\fromproperty #'header:composer
+    \\italic Unknown
+  }
+}
+@end lilypond"
+  (define (false-if-empty stencil)
+    (if (ly:stencil-empty? stencil) #f stencil))
+  (or
+   (any
+    (lambda (m)
+      (if (markup? m)
+          (false-if-empty (interpret-markup layout props m))
+          (any false-if-empty (interpret-markup-list layout props (list m)))))
+    args)
+   empty-stencil))
+
 (define-public empty-markup
   (make-simple-markup ""))