2 ;;;; documentation-lib.scm -- Assorted Functions for generated documentation
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 (use-modules (oop goops)
13 (define-class <texi-node> ()
14 (appendix #:init-value #f #:accessor appendix? #:init-keyword #:appendix)
15 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
16 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
17 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
18 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc))
20 (define (menu-entry x)
25 (define* (dump-node node port level)
29 (if (= level 0) "Top" (node-name node))
32 (texi-appendix-section-command level)
33 (texi-section-command level))
39 (if (pair? (node-children node))
41 (map (lambda (x) (menu-entry x))
42 (node-children node)))
45 (map (lambda (x) (dump-node x port (+ 1 level)))
46 (node-children node)))
48 (define (processing name)
49 (ly:message (_ "Processing ~S...") name))
51 (define (self-evaluating? x)
52 (or (number? x) (string? x) (procedure? x) (boolean? x)))
58 (string-append "@code{" (texify (scm->string x)) "}"))
62 (define (texi-section-command level)
64 ;; Hmm, texinfo doesn't have ``part''
69 (4 . "@unnumberedsubsubsec")
70 (5 . "@unnumberedsubsubsec"))))
72 (define (texi-appendix-section-command level)
73 (assoc-get level '((0 . "@top")
76 (3 . "@appendixsubsec")
77 (4 . "@appendixsubsubsec")
78 (5 . "@appendixsubsubsec"))))
80 (define (one-item->texi label-desc-pair)
81 "Document one (LABEL . DESC); return empty string if LABEL is empty string."
82 (if (eq? (car label-desc-pair) "")
84 (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
87 (define (description-list->texi items-alist quote?)
88 "Document ITEMS-ALIST in a table; entries contain (item-label .
89 string-to-use). If QUOTE? is #t, embed table in a @quotation environment."
92 (if quote? "@quotation\n" "")
94 (apply string-append (map one-item->texi items-alist))
97 (if quote? "@end quotation\n" "")))
99 (define (texi-menu items-alist)
100 "Generate what is between @menu and @end menu."
102 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
110 (string-append "\n* " (car x) ":: ")
115 ;; Menus don't appear in html, so we make a list ourselves
118 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
124 (define (texi-file-head name file-name top)
126 "\\input texinfo @c -*-texinfo-*-"
127 "\n@setfilename " file-name ".info"
129 "\n@dircategory LilyPond"
131 ;; prepend GNU for dir, must be unique
132 "\n* GNU " name ": (" file-name "). " name "."
134 "@documentlanguage en\n"
135 "@documentencoding utf-8\n"))
137 (define (context-name name)
140 (define (engraver-name name)
143 (define (grob-name name)
145 (symbol->string name)
148 (define (interface-name name)
152 "Return @ref{X}. If mapping ref-ify to a list that needs to be sorted,
153 sort the list first."
154 (string-append "@ref{" x "}"))
156 (define (human-listify lst)
157 "Produce a textual enumeration from LST, a list of strings"
161 ((null? (cdr lst)) (car lst))
162 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
163 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
165 (define (writing-wip x)
166 (ly:message (_ "Writing ~S...") x))
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 (define (property->texi where sym . rest)
173 "Document SYM for WHERE (which can be translation, backend, music),
174 with init values from ALIST (1st optional argument)
176 (let* ((name (symbol->string sym))
177 (alist (if (pair? rest) (car rest) '()))
178 (type?-name (string->symbol
179 (string-append (symbol->string where) "-type?")))
180 (doc-name (string->symbol
181 (string-append (symbol->string where) "-doc")))
182 (type (object-property sym type?-name))
183 (typename (type-name type))
184 (desc (object-property sym doc-name))
185 (init-value (assoc-get sym alist)))
188 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
191 (string-append "@code{" name "} "
196 (scm->texi init-value)