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 (assoc-get 'properties-read (ly:translator-description engraver)))
23 (propsw (assoc-get 'properties-written (ly:translator-description engraver)))
24 (accepted (assoc-get 'events-accepted (ly:translator-description engraver)))
25 (name-sym (ly:translator-name engraver))
26 (name-str (symbol->string name-sym))
27 (desc (assoc-get 'description (ly:translator-description engraver)))
28 (grobs (engraver-grobs engraver)))
35 "Music types accepted:\n\n"
37 (map ref-ify (sort (map symbol->string accepted) ly:string-ci<?))))
43 (description-list->texi
44 (map (lambda (x) (property->texi 'translation x '()))
45 (sort propsr ly:symbol-ci<?))
53 (description-list->texi
54 (map (lambda (x) (property->texi 'translation x '()))
55 (sort propsw ly:symbol-ci<?))
60 "\n\nThis engraver creates the following layout object(s):\n\n"
61 (human-listify (map ref-ify (uniq-list (sort grobs ly:string-ci<?))))
67 (let* ((layout-alist (ly:output-description $defaultlayout))
68 (context-description-alist (map cdr layout-alist))
73 (let* ((context (assoc-get 'context-name x))
74 (group (assq-ref x 'group-type))
79 (assoc-get 'consists x))))
80 (if (member name-sym consists)
83 context-description-alist)))
84 (context-list (human-listify (map ref-ify
86 (map symbol->string contexts)
89 "@code{" name-str "} "
90 (if (equal? context-list "none")
91 "is not part of any context"
93 "is part of the following context(s): "
98 ;; First level Engraver description
99 (define (engraver-doc grav)
101 #:name (symbol->string (ly:translator-name grav))
102 #:text (engraver-doc-string grav #t)))
104 ;; Second level, part of Context description
105 (define name->engraver-table (make-vector 61 '()))
108 (hash-set! name->engraver-table (ly:translator-name x) x))
109 (ly:get-all-translators))
111 (define (find-engraver-by-name name)
113 (hash-ref name->engraver-table name #f))
115 (define (document-engraver-by-name name)
118 (let* ((eg (find-engraver-by-name name)))
120 (cons (string-append "@code{" (ref-ify (symbol->string name)) "}")
121 (engraver-doc-string eg #f))))
123 (define (document-property-operation op)
125 (context-sym (cadr op))
137 (format "grob-property @code{~a} "
138 (string-join (map symbol->string path) " "))
139 (format "in @ref{~a} to ~a."
140 context-sym (scm->texi value))
142 ((equal? (object-property context-sym 'is-grob?) #t) "")
143 ((equal? tag 'assign)
144 (format "@item Set translator property @code{~a} to ~a.\n"
146 (scm->texi (car args))))
150 (define (context-doc context-desc)
151 (let* ((name-sym (assoc-get 'context-name context-desc))
152 (name (symbol->string name-sym))
153 (aliases (map symbol->string (assoc-get 'aliases context-desc)))
154 (desc (assoc-get 'description context-desc "(not documented"))
155 (accepts (assoc-get 'accepts context-desc))
156 (consists (assoc-get 'consists context-desc))
157 (props (assoc-get 'property-ops context-desc))
158 (grobs (context-grobs context-desc))
159 (grob-refs (map ref-ify (sort grobs ly:string-ci<?))))
168 "\n\nThis context also accepts commands for the following context(s):\n\n"
169 (human-listify (sort aliases ly:string-ci<?))
173 "\n\nThis context creates the following layout object(s):\n\n"
174 (human-listify (uniq-list grob-refs))
177 (if (and (pair? props) (not (null? props)))
178 (let ((str (apply string-append
179 (sort (map document-property-operation props)
181 (if (string-null? str)
184 "\n\nThis context sets the following properties:\n\n"
191 "\n\nThis context is a `bottom' context; it cannot contain other contexts."
196 (human-listify (map ref-ify (sort (map symbol->string accepts)
203 "\n\nThis context is built from the following engraver(s):"
204 (description-list->texi
205 (map document-engraver-by-name (sort consists ly:symbol-ci<?))
208 (define (engraver-grobs grav)
209 (let* ((eg (if (symbol? grav)
210 (find-engraver-by-name grav)
214 (map symbol->string (assoc-get 'grobs-created (ly:translator-description eg))))))
216 (define (context-grobs context-desc)
217 (let* ((group (assq-ref context-desc 'group-type))
222 (assoc-get 'consists context-desc)))
224 (map engraver-grobs consists))))
227 (define (all-contexts-doc)
229 (sort (ly:output-description $defaultlayout)
230 (lambda (x y) (ly:symbol-ci<? (car x) (car y)))))
231 (names (sort (map symbol->string (map car layout-alist)) ly:string-ci<?))
232 (contexts (map cdr layout-alist)))
236 #:desc "Complete descriptions of all contexts."
238 (map context-doc contexts))))
240 (define all-engravers-list (ly:get-all-translators))
241 (set! all-engravers-list
242 (sort all-engravers-list
243 (lambda (a b) (ly:string-ci<? (symbol->string (ly:translator-name a))
244 (symbol->string (ly:translator-name b))))))
246 (define (all-engravers-doc)
248 #:name "Engravers and Performers"
249 #:desc "All separate engravers and performers."
250 #:text "See @ruser{Modifying context plug-ins}."
252 (map engraver-doc all-engravers-list)))
254 (define (translation-properties-doc-string lst)
255 (let* ((ps (sort (map symbol->string lst) ly:string-ci<?))
256 (sortedsyms (map string->symbol ps))
259 (lambda (x) (property->texi 'translation x '()))
261 (texi (description-list->texi propdescs #f)))
264 (define (translation-doc-node)
267 #:desc "From music to layout."
273 #:name "Tunable context properties"
274 #:desc "All tunable context properties."
275 #:text (translation-properties-doc-string
276 all-user-translation-properties))
279 #:name "Internal context properties"
280 #:desc "All internal context properties."
281 #:text (translation-properties-doc-string
282 all-internal-translation-properties)))))