-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual.lisp
103 lines (91 loc) · 4.49 KB
/
manual.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;; Copyright (C) 2007-2008 Shawn Betts
;;
;; This file is part of thesiswm.
;;
;; thesiswm is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; thesiswm is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING. If not, see
;; <http://www.gnu.org/licenses/>.
;; Commentary:
;;
;; Generate the texinfo manual from docstrings in the source. Note,
;; this only works in sbcl, clisp and lispworks
;;
;; Code:
(in-package #:thesiswm)
(require :sb-introspect)
;; handy for figuring out which symbol is borking the documentation
(defun dprint (sym)
(declare (ignorable sym))
;;(format t "~&Doing ~a..." sym))
)
(defun generate-function-doc (s line)
(ppcre:register-groups-bind (name) ("^@@@ (.*)" line)
(dprint name)
(let ((fn (if (find #\( name :test 'char=)
;; handle (setf <symbol>) functions
(with-standard-io-syntax
(let ((*package* (find-package :thesiswm)))
(fdefinition (read-from-string name))))
(symbol-function (find-symbol (string-upcase name) :thesiswm))))
(*print-pretty* nil))
(format s "@defun {~a} ~{~a~^ ~}~%~a~&@end defun~%~%"
name
(sb-introspect:function-lambda-list fn)
(documentation fn 'function))
t)))
(defun generate-macro-doc (s line)
(ppcre:register-groups-bind (name) ("^%%% (.*)" line)
(dprint name)
(let* ((symbol (find-symbol (string-upcase name) :thesiswm))
(*print-pretty* nil))
(format s "@defmac {~a} ~{~a~^ ~}~%~a~&@end defmac~%~%"
name
(sb-introspect:function-lambda-list (macro-function symbol))
(documentation symbol 'function))
t)))
(defun generate-variable-doc (s line)
(ppcre:register-groups-bind (name) ("^### (.*)" line)
(dprint name)
(let ((sym (find-symbol (string-upcase name) :thesiswm)))
(format s "@defvar ~a~%~a~&@end defvar~%~%"
name (documentation sym 'variable))
t)))
(defun generate-hook-doc (s line)
(ppcre:register-groups-bind (name) ("^\\$\\$\\$ (.*)" line)
(dprint name)
(let ((sym (find-symbol (string-upcase name) :thesiswm)))
(format s "@defvr {Hook} ~a~%~a~&@end defvr~%~%"
name (documentation sym 'variable))
t)))
(defun generate-command-doc (s line)
(ppcre:register-groups-bind (name) ("^!!! (.*)" line)
(dprint name)
(if-let (symbol (find-symbol (string-upcase name) :thesiswm))
(let ((cmd (symbol-function symbol))
(*print-pretty* nil))
(format s "@deffn {Command} ~a ~{~a~^ ~}~%~a~&@end deffn~%~%"
name
(sb-introspect:function-lambda-list cmd)
(documentation cmd 'function))
t)
(warn "Symbol ~A not found in package STUMPWM" name))))
(defun generate-manual (&key (in #p"thesiswm.texi.in") (out #p"thesiswm.texi"))
(let ((*print-case* :downcase))
(with-open-file (os out :direction :output :if-exists :supersede)
(with-open-file (is in :direction :input)
(loop for line = (read-line is nil is)
until (eq line is) do
(or (generate-function-doc os line)
(generate-macro-doc os line)
(generate-hook-doc os line)
(generate-variable-doc os line)
(generate-command-doc os line)
(write-line line os)))))))