1 ;;;; document-translation.scm -- Functions for engraver documentation
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2009 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)
56 (description-list->texi
57 (map (lambda (x) (property->texi 'translation x '())) propsw)
62 "\n\nThis engraver creates the following layout object(s):\n\n"
63 (human-listify (map ref-ify (uniq-list (sort grobs string<?))))
69 (let* ((layout-alist (ly:output-description $defaultlayout))
70 (context-description-alist (map cdr layout-alist))
75 (let* ((context (cdr (assoc 'context-name x)))
76 (group (assq-ref x 'group-type))
81 (cdr (assoc 'consists x)))))
82 (if (member name-sym consists)
85 context-description-alist)))
86 (context-list (human-listify (map ref-ify
88 (map symbol->string contexts)
91 "@code{" name-str "} "
92 (if (equal? context-list "none")
93 "is not part of any context"
95 "is part of the following context(s): "
100 ;; First level Engraver description
101 (define (engraver-doc grav)
103 #:name (symbol->string (ly:translator-name grav))
104 #:text (engraver-doc-string grav #t)))
106 ;; Second level, part of Context description
107 (define name->engraver-table (make-vector 61 '()))
110 (hash-set! name->engraver-table (ly:translator-name x) x))
111 (ly:get-all-translators))
113 (define (find-engraver-by-name name)
115 (hash-ref name->engraver-table name #f))
117 (define (document-engraver-by-name name)
120 (let* ((eg (find-engraver-by-name name)))
122 (cons (string-append "@code{" (ref-ify (symbol->string name)) "}")
123 (engraver-doc-string eg #f))))
125 (define (document-property-operation op)
127 (context-sym (cadr op))
139 (format "grob-property @code{~a} "
140 (string-join (map symbol->string path) " "))
141 (format "in @ref{~a} to ~a."
142 context-sym (scm->texi value))
144 ((equal? (object-property context-sym 'is-grob?) #t) "")
145 ((equal? tag 'assign)
146 (format "@item Set translator property @code{~a} to ~a.\n"
148 (scm->texi (car args))))
152 (define (context-doc context-desc)
153 (let* ((name-sym (cdr (assoc 'context-name context-desc)))
154 (name (symbol->string name-sym))
155 (aliases (map symbol->string (cdr (assoc 'aliases context-desc))))
156 (desc-handle (assoc 'description context-desc))
157 (desc (if (and (pair? desc-handle) (string? (cdr desc-handle)))
158 (cdr desc-handle) "(not documented)"))
160 (accepts (cdr (assoc 'accepts context-desc)))
161 (consists (cdr (assoc 'consists context-desc)))
162 (props (cdr (assoc 'property-ops context-desc)))
163 (grobs (context-grobs context-desc))
164 (grob-refs (map (lambda (x) (ref-ify x)) grobs)))
173 "\n\nThis context also accepts commands for the following context(s):\n\n"
174 (human-listify aliases)
178 "\n\nThis context creates the following layout object(s):\n\n"
179 (human-listify (uniq-list (sort grob-refs string<?)))
182 (if (and (pair? props) (not (null? props)))
183 (let ((str (apply string-append (map document-property-operation
185 (if (string-null? str)
188 "\n\nThis context sets the following properties:\n\n"
195 "\n\nThis context is a `bottom' context; it cannot contain other contexts."
200 (human-listify (map ref-ify (map symbol->string accepts)))
206 "\n\nThis context is built from the following engraver(s):"
207 (description-list->texi
208 (map document-engraver-by-name consists)
211 (define (engraver-grobs grav)
212 (let* ((eg (if (symbol? grav)
213 (find-engraver-by-name grav)
217 (map symbol->string (cdr (assoc 'grobs-created (ly:translator-description eg)))))))
219 (define (context-grobs context-desc)
220 (let* ((group (assq-ref context-desc 'group-type))
225 (cdr (assoc 'consists context-desc))))
227 (map engraver-grobs consists))))
230 (define (all-contexts-doc)
232 (sort (ly:output-description $defaultlayout)
233 (lambda (x y) (symbol<? (car x) (car y)))))
234 (names (sort (map symbol->string (map car layout-alist)) string<?))
235 (contexts (map cdr layout-alist)))
239 #:desc "Complete descriptions of all contexts."
241 (map context-doc contexts))))
243 (define all-engravers-list (ly:get-all-translators))
244 (set! all-engravers-list
245 (sort all-engravers-list
246 (lambda (a b) (string<? (symbol->string (ly:translator-name a))
247 (symbol->string (ly:translator-name b))))))
249 (define (all-engravers-doc)
251 #:name "Engravers and Performers"
252 #:desc "All separate engravers and performers."
253 #:text "See @ruser{Modifying context plug-ins}."
255 (map engraver-doc all-engravers-list)))
257 (define (translation-properties-doc-string lst)
258 (let* ((ps (sort (map symbol->string lst) string<?))
259 (sortedsyms (map string->symbol ps))
262 (lambda (x) (property->texi 'translation x '()))
264 (texi (description-list->texi propdescs #f)))
267 (define (translation-doc-node)
270 #:desc "From music to layout."
276 #:name "Tunable context properties"
277 #:desc "All tunable context properties."
278 #:text (translation-properties-doc-string
279 all-user-translation-properties))
282 #:name "Internal context properties"
283 #:desc "All internal context properties."
284 #:text (translation-properties-doc-string
285 all-internal-translation-properties)))))