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* ((try-eval (lambda (x . y)
36 (with-exception-handler
40 (if (null? y) (eval x)
43 (result-mid (call-with-values
45 (try-eval form (environment module))
52 (error (if (condition? result-mid)
55 (with-output-to-string
56 (lambda () (display-condition result-mid))))))
58 (write `((result ,(write-to-string result))
63 (define (geiser:module-completions prefix . rest)
64 (define (substring? s1 s2)
65 (let ([n1 (string-length s1)] [n2 (string-length s2)])
67 (let loop1 ([i1 0] [j i2])
71 (if (char=? (string-ref s1 i1) (string-ref s2 j))
72 (loop1 (fx+ i1 1) (fx+ j 1))
73 (loop2 (fx+ i2 1)))))))))
75 (substring? prefix el))
76 (map write-to-string (library-list))))
78 (define (procedure-parameter-list p)
79 ;; same as (inspect object), then hitting c
80 (let ((s (((inspect/object p) 'code) 'source)))
82 (let ((form (s 'value)))
85 (eq? (car form) 'lambda))
90 (define (operator-arglist operator)
91 (let ((binding (eval operator)))
93 (let ((arglist (procedure-parameter-list binding)))
94 (let loop ((arglist arglist)
98 (cond ((null? arglist)
99 `(,operator ("args" (("required" ,@(reverse required))
100 ("optional" ,@(reverse optional))
102 ;; ("module" ,module)
108 (cons "..." (cons arglist optional))))
113 (if optionals? required (cons (car arglist) required))
114 (if optionals? (cons (car arglist) optional) optional))))))
117 (define (geiser:autodoc ids . rest)
118 (cond ((null? ids) '())
120 (geiser:autodoc (list ids)))
121 ((not (symbol? (car ids)))
122 (geiser:autodoc (cdr ids)))
125 (operator-arglist id))
128 (define (geiser:no-values)
131 (define (geiser:newline)