]> git.donarmstrong.com Git - lilypond.git/blob - scm/documentation-lib.scm
Improve formatting of internal documentation.
[lilypond.git] / scm / documentation-lib.scm
1 ;;;;
2 ;;;; documentation-lib.scm -- Assorted Functions for generated documentation
3 ;;;;
4 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; 
6 ;;;; (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 ;;;;                 Jan Nieuwenhuizen <janneke@gnu.org>
8
9 (use-modules (oop goops)
10              (srfi srfi-13)
11              (srfi srfi-1))
12
13 (define-class <texi-node> ()
14   (children #:init-value '() #:accessor node-children #:init-keyword #:children)
15   (text #:init-value "" #:accessor node-text #:init-keyword #:text)
16   (name #:init-value "" #:accessor node-name #:init-keyword #:name)
17   (description #:init-value "" #:accessor node-desc #:init-keyword #:desc))
18
19 (define (menu-entry x)
20   (cons
21    (node-name x)
22    (node-desc x)))
23
24 (define (dump-node node port level)
25   (display
26    (string-append
27     "\n@node "
28     (node-name node)
29     "\n\n"
30     (texi-section-command level) " "
31     (node-name node)
32     "\n\n"
33     (node-text node)
34     "\n\n"
35     (if (pair? (node-children node))
36         (texi-menu
37          (map (lambda (x) (menu-entry x))
38               (node-children node)))
39         ""))
40    port)
41   (map (lambda (x) (dump-node x port (+ 1 level)))
42        (node-children node)))
43
44 (define (processing name)
45   (ly:message (_ "Processing ~S...") name))
46
47 (define (self-evaluating? x)
48   (or (number? x) (string? x) (procedure? x) (boolean? x)))
49
50 (define (texify x)
51   x)
52
53 (define (scm->texi x)
54   (string-append "@code{" (texify (scm->string x)) "}"))
55
56
57
58 (define (texi-section-command level)
59   (cdr (assoc level '(
60                       ;; Hmm, texinfo doesn't have ``part''
61                       (0 . "@top")
62                       (1 . "@unnumbered")
63                       (2 . "@unnumberedsec")
64                       (3 . "@unnumberedsubsec")
65                       (4 . "@unnumberedsubsubsec")
66                       (5 . "@unnumberedsubsubsec")))))
67
68 (define (one-item->texi label-desc-pair)
69   "Document one (LABEL . DESC); return empty string if LABEL is empty string."
70   (if (eq? (car label-desc-pair) "")
71       ""
72       (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
73
74
75 (define (description-list->texi items-alist quote?)
76   "Document ITEMS-ALIST in a table; entries contain (item-label . string-to-use)."
77   (string-append
78    "\n"
79    (if quote? "@quotation\n" "")
80    "@table @asis\n"
81    (apply string-append (map one-item->texi items-alist))
82    "\n"
83    "@end table\n"
84    (if quote? "@end quotation\n" "")))
85
86 (define (texi-menu items-alist)
87   "Generate what is between @menu and @end menu."
88   (let ((maxwid
89          (apply max (map (lambda (x) (string-length (car x))) items-alist))))
90     
91     (string-append
92      "\n@menu"
93      (apply string-append
94             (map (lambda (x)
95                    (string-append
96                     (string-pad-right 
97                      (string-append "\n* " (car x) ":: ")
98                      (+ maxwid 8))
99                     (cdr x)))
100                  items-alist))
101      "\n@end menu\n"
102      ;; Menus don't appear in html, so we make a list ourselves
103      "\n@ignore\n"
104      "\n@ifhtml\n"
105      (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
106                                   items-alist)
107                              #t)
108      "\n@end ifhtml\n"
109      "\n@end ignore\n")))
110
111 (define (texi-file-head name file-name top)
112   (string-append
113    "\\input texinfo @c -*-texinfo-*-"
114    "\n@setfilename " file-name ".info"
115    "\n@settitle " name
116    "\n@dircategory LilyPond"
117    "\n@direntry"
118    ;; prepend GNU for dir, must be unique
119    "\n* GNU " name ": (" file-name ").          " name "."
120    "\n@end direntry\n"
121    "@documentlanguage en\n"
122    "@documentencoding utf-8\n"))
123
124 (define (context-name name)
125   name)
126
127 (define (engraver-name name)
128   name)
129
130 (define (grob-name name)
131   (if (symbol? name)
132       (symbol->string name)
133       name))
134
135 (define (interface-name name)
136   name)
137
138 (define (ref-ify x)
139   "Add ref to X"
140   (string-append "@ref{" x "}"))
141
142 (define (human-listify lst)
143   "Produce a textual enumeration from LST, a list of strings"
144   
145   (cond
146    ((null? lst) "none")
147    ((null? (cdr lst)) (car lst))
148    ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
149    (else (string-append (car lst) ", " (human-listify (cdr lst))))))
150
151 (define (writing-wip x)
152   (ly:message (_ "Writing ~S...") x))
153
154
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;; property  stuff.
157
158 (define (property->texi where sym . rest)
159   "Document SYM for WHERE (which can be translation, backend, music),
160 with init values from ALIST (1st optional argument)
161 "
162   (let* ((name (symbol->string sym))
163          (alist (if (pair? rest) (car rest) '()))
164          (type?-name (string->symbol
165                       (string-append (symbol->string where) "-type?")))
166          (doc-name (string->symbol                  
167                     (string-append (symbol->string where) "-doc")))
168          (type (object-property sym type?-name))
169          (typename (type-name type))
170          (desc (object-property sym doc-name))
171          (handle (assoc sym alist)))
172
173     (if (eq? desc #f)
174         (ly:error (_ "cannot find description for property ~S (~S)") sym where))
175     
176     (cons
177      (string-append "@code{" name "} "
178                     "(" typename ")"
179                     (if handle
180                         (string-append
181                          ":\n\n"
182                          (scm->texi (cdr handle))
183                          "\n\n")
184                         ""))
185      desc)))
186