4 geiser:module-completions
10 (define string-prefix?
12 (let ([n (string-length x)])
13 (and (fx<= n (string-length y))
16 (and (char=? (string-ref x i) (string-ref y i))
17 (prefix? (fx+ i 1)))))))))
19 (define (geiser:completions prefix . rest)
23 (string-prefix? prefix el))
24 (map write-to-string (environment-symbols (interaction-environment))))))
26 (define (write-to-string x)
27 (with-output-to-string
31 (define (geiser:eval module form . rest)
33 (let* ((body (lambda ()
35 (eval form (environment module))
37 (gen-result (lambda (result-mid is-error?)
43 (with-output-to-string
45 (display-condition result-mid)))))))
46 `((result ,(with-output-to-string
48 (pretty-print result-mid))))
52 (with-exception-handler
54 (k (gen-result e #t)))
62 (k (gen-result (cons x y) #f)))))))))))
66 (define (geiser:module-completions prefix . rest)
67 (define (substring? s1 s2)
68 (let ([n1 (string-length s1)] [n2 (string-length s2)])
70 (let loop1 ([i1 0] [j i2])
74 (if (char=? (string-ref s1 i1) (string-ref s2 j))
75 (loop1 (fx+ i1 1) (fx+ j 1))
76 (loop2 (fx+ i2 1)))))))))
78 (substring? prefix el))
79 (map write-to-string (library-list))))
81 (define (procedure-parameter-list p)
82 ;; same as (inspect object), then hitting c
83 (let ((s (((inspect/object p) 'code) 'source)))
85 (let ((form (s 'value)))
88 (eq? (car form) 'lambda))
93 (define (operator-arglist operator)
94 (let ((binding (eval operator)))
96 (let ((arglist (procedure-parameter-list binding)))
97 (let loop ((arglist arglist)
101 (cond ((null? arglist)
102 `(,operator ("args" (("required" ,@(reverse required))
103 ("optional" ,@(reverse optional))
105 ;; ("module" ,module)
111 (cons "..." (cons arglist optional))))
116 (if optionals? required (cons (car arglist) required))
117 (if optionals? (cons (car arglist) optional) optional))))))
120 (define (geiser:autodoc ids . rest)
121 (cond ((null? ids) '())
123 (geiser:autodoc (list ids)))
124 ((not (symbol? (car ids)))
125 (geiser:autodoc (cdr ids)))
128 (operator-arglist id))
131 (define (geiser:no-values)
134 (define (geiser:newline)