From: Dan Eble Date: Sat, 8 Nov 2014 19:55:15 +0000 (-0500) Subject: Issue 4191: Add a \first-visible markup command which uses the first X-Git-Tag: release/2.19.16-1~2^2~59^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1505d82a3b0bed986270d864865817b6207cf179;p=lilypond.git Issue 4191: Add a \first-visible markup command which uses the first argument that produces a non-empty stencil and ignores the rest. --- diff --git a/input/regression/markup-first-visible.ly b/input/regression/markup-first-visible.ly new file mode 100644 index 0000000000..bba748cd93 --- /dev/null +++ b/input/regression/markup-first-visible.ly @@ -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 + } +} diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index dbede18018..f92cf84f05 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -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 ""))