summaryrefslogtreecommitdiff
path: root/scheme/plt/geiser
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-17 04:18:02 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-17 04:18:02 +0200
commit283e6f040449bb4f740991956007332c48308b38 (patch)
treea33bb00a155f11149b361f97aeebe2c0a1cc05ae /scheme/plt/geiser
parent9d64bcb33f7ac1b3a06220842d04ce3c0534948e (diff)
downloadgeiser-chez-283e6f040449bb4f740991956007332c48308b38.tar.gz
geiser-chez-283e6f040449bb4f740991956007332c48308b38.tar.bz2
Simpler, more correct and efficient autodoc implementation.
Not that it was difficult: it's replacing an ugly kludge.
Diffstat (limited to 'scheme/plt/geiser')
-rw-r--r--scheme/plt/geiser/autodoc.ss97
1 files changed, 26 insertions, 71 deletions
diff --git a/scheme/plt/geiser/autodoc.ss b/scheme/plt/geiser/autodoc.ss
index 6607a94..2fe3a83 100644
--- a/scheme/plt/geiser/autodoc.ss
+++ b/scheme/plt/geiser/autodoc.ss
@@ -31,39 +31,32 @@
(eval `(help ,symbol #:from ,mod)))))
(eval `(help ,symbol))))
-(define (autodoc form)
- (cond ((null? form) #f)
- ((symbol? form) (describe-application (list form)))
- ((not (pair? form)) #f)
- ((not (list? form)) (autodoc (pair->list form)))
- ((define-head? form) => autodoc)
- (else (autodoc/list form))))
-
-(define (autodoc/list form)
- (let ((lst (last form)))
- (cond ((and (symbol? lst) (describe-application (list lst))))
- ((and (pair? lst) (not (memq (car lst) '(quote))) (autodoc lst)))
- (else (describe-application form)))))
-
-(define (define-head? form)
- (define defforms '(-define
- define define-values
- define-method define-class define-generic define-struct
- define-syntax define-syntaxes -define-syntax))
- (and (= 2 (length form))
- (memq (car form) defforms)
- (car form)))
-
-(define (describe-application form)
- (let* ((fun (car form))
- (loc (symbol-location* fun))
- (name (car loc))
- (path (cdr loc))
- (sgn (and path (find-signature path name fun))))
- (and sgn
- (list (cons 'signature (format-signature fun sgn))
- (cons 'position (find-position sgn form))
- (cons 'module (module-path-name->name path))))))
+(define (autodoc ids)
+ (if (not (list? ids))
+ '()
+ (map (lambda (id) (or (autodoc* id) (list id))) ids)))
+
+(define (autodoc* id)
+ (and
+ (symbol? id)
+ (let* ((loc (symbol-location* id))
+ (name (car loc))
+ (path (cdr loc))
+ (sgn (and path (find-signature path name id))))
+ (and sgn
+ `(,id
+ (name . ,name)
+ ,@(format-signature sgn)
+ (module . ,(module-path-name->name path)))))))
+
+(define (format-signature sign)
+ (if (signature? sign)
+ `((required ,@(signature-required sign))
+ (optional ,@(signature-optional sign)
+ ,@(let ((rest (signature-rest sign)))
+ (if rest (list "...") '())))
+ (key ,@(signature-keys sign)))
+ '()))
(define signatures (make-hash))
@@ -167,44 +160,6 @@
(opt-no (- max-val min-val)))
(make-signature (args 0 min-val) (args min-val opt-no) '() #f)))))
-(define (format-signature fun sign)
- (cond ((symbol? sign) (cons fun sign))
- ((signature? sign)
- (let ((req (signature-required sign))
- (opt (signature-optional sign))
- (keys (signature-keys sign))
- (rest (signature-rest sign)))
- `(,fun
- ,@req
- ,@(if (null? opt) opt (cons 'geiser-opt_marker opt))
- ,@(if (null? keys) keys (cons 'geiser-key_maker keys))
- ,@(if rest (list 'geiser-rest_marker rest) '()))))
- (else #f)))
-
-(define (find-position sign form)
- (if (signature? sign)
- (let* ((lf (length form))
- (lf-1 (- lf 1)))
- (if (= 1 lf) 0
- (let ((req (length (signature-required sign)))
- (opt (length (signature-optional sign)))
- (keys (map (lambda (k) (symbol->keyword (if (list? k) (car k) k)))
- (signature-keys sign)))
- (rest (signature-rest sign)))
- (cond ((<= lf (+ 1 req)) lf-1)
- ((<= lf (+ 1 req opt)) (if (> opt 0) lf lf-1))
- ((or (memq (last form) keys)
- (memq (car (take-right form 2)) keys)) =>
- (lambda (sl)
- (+ 2 req
- (if (> opt 0) (+ 1 opt) 0)
- (- (length keys) (length sl)))))
- (else (+ 1 req
- (if (> opt 0) (+ 1 opt) 0)
- (if (null? keys) 0 (+ 1 (length keys)))
- (if rest 2 0)))))))
- 0))
-
(define (update-module-cache path . form)
(when (and (string? path)
(or (null? form)