]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 5145/2: Allow $... to specify a markup command
authorDavid Kastrup <dak@gnu.org>
Mon, 12 Jun 2017 11:44:51 +0000 (13:44 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 12 Jun 2017 15:17:45 +0000 (17:17 +0200)
This is a partial (though more flexible) substitute for \on-the-fly
since it allows to replace

\on-the-fly #(lambda (layout props args) ...)

with

$(let ((fun (lambda (layout props args) ...)))
   (set! (markup-command-signature fun) (list markup?))
   fun)

Namely: ad-hoc written functions (probably most useful when written
using macros) can be employed as markup commands when preceded with $
as long as they have a suitable markup command signature attached.
This feature is mainly added for consistency with music functions.

lily/include/lily-imports.hh
lily/lexer.ll
lily/lily-imports.cc

index d930f69cf940527ddd9eba2703ecf5920e220d34..1b63a537179a5a20f8922f008102d2692d7731a6 100644 (file)
@@ -86,6 +86,7 @@ namespace Lily {
   extern Variable make_safe_lilypond_module;
   extern Variable make_span_event;
   extern Variable markup_p;
+  extern Variable markup_command_signature;
   extern Variable markup_list_p;
   extern Variable midi_program;
 #if !GUILEV2
index 19f84616f36ca3d38179f397daddfb1291a1d9ab..21d2fc1acc16bc32cd224c1e0013fcf93151db4f 100644 (file)
@@ -417,6 +417,20 @@ BOM_UTF8   \357\273\277
 
        sval = eval_scm (sval, hi, '$');
 
+       if (YYSTATE == markup && ly_is_procedure (sval))
+       {
+               SCM sig = Lily::markup_command_signature (sval);
+               if (scm_is_true (sig))
+               {
+                       yylval = sval;
+                       int token = MARKUP_FUNCTION;
+                       if (scm_is_true (scm_object_property
+                                        (sval, ly_symbol2scm ("markup-list-command"))))
+                               token = MARKUP_LIST_FUNCTION;
+                       push_markup_predicates (sig);
+                       return token;
+               }
+       }
        int token = scan_scm_id (sval);
        if (!scm_is_eq (yylval, SCM_UNSPECIFIED))
                return token;
index 62e58b603c1ff36e8c150fbf920c9e6bae711965..f3cd3b1ab244b6287fec83edaa75b1f8f2b84334 100644 (file)
@@ -80,6 +80,7 @@ namespace Lily {
   Variable make_safe_lilypond_module ("make-safe-lilypond-module");
   Variable make_span_event ("make-span-event");
   Variable markup_p ("markup?");
+  Variable markup_command_signature ("markup-command-signature");
   Variable markup_list_p ("markup-list?");
   Variable midi_program ("midi-program");
 #if !GUILEV2