summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter <craven@gmx.net>2016-05-01 10:44:06 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2016-05-02 21:15:49 +0200
commitddf6ce8db51ab270faee5edb723f91c827e62a57 (patch)
treed51ee988eec21f806c6912f4a02f81c8af1160ae
parent366f6ecbd3dd9237ded638d7c6ad04dfec90f19d (diff)
downloadgeiser-guile-ddf6ce8db51ab270faee5edb723f91c827e62a57.tar.gz
geiser-guile-ddf6ce8db51ab270faee5edb723f91c827e62a57.tar.bz2
geiser-chibi: Implement autodoc for procedures in known modules
-rw-r--r--scheme/chibi/geiser/geiser.scm45
-rw-r--r--scheme/chibi/geiser/geiser.sld2
2 files changed, 45 insertions, 2 deletions
diff --git a/scheme/chibi/geiser/geiser.scm b/scheme/chibi/geiser/geiser.scm
index fe0569e..79a1b4e 100644
--- a/scheme/chibi/geiser/geiser.scm
+++ b/scheme/chibi/geiser/geiser.scm
@@ -40,8 +40,51 @@
(string-contains prefix (write-to-string module))))
modules)))))
+(define (procedure-arglist id fun)
+ (let ((arglist (lambda-params (procedure-analysis fun))))
+ (if (pair? arglist)
+ (let loop ((arglist arglist)
+ (optionals? #f)
+ (required '())
+ (optional '()))
+ (cond ((null? arglist)
+ `(,id ("args" (("required" ,@(reverse required))
+ ("optional" ,@(reverse optional))
+ ("key")
+ ("module" ,(let ((mod (containing-module fun))) (if mod (car mod) #f)))))))
+ ((symbol? arglist)
+ (loop '()
+ #t
+ required
+ (cons "..." (cons arglist optional))))
+ (else
+ (loop
+ (cdr arglist)
+ optionals?
+ (if optionals? required (cons (car arglist) required))
+ (if optionals? (cons (car arglist) optional) optional)))))
+ '())))
+
+(define (geiser:operator-arglist id)
+ (let ((binding (eval id)))
+ (cond ((procedure? binding)
+ (if (opcode? binding)
+ '()
+ (procedure-arglist id binding)))
+ (else
+ '()))))
+
(define (geiser:autodoc ids . rest)
- '())
+ rest
+ (cond ((null? ids) '())
+ ((not (list? ids))
+ (geiser:autodoc (list ids)))
+ ((not (symbol? (car ids)))
+ (geiser:autodoc (cdr ids)))
+ (else
+ (map (lambda (id)
+ (geiser:operator-arglist id))
+ ids))))
(define (geiser:no-values)
#f)
diff --git a/scheme/chibi/geiser/geiser.sld b/scheme/chibi/geiser/geiser.sld
index a6e2704..56abab3 100644
--- a/scheme/chibi/geiser/geiser.sld
+++ b/scheme/chibi/geiser/geiser.sld
@@ -5,5 +5,5 @@
geiser:module-completions
geiser:no-values
geiser:newline)
- (import (scheme small) (chibi modules) (chibi) (meta) (chibi string) (srfi 1) (srfi 95))
+ (import (scheme small) (chibi modules) (chibi) (meta) (chibi ast) (chibi string) (srfi 1) (srfi 95))
(include "geiser.scm"))