After some (...) pain with guile/scheme I come up with the
 functions below.

 Use them like
la = \lyricmode { war -- um,:?!; }
\addlyrics { \u\la \a\la "." }
  will get you
War -- um,:?!; war -- um.

////////

(define u
  (define-music-function (music) (ly:music?)
    (let* ((elm (ly:music-property music 'elements))
           (fst (car elm))
           (txt (ly:music-property fst 'text))
           (Txt "")
           )
      (if (string? txt)
          (begin
            (set! Txt (string-capitalize txt))
            (ly:music-set-property! fst 'text Txt)
            )
          )
      )
    music))

(define a
  (define-music-function (music chr) (ly:music? string?)
    (let* ((elm (ly:music-property music 'elements))
           (len (length elm))
           (lst (car (list-tail elm (- len 1))))
           (txt (ly:music-property lst 'text))
           (tx  (string-trim-right txt char-set:punctuation))
           (txp (string-append tx chr))
           )
      (ly:music-set-property! lst 'text txp)
      )
    music
    )
  )

Regards,
/Karl Hammar


Reply via email to