]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4487/3: Implement partial markups
authorDavid Kastrup <dak@gnu.org>
Sun, 15 Jun 2014 12:12:34 +0000 (14:12 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 18 Jul 2015 04:42:13 +0000 (06:42 +0200)
A partial markup acts as a chain of markup commands where everything but
the final markup has already been supplied.

For example:

bold-red-markup = \markup \bold \with-color #red \etc

\markup \bold-red "text"
\markuplist \column-lines \bold-red { One Two Three }

Please note that in order for \markup to recognize the resulting markup
command inside of markup expressions, the identifier to which the
resulting markup command is assigned needs to have "-markup" appended to
its name: LilyPond encodes markup command names in this manner so that
markup commands can use the same name as other entities outside of
markup mode.

Note also that this will not work with the markup macro since the latter
additionally requires the definition of a suitable make-bold-red-markup
command.

input/regression/markup-partial.ly [new file with mode: 0644]
lily/include/lily-imports.hh
lily/lily-imports.cc
lily/parser.yy
scm/ly-syntax-constructors.scm

diff --git a/input/regression/markup-partial.ly b/input/regression/markup-partial.ly
new file mode 100644 (file)
index 0000000..37d2255
--- /dev/null
@@ -0,0 +1,14 @@
+\version "2.19.24"
+
+\header
+{ texidoc = "Partial markups acts as a chain of markup
+  commands where everything but the final markup has already been
+  supplied."
+}
+
+\layout { ragged-right = ##t }
+
+bold-red-markup = \markup \bold \with-color #red \etc
+
+\markup \bold-red "Single markup"
+\markuplist \column-lines \bold-red { Markups in a list. }
index 535b40bea40a07e8672e3af8e96001056adee75c..383896a021614e54b3fec2ec87399cafb6c0c2c4 100644 (file)
@@ -119,6 +119,7 @@ namespace Syntax {
   extern Variable multi_measure_rest;
   extern Variable music_function;
   extern Variable music_function_call_error;
+  extern Variable partial_markup;
   extern Variable partial_music_function;
   extern Variable property_operation;
   extern Variable repeat;
index 2a8ecf9e84579893b459edd24138871b116d56f9..3a694f9d10e23bd7d56314c955ca5736edb88080 100644 (file)
@@ -112,6 +112,7 @@ namespace Syntax {
   Variable multi_measure_rest ("multi-measure-rest");
   Variable music_function ("music-function");
   Variable music_function_call_error ("music-function-call-error");
+  Variable partial_markup ("partial-markup");
   Variable partial_music_function ("partial-music-function");
   Variable property_operation ("property-operation");
   Variable repeat ("repeat");
index e8fb1b9383d028c580082cb2fcbfa8870e9a4bd7..9da363df933d208053348e40223a98e6ea359a6e 100644 (file)
@@ -510,6 +510,7 @@ embedded_scm_bare_arg:
                $$ = parser->lexer_->eval_scm_token ($1, @1);
        }
        | FRACTION
+       | partial_markup
        | full_markup_list
        | context_modification
        | score_block
@@ -692,6 +693,7 @@ identifier_init_nonumber:
        | FRACTION
        | string
         | embedded_scm
+       | partial_markup
        | full_markup_list
         | context_modification
        | partial_function ETC
@@ -3612,11 +3614,24 @@ full_markup_list:
        }
        ;
 
-full_markup:
+markup_mode:
        MARKUP
-               { parser->lexer_->push_markup_state (); }
-       markup_top {
-               $$ = $3;
+       {
+               parser->lexer_->push_markup_state ();
+       }
+       ;
+
+full_markup:
+       markup_mode markup_top {
+               $$ = $2;
+               parser->lexer_->pop_state ();
+       }
+       ;
+
+partial_markup:
+       markup_mode markup_head_1_list ETC
+       {
+               $$ = MAKE_SYNTAX (partial_markup, @2, $2);
                parser->lexer_->pop_state ();
        }
        ;
index b617f72764eaa5a44e1af6414a5db2eea63a8116..a0d35ae92e31b175309f2a7e00089aed0ae4b121 100644 (file)
@@ -198,6 +198,19 @@ into a @code{MultiMeasureTextEvent}."
                       (make-map-markup-commands-markup-list
                        compose complex) completed))))))))
 
+(define-public (partial-markup commands)
+  ;; Like composed-markup-list, except that the result is a single
+  ;; markup command that can be applied to one markup
+  (define (compose arg)
+    (fold
+     (lambda (cmd prev) (append cmd (list prev)))
+     arg
+     commands))
+  (let ((chain (lambda (layout props arg)
+                 (interpret-markup layout props (compose arg)))))
+    (set-object-property! chain 'markup-signature (list markup?))
+    chain))
+
 (define-public (property-operation ctx music-type symbol . args)
   (let* ((props (case music-type
                   ((PropertySet) (list 'value (car args)))