]> git.donarmstrong.com Git - lilypond.git/blob - scm/documentation-lib.scm
texi2html: Use @(sub)section for internalsref (user-friendlier, works with TOC)
[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 . "@chapter")
63                       (2 . "@section")
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 .
77 string-to-use).  If QUOTE? is #t, embed table in a @quotation environment."
78   (string-append
79    "\n"
80    (if quote? "@quotation\n" "")
81    "@table @asis\n"
82    (apply string-append (map one-item->texi items-alist))
83    "\n"
84    "@end table\n"
85    (if quote? "@end quotation\n" "")))
86
87 (define (texi-menu items-alist)
88   "Generate what is between @menu and @end menu."
89   (let ((maxwid
90          (apply max (map (lambda (x) (string-length (car x))) items-alist))))
91     
92     (string-append
93      "\n@menu"
94      (apply string-append
95             (map (lambda (x)
96                    (string-append
97                     (string-pad-right 
98                      (string-append "\n* " (car x) ":: ")
99                      (+ maxwid 8))
100                     (cdr x)))
101                  items-alist))
102      "\n@end menu\n"
103      ;; Menus don't appear in html, so we make a list ourselves
104      "\n@ignore\n"
105      "\n@ifhtml\n"
106      (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
107                                   items-alist)
108                              #t)
109      "\n@end ifhtml\n"
110      "\n@end ignore\n")))
111
112 (define (texi-file-head name file-name top)
113   (string-append
114    "\\input texinfo @c -*-texinfo-*-"
115    "\n@setfilename " file-name ".info"
116    "\n@settitle " name
117    "\n@dircategory LilyPond"
118    "\n@direntry"
119    ;; prepend GNU for dir, must be unique
120    "\n* GNU " name ": (" file-name ").          " name "."
121    "\n@end direntry\n"
122    "@documentlanguage en\n"
123    "@documentencoding utf-8\n"))
124
125 (define (context-name name)
126   name)
127
128 (define (engraver-name name)
129   name)
130
131 (define (grob-name name)
132   (if (symbol? name)
133       (symbol->string name)
134       name))
135
136 (define (interface-name name)
137   name)
138
139 (define (ref-ify x)
140   "Add ref to X"
141   (string-append "@ref{" x "}"))
142
143 (define (human-listify lst)
144   "Produce a textual enumeration from LST, a list of strings"
145   
146   (cond
147    ((null? lst) "none")
148    ((null? (cdr lst)) (car lst))
149    ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
150    (else (string-append (car lst) ", " (human-listify (cdr lst))))))
151
152 (define (writing-wip x)
153   (ly:message (_ "Writing ~S...") x))
154
155
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;; property  stuff.
158
159 (define (property->texi where sym . rest)
160   "Document SYM for WHERE (which can be translation, backend, music),
161 with init values from ALIST (1st optional argument)
162 "
163   (let* ((name (symbol->string sym))
164          (alist (if (pair? rest) (car rest) '()))
165          (type?-name (string->symbol
166                       (string-append (symbol->string where) "-type?")))
167          (doc-name (string->symbol                  
168                     (string-append (symbol->string where) "-doc")))
169          (type (object-property sym type?-name))
170          (typename (type-name type))
171          (desc (object-property sym doc-name))
172          (handle (assoc sym alist)))
173
174     (if (eq? desc #f)
175         (ly:error (_ "cannot find description for property ~S (~S)") sym where))
176     
177     (cons
178      (string-append "@code{" name "} "
179                     "(" typename ")"
180                     (if handle
181                         (string-append
182                          ":\n\n"
183                          (scm->texi (cdr handle))
184                          "\n\n")
185                         ""))
186      desc)))
187