David Kastrup <[email protected]> writes:

> Paul Morris <[email protected]> writes:
>
>> This would really simplify the process of creating custom contexts,
>> especially in the common case of wanting a modified version of an
>> existing context that works everywhere it does.”
>>
>> See full discussion thread here:
>> http://lists.gnu.org/archive/html/lilypond-user/2015-02/msg00684.html
>
> The discussion does not lead to any workable conclusion.  In its course,
> there is a proposal of an additional \alias-like command that would
> differ with regard to \alias in that it would declare acceptability.
> That's all very wishy-washy.
>
> I think it would make more sense to have a command that will walk
> through an output definition and make the required changes, like
>
> \accept-like Voice myVoice
> \layout {
>   \context {
>     \Voice
>     \name "myVoice"
>     ...
>   }
> }
>
> That does not require new internals and is pretty straightforward to
> write as a scheme function taking two symbols and an output definition
> as arguments and returning an output definition.

Here is a proof of concept.

accept-like =
#(define-scheme-function (parser location old new out)
   (symbol? symbol? ly:output-def?)
   (for-each
    (lambda (p)
      (let* ((sym (car p))
	     (def (cdr p))
	     (acc (ly:context-def-lookup def 'accepts)))
	(if (and (memq old acc) (not (memq new acc)))
	    (ly:output-def-set-variable! out sym
					 (ly:context-def-modify
					  def
					  (ly:make-context-mod
					   `((accepts ,new))))))))
  (ly:output-find-context-def out))
  out)

\accept-like Voice my-Voice
\layout {
  \context {
    \Voice
    \name my-Voice
  }
}

{
  \new my-Voice { c1 }
}

-- 
David Kastrup
_______________________________________________
bug-lilypond mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-lilypond

Reply via email to