]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2874: Provide an \undo function for turning overrides and sets into reverts...
authorDavid Kastrup <dak@gnu.org>
Wed, 3 Oct 2012 11:38:24 +0000 (13:38 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 12 Oct 2012 13:13:27 +0000 (15:13 +0200)
\undo\hideNotes is equivalent to \unHideNotes, \undo\easyHeadsOn to
\easyHeadsOff.  While this can't undo reverts, it is useful for a lot
of overriding commands defined in ly/property-init.ly, and is also
useful in combination with \hide/\omit.

ly/music-functions-init.ly

index 2180b895e12c2d0e06bb9f1fd7fedd1e0a32ffb6..4fa31929d4ef9e2188ba5745612b092c870143e7 100644 (file)
@@ -1321,6 +1321,50 @@ are affected.")
           (ly:music-property music 'tweaks)))
    music)
 
+undo =
+#(define-music-function (parser location music)
+   (ly:music?)
+   (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
+@code{\\revert} and @code{\\unset}, respectively.  Any reverts and
+unsets already in @var{music} are ignored and not converted.")
+   (let loop
+       ((music music))
+     (let
+         ((lst
+           (fold-some-music
+            (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
+                            (music-is-of-type? m 'context-specification)))
+            (lambda (m overrides)
+              (case (ly:music-property m 'name)
+                ((OverrideProperty)
+                 (cons
+                  (make-music 'RevertProperty
+                              'symbol (ly:music-property m 'symbol)
+                              'grob-property-path
+                              (cond
+                               ((ly:music-property m 'grob-property #f) => list)
+                               (else
+                                (ly:music-property m 'grob-property-path))))
+                  overrides))
+                ((PropertySet)
+                 (cons
+                  (make-music 'PropertyUnset
+                              'symbol (ly:music-property m 'symbol))
+                  overrides))
+                ((ContextSpeccedMusic)
+                 (cons
+                  (make-music 'ContextSpeccedMusic
+                              'element (loop (ly:music-property m 'element))
+                              'context-type (ly:music-property m 'context-type))
+                  overrides))
+                (else overrides)))
+            '()
+            music)))
+       (cond
+        ((null? lst) (make-music 'Music))
+        ((null? (cdr lst)) (car lst))
+        (else (make-sequential-music lst))))))
+
 unfoldRepeats =
 #(define-music-function (parser location music) (ly:music?)
    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or