1 | #-abcl We're only grovelling ABCL docstrings here. |
---|
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 | (asdf:load-system 'swank) ;; XXX Does this load the SWANK-BACKEND package as well |
---|
10 | |
---|
11 | (defun arglist-as-tex (symbol) |
---|
12 | (handler-case |
---|
13 | (loop :for arg :in (arglist symbol) |
---|
14 | :collecting |
---|
15 | (format nil |
---|
16 | ;;; XXX should really check the entire input for TeX escapes |
---|
17 | (if (and (symbolp arg) |
---|
18 | (or (string= (subseq (symbol-name arg) 0 1) #\&) |
---|
19 | (string= (subseq (symbol-name arg) 0 1) #\%))) |
---|
20 | "\\~A" |
---|
21 | "~A") |
---|
22 | (if (symbolp arg) |
---|
23 | (string-downcase (symbol-name arg)) |
---|
24 | (format nil "~(~A~)" arg)))) |
---|
25 | (t (e) |
---|
26 | (progn (warn "Failed to form arglist for ~A: ~A" symbol e) |
---|
27 | (list ""))))) |
---|
28 | |
---|
29 | |
---|
30 | (defvar *type-alist* |
---|
31 | '((:function |
---|
32 | . "Function") |
---|
33 | (:macro |
---|
34 | . "Macro") |
---|
35 | (:variable |
---|
36 | . "Variable") |
---|
37 | (:class |
---|
38 | . "Class") |
---|
39 | (:special-operator |
---|
40 | . "Special Operator") |
---|
41 | (:generic-function |
---|
42 | . "Generic Function"))) |
---|
43 | |
---|
44 | (defun symbol-as-tex (symbol) |
---|
45 | "Return the TeX representation of a SYMBOL as Tex." |
---|
46 | (let (type documentation arglist doc symbol-name package-name) |
---|
47 | (when (setf doc (swank-backend:describe-symbol-for-emacs symbol)) |
---|
48 | (cond |
---|
49 | ((find :function doc) |
---|
50 | (setf type :function |
---|
51 | documentation (second doc) |
---|
52 | arglist (format nil "~{~A~^ ~}" (arglist-as-tex symbol)))) |
---|
53 | ((find :variable doc) |
---|
54 | (setf type :variable |
---|
55 | documentation (second doc))) |
---|
56 | ((find :macro doc) |
---|
57 | (setf type :macro |
---|
58 | documentation (second doc))) |
---|
59 | ((find :generic-function doc) |
---|
60 | (setf type :generic-function |
---|
61 | documentation (second doc))) |
---|
62 | ((find :class doc) |
---|
63 | (setf type :class |
---|
64 | documentation (second doc))) |
---|
65 | ((find :special-operator doc) |
---|
66 | (setf type :special-operator |
---|
67 | documentation (second doc))) |
---|
68 | (t |
---|
69 | (warn "Unknown type of documentation for symbol ~A: ~A" |
---|
70 | symbol doc))) |
---|
71 | (setf symbol-name (string-downcase |
---|
72 | symbol) |
---|
73 | package-name (string-downcase |
---|
74 | (package-name (find-package (symbol-package symbol))))) |
---|
75 | (format nil "~&\\paragraph{}~&\\label{~A:~A}~&\\index{~A}~&--- ~A: \\textbf{~A} [\\textbf{~A}] \\textit{~A}~%~%\\begin{adjustwidth}{5em}{5em}~&~A~&\\end{adjustwidth}" |
---|
76 | (package-name (find-package (symbol-package symbol))) |
---|
77 | (symbol-name symbol) |
---|
78 | (symbol-name symbol) |
---|
79 | (cdr (assoc type *type-alist*)) |
---|
80 | symbol-name |
---|
81 | package-name |
---|
82 | (if arglist arglist "") |
---|
83 | (if documentation documentation ""))))) |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|