Am So., 18. Nov. 2018 um 20:40 Uhr schrieb David Kastrup <d...@gnu.org>:

> Just do
>
> (eq? ctx (ly:context-find ctx 'Staff))
>
> --
> David Kastrup

I did not even consider to use ly:context-find. The description says:
Find a _parent_ of context that has name or alias name. Return #f if not found.
So I expected it could return
Staff as parent of Voice
StaffGroup as parent of Staff
Score as parent of StaffGroup

Similar to
Function: ly:context-parent context
    Return the parent of context, #f if none.
Although this one returns a tree of contexts not even a single parent.
At least for me this was a surprise.

Is my understanding of parents with contexts entirely wrong ...?

Anyway, the following works very nicely:

foo =
  \applyContext
    #(lambda (ctx)
       (let* ((ctx-name (ly:context-name ctx)))
         (if (eq? ctx (ly:context-find ctx 'Staff))
             (format #t "\n\tI'm in a staff-like context: ~a" ctx-name)
             (format #t "\n\tWrong here in: ~a" ctx-name))))

\score {
  <<
    \new StaffGroup R1
    \new Staff R1
    \new TabStaff R1
    \new DrumStaff R1
    \new ChoirStaff R1
  >>
  \layout {
      \context Staff \foo
    \context {
      \StaffGroup
      \foo
    }
    \context {
      \ChoirStaff
      \foo
    }
  }
}

Thanks,
  Harm

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to