source: tags/1.3.1/doc/manual/grovel.lisp

Last change on this file was 13858, checked in by rschlatte, 12 years ago

Manual: fix grovel.lisp, add to Makefile (not run by default)

... also create new versions of generated files.

File size: 3.5 KB
Line 
1
2(defun grovel-docstrings-as-tex (&optional (package (find-package :java)))
3  (let ((output-file (format nil "~A.tex" (string-downcase (package-name package)))))
4    (with-open-file (stream output-file :direction :output)
5      (format t "Writing output to ~A.~%" output-file)
6      (loop :for symbol :being :each :external-symbol :of package 
7         :doing (format stream "~&~A~%~%" (symbol-as-tex symbol))))))
8
9(require :asdf)
10
11(asdf:load-system 'swank) ;; XXX Does this load the SWANK-BACKEND package as well
12
13(defun texify-string (string &optional remove)
14  (with-output-to-string (s)
15    (loop for char across string
16         do (if (find char '(#\& #\% #\#))
17                (unless remove
18                  (write-char #\\ s)
19                  (write-char char s))
20                (write-char char s)))))
21
22(defun texify (thing)
23  "Return STRING with LaTeX-sensitive characters escaped.
24Downcase symbol names but leave strings alone."
25  (cond ((listp thing)
26         (format nil "~A" (mapcar #'texify thing)))
27        ((stringp thing) (texify-string thing))
28        ((symbolp thing) (texify-string (string-downcase (symbol-name thing))))))
29
30(defun arglist-as-tex (symbol)
31  (handler-case 
32      (loop :for arg :in (arglist symbol)
33         :collecting (texify arg))
34    (t (e) 
35      (progn (warn "Failed to form arglist for ~A: ~A" symbol e)
36             (list "")))))
37             
38
39(defvar *type-alist* 
40  '((:function 
41     . "Function")
42    (:macro 
43     . "Macro")
44    (:variable 
45     . "Variable")
46    (:class 
47     . "Class")
48    (:special-operator
49     . "Special Operator")
50    (:generic-function 
51     . "Generic Function")))
52
53(defun symbol-as-tex (symbol)
54  "Return the TeX representation of a SYMBOL as Tex."
55  (let (type documentation arglist doc symbol-name package-name)
56    (when (setf doc (swank-backend:describe-symbol-for-emacs symbol))
57        (cond 
58          ((find :function doc)
59           (setf type :function
60                 documentation (second doc)
61                 arglist (format nil "~{~A~^ ~}" (arglist-as-tex symbol))))
62          ((find :variable doc)
63           (setf type :variable 
64                 documentation (second doc)))
65          ((find :macro doc)
66           (setf type :macro
67                 documentation (second doc)))
68          ((find :generic-function doc)
69           (setf type :generic-function
70                 documentation (second doc)))
71          ((find :class doc)
72           (setf type :class
73                 documentation (second doc)))
74          ((find :special-operator doc)
75           (setf type :special-operator
76                 documentation (second doc)))
77          (t 
78           (warn "Unknown type of documentation for symbol ~A: ~A"
79                 symbol doc)))
80        (setf symbol-name (string-downcase 
81                           symbol)
82              package-name (string-downcase 
83                            (package-name (find-package (symbol-package symbol)))))
84        (format nil "~&\\paragraph{}
85\\label{~A:~A}
86\\index{~A}
87--- ~A: \\textbf{~A} [\\textbf{~A}] \\textit{~A}
88
89\\begin{adjustwidth}{5em}{5em}
90~A
91\\end{adjustwidth}"
92                (texify-string (package-name (find-package (symbol-package symbol))) t)
93                (texify-string (symbol-name symbol) t)
94                (texify-string (symbol-name symbol) t)
95                (cdr (assoc type *type-alist*))
96                (texify symbol-name)
97                (texify package-name)
98                (if arglist arglist "")
99                (if documentation (texify documentation) "")))))
100               
101               
102
103
104
105 
106         
107   
108     
Note: See TracBrowser for help on using the repository browser.