Where was my music-function called?

Graham King <[email protected]> Fri, 24 Jul 2026 13:11:04 +0100
Newsgroups gmane.comp.gnu.lilypond.general
Message-ID <[email protected]>
I'm trying to debug some Scheme code, and it would be really helpful to
be able to make a music-function display the lilypond source-code-line-
number where the music-function was called.

Is this possible?

In other words, how can I make this code display "8" rather than "foo"?

(the message is the point; inserting a note is just random
functionality to illustrate the problem)

\version "2.27.1"

insertC =3D #(define-music-function ()()
            (ly:message "insertC called at line ~a" "foo")
            #{ c'1 #} )

{ \repeat unfold 3 { c' d' e' f' }
  \insertC
}

Grateful for any insights!
-- Graham