1 ;;;; document-translation.scm -- Functions for engraver documentation
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
8 (define (engraver-makes-grob? name-symbol grav)
9 (memq name-symbol (assoc 'grobs-created (ly:translator-description grav))))
11 (define (engraver-accepts-music-type? name-symbol grav)
12 (memq name-symbol (assoc 'events-accepted (ly:translator-description grav))))
14 (define (engraver-accepts-music-types? types grav)
18 (engraver-accepts-music-type? (car types) grav)
19 (engraver-accepts-music-types? (cdr types) grav))))
21 (define (engraver-doc-string engraver in-which-contexts)
22 (let* ((propsr (cdr (assoc 'properties-read (ly:translator-description engraver))))
23 (propsw (cdr (assoc 'properties-written (ly:translator-description engraver))))
24 (accepted (cdr (assoc 'events-accepted (ly:translator-description engraver))))
25 (name-sym (ly:translator-name engraver))
26 (name-str (symbol->string name-sym))
27 (desc (cdr (assoc 'description (ly:translator-description engraver))))
28 (grobs (engraver-grobs engraver)))
35 "Music types accepted:\n\n"
47 (description-list->texi
48 (map (lambda (x) (property->texi 'translation x '())) propsr)))
55 (description-list->texi
56 (map (lambda (x) (property->texi 'translation x '())) propsw))))
60 "This engraver creates the following layout objects: \n "
61 (human-listify (map ref-ify (uniq-list (sort grobs string<? ))))
67 (let* ((layout-alist (ly:output-description $defaultlayout))
68 (context-description-alist (map cdr layout-alist))
73 (let* ((context (cdr (assoc 'context-name x)))
74 (group (assq-ref x 'group-type))
79 (cdr (assoc 'consists x)))))
80 (if (member name-sym consists)
83 context-description-alist))))
85 "@code{" name-str "} is part of contexts: "
86 (human-listify (map ref-ify
88 (map symbol->string contexts) string<?)))))
91 ;; First level Engraver description
92 (define (engraver-doc grav)
94 #:name (symbol->string (ly:translator-name grav))
95 #:text (engraver-doc-string grav #t)))
97 ;; Second level, part of Context description
98 (define name->engraver-table (make-vector 61 '()))
101 (hash-set! name->engraver-table (ly:translator-name x) x))
102 (ly:get-all-translators))
104 (define (find-engraver-by-name name)
106 (hash-ref name->engraver-table name #f))
108 (define (document-engraver-by-name name)
111 (let* ((eg (find-engraver-by-name name)))
113 (cons (string-append "@code{" (ref-ify (symbol->string name)) "}")
114 (engraver-doc-string eg #f))))
116 (define (document-property-operation op)
118 (context-sym (cadr op))
130 (format "grob-property @code{~a} " (string-join (map symbol->string path) " "))
131 (format " in @ref{~a} to @code{~a}. " context-sym (scm->texi value))
133 ((equal? (object-property context-sym 'is-grob?) #t) "")
134 ((equal? tag 'assign)
135 (format "@item Set translator property @code{~a} to @code{~a}"
137 (scm->texi (car args))))
141 (define (context-doc context-desc)
142 (let* ((name-sym (cdr (assoc 'context-name context-desc)))
143 (name (symbol->string name-sym))
144 (aliases (map symbol->string (cdr (assoc 'aliases context-desc))))
145 (desc-handle (assoc 'description context-desc))
146 (desc (if (and (pair? desc-handle) (string? (cdr desc-handle)))
147 (cdr desc-handle) "(not documented)"))
149 (accepts (cdr (assoc 'accepts context-desc)))
150 (consists (cdr (assoc 'consists context-desc)))
151 (props (cdr (assoc 'property-ops context-desc)))
152 (grobs (context-grobs context-desc))
153 (grob-refs (map (lambda (x) (ref-ify x)) grobs)))
161 (string-append "\n\n This context also accepts commands for the following context(s):\n\n"
162 (human-listify aliases))
164 "\n\nThis context creates the following layout objects: \n\n"
165 (human-listify (uniq-list (sort grob-refs string<? )))
169 "\n\nThis context sets the following properties:\n"
171 (apply string-append (map document-property-operation props))
176 "\n\nThis context is a `bottom' context; it can not contain other contexts."
179 name " can contain \n"
180 (human-listify (map ref-ify (map symbol->string accepts)))))
182 "\n\nThis context is built from the following engravers: "
183 (description-list->texi
184 (map document-engraver-by-name consists))))))
186 (define (engraver-grobs grav)
187 (let* ((eg (if (symbol? grav)
188 (find-engraver-by-name grav)
192 (map symbol->string (cdr (assoc 'grobs-created (ly:translator-description eg)))))))
194 (define (context-grobs context-desc)
195 (let* ((group (assq-ref context-desc 'group-type))
200 (cdr (assoc 'consists context-desc))))
202 (map engraver-grobs consists))))
205 (define (all-contexts-doc)
207 (sort (ly:output-description $defaultlayout)
208 (lambda (x y) (symbol<? (car x) (car y)))))
209 (names (sort (map symbol->string (map car layout-alist)) string<?))
210 (contexts (map cdr layout-alist)))
214 #:desc "Complete descriptions of all contexts"
216 (map context-doc contexts))))
218 (define all-engravers-list (ly:get-all-translators))
219 (set! all-engravers-list
220 (sort all-engravers-list
221 (lambda (a b) (string<? (symbol->string (ly:translator-name a))
222 (symbol->string (ly:translator-name b))))))
224 (define (all-engravers-doc)
227 #:desc "All separate engravers"
228 #:text "See @usermanref{Modifying context plug-ins}."
230 (map engraver-doc all-engravers-list)))
232 (define (translation-properties-doc-string lst)
233 (let* ((ps (sort (map symbol->string lst) string<?))
234 (sortedsyms (map string->symbol ps))
237 (lambda (x) (property->texi 'translation x '()))
239 (texi (description-list->texi propdescs)))
242 (define (translation-doc-node)
245 #:desc "From music to layout"
251 #:name "Tunable context properties"
252 #:desc "All tunable context properties"
253 #:text (translation-properties-doc-string
254 all-user-translation-properties))
257 #:name "Internal context properties"
258 #:desc "All internal context properties"
259 #:text (translation-properties-doc-string
260 all-internal-translation-properties)))))