]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4191: Add a \first-visible markup command which uses the first
authorDan Eble <nine.fierce.ballads@gmail.com>
Sat, 8 Nov 2014 19:55:15 +0000 (14:55 -0500)
committerDan Eble <nine.fierce.ballads@gmail.com>
Thu, 20 Nov 2014 23:10:16 +0000 (18:10 -0500)
argument that produces a non-empty stencil and ignores the rest.

input/regression/markup-first-visible.ly [new file with mode: 0644]
scm/define-markup-commands.scm

diff --git a/input/regression/markup-first-visible.ly b/input/regression/markup-first-visible.ly
new file mode 100644 (file)
index 0000000..bba748c
--- /dev/null
@@ -0,0 +1,87 @@
+\version "2.19.16"
+
+\header {
+  texidoc = "The markup command @code{\\first-visible} uses the first argument that produces a non-empty stencil and ignores the rest.
+
+The expected markup on this score is \"Lame Songs for Testing\" followed by a \"C\" time signature symbol."
+
+  publication = "Lame Songs for Testing"
+}
+
+#(ly:expect-warning "Cannot find glyph nonesuch-1")
+#(ly:expect-warning "Cannot find glyph nonesuch-2")
+
+\paper {
+  scoreTitleMarkup = \markup {
+    \first-visible {
+      \musicglyph #"nonesuch-1"
+      \fromproperty #'header:composer
+      \italic \fromproperty #'header:publication
+    }
+    \first-visible {
+      \musicglyph #"timesig.C44"
+      \musicglyph #"this should not be attempted"
+    }
+  }
+}
+
+\score { f' }
+
+\markup {
+  No elements: \first-visible {}
+}
+
+\markup {
+  One element (expect 111): \first-visible { 111 }
+}
+
+\markup {
+  Single markup list (expect aaa):
+  \first-visible \column-lines {
+  \musicglyph #"nonesuch-2"
+  ""
+  aaa
+  bbb
+  }
+}
+
+\markup {
+  Multiple markup lists (expect ccc):
+  \first-visible {
+    \column-lines { }
+    \column-lines { ccc ddd }
+    \column-lines { eee }
+  }
+}
+
+\markup {
+  Mixed markup and markup lists (expect fff):
+  \first-visible {
+    ""
+    \column-lines { }
+    \normal-text fff
+    \column-lines { ggg hhh }
+    iii
+  }
+}
+
+\markup {
+  Nested markup lists (expect jjj):
+  \first-visible {
+    \column-lines {
+      \column-lines {
+        \column-lines {
+         ""
+        }
+      }
+    }
+    \column-lines {
+      \column-lines {
+        \column-lines {
+          jjj
+        }
+      }
+    }
+    kkk
+  }
+}
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 ""))