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 (cdr (assoc 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)
153 (string-append "@ref{" x "}"))
155 (define (human-listify lst)
156 "Produce a textual enumeration from LST, a list of strings"
160 ((null? (cdr lst)) (car lst))
161 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
162 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
164 (define (writing-wip x)
165 (ly:message (_ "Writing ~S...") x))
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
171 (define (property->texi where sym . rest)
172 "Document SYM for WHERE (which can be translation, backend, music),
173 with init values from ALIST (1st optional argument)
175 (let* ((name (symbol->string sym))
176 (alist (if (pair? rest) (car rest) '()))
177 (type?-name (string->symbol
178 (string-append (symbol->string where) "-type?")))
179 (doc-name (string->symbol
180 (string-append (symbol->string where) "-doc")))
181 (type (object-property sym type?-name))
182 (typename (type-name type))
183 (desc (object-property sym doc-name))
184 (handle (assoc sym alist)))
187 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
190 (string-append "@code{" name "} "
195 (scm->texi (cdr handle))