Re: Where was my music-function called?

David Kastrup <[email protected]> Sun, 26 Jul 2026 00:35:32 +0200
Newsgroups gmane.comp.gnu.lilypond.general
Organization Organization?!?
Message-ID <[email protected]>
--=-=-=
Content-Type: text/plain

Graham King <[email protected]> writes:

> 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 = #(define-music-function ()()
>             (ly:message "insertC called at line ~a" "foo")
>             #{ c'1 #} )
>
> { \repeat unfold 3 { c' d' e' f' }
>   \insertC
> }

I'd use ly:input-message:


--=-=-=
Content-Type: text/x-lilypond
Content-Disposition: inline; filename=xxx.ly

\version "2.27.1"

insertC = #(define-music-function ()()
            (ly:input-message (*location*) "insertC called")
            #{ c'1 #} )

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

--=-=-=
Content-Type: text/plain


This formats the output in a manner that you can use any IDE (like
Frescobaldi) to click on the message and get to the point in the source.

-- 
David Kastrup

--=-=-=--