bug-lilypond
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make defining new contexts simpler with better \alias functionality


From: David Kastrup
Subject: Re: Make defining new contexts simpler with better \alias functionality
Date: Fri, 06 Mar 2015 16:49:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

David Kastrup <address@hidden> writes:

> Paul Morris <address@hidden> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]