From a368a3c589fa4de0afb94ff76f990822d2fbb55f Mon Sep 17 00:00:00 2001 From: tux Date: Thu, 23 Jan 2025 23:08:15 +0100 Subject: [PATCH] Refactor author-format function --- footer_with_songinfo.ly | 16 +++++++++------- toc_include.ly | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/footer_with_songinfo.ly b/footer_with_songinfo.ly index 3c8d056..cfef644 100644 --- a/footer_with_songinfo.ly +++ b/footer_with_songinfo.ly @@ -1,8 +1,8 @@ #(use-modules (ice-9 receive)) -#(define (format-author layout authorId noDetails) +#(define (format-author author-format-function authorId noDetails) (let ((author (if (defined? 'AUTHOR_DATA) (assoc-ref AUTHOR_DATA authorId) #f))) (if author - ((ly:output-def-lookup layout 'authorFormat) + (author-format-function noDetails (assoc-ref author "name") (assoc-ref author "trail_name") @@ -29,14 +29,17 @@ (assoc-ref song key) (ly:warning (ly:format "song with id ~a not found" songId))))) + (define* (default-author-format authorId #:optional (noDetails #f)) + (format-author (ly:output-def-lookup layout 'authorFormat) authorId noDetails)) + (define (format-poet poetId) - (string-append (ly:output-def-lookup layout 'poetPrefix) " " (format-author layout poetId #f))) + (string-append (ly:output-def-lookup layout 'poetPrefix) " " (default-author-format poetId))) (define (format-composer composerId) - (string-append (ly:output-def-lookup layout 'composerPrefix) " " (format-author layout composerId #f))) + (string-append (ly:output-def-lookup layout 'composerPrefix) " " (default-author-format composerId))) (define (format-poet-and-composer authorId) - (string-append (ly:output-def-lookup layout 'poetAndComposerEqualPrefix) " " (format-author layout authorId #f))) + (string-append (ly:output-def-lookup layout 'poetAndComposerEqualPrefix) " " (default-author-format authorId))) (define (numbered-contribution-prefix contributionNumbers prefixLookup) (string-append @@ -50,8 +53,7 @@ (define (format-authors authorIds) (map (lambda (authorId) - (format-author - layout + (default-author-format authorId (if (member authorId referencedAuthors) #t diff --git a/toc_include.ly b/toc_include.ly index cb78c7b..67444b0 100644 --- a/toc_include.ly +++ b/toc_include.ly @@ -209,7 +209,7 @@ #(make-on-the-fly-markup (lambda (layout props m) (interpret-markup layout props - (make-justify-string-markup (format-author layout (chain-assoc-get 'index:text props #f) #f)))) + (make-justify-string-markup (format-author (ly:output-def-lookup layout 'authorFormat) (chain-assoc-get 'index:text props #f) #f)))) (make-null-markup)) \vspace #.4 } @@ -317,7 +317,7 @@ headerToTOC = #(define-music-function (parser location header label) (ly:book? s (ly:string-substitute "\"" "\\\"" field)) "\""))) (define (format-authors authorIds) - (string-join (map (lambda (authorId) (format-author layout authorId #f)) authorIds) ", ")) + (string-join (map (lambda (authorId) (format-author (ly:output-def-lookup layout 'authorFormat) authorId #f)) authorIds) ", ")) (define cr-regex (ly:make-regex "\r")) (define crlf-regex (ly:make-regex "\r\n")) (define para-sep-regex (ly:make-regex "\n[ \t\n]*\n[ \t\n]*"))