+settingsFrom =
+#(define-scheme-function (parser location ctx music)
+ ((symbol?) ly:music?)
+ (_i "Take the layout instruction events from @var{music}, optionally
+restricted to those applying to context type @var{ctx}, and return
+a context modification duplicating their effect.")
+ (let ((mods (ly:make-context-mod)))
+ (define (musicop m)
+ (if (music-is-of-type? m 'layout-instruction-event)
+ (ly:add-context-mod
+ mods
+ (case (ly:music-property m 'name)
+ ((PropertySet)
+ (list 'assign
+ (ly:music-property m 'symbol)
+ (ly:music-property m 'value)))
+ ((PropertyUnset)
+ (list 'unset
+ (ly:music-property m 'symbol)))
+ ((OverrideProperty)
+ (list 'push
+ (ly:music-property m 'symbol)
+ (ly:music-property m 'grob-property-path)
+ (ly:music-property m 'grob-value)))
+ ((RevertProperty)
+ (list 'pop
+ (ly:music-property m 'symbol)
+ (ly:music-property m 'grob-property-path)))))
+ (case (ly:music-property m 'name)
+ ((SequentialMusic SimultaneousMusic)
+ (for-each musicop (ly:music-property m 'elements)))
+ ((ContextSpeccedMusic)
+ (if (or (not ctx)
+ (eq? ctx (ly:music-property m 'context-type)))
+ (musicop (ly:music-property m 'element)))))))
+ (musicop music)
+ mods))
+