branch: elpa/geiser-chicken
commit 935a114d0a42331e25ec5de0de2087128519ad98
Author: Dan Leslie <[email protected]>
Commit: Dan Leslie <[email protected]>
Allows redefinition of modules
If one were to re-evaluate a buffer with a module in it there would be
problems because it would appear as a nested request.
Solution:
- Check if a module definition is a fore-most request, and if so,
evaluate at top level
---
geiser/emacs.scm | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/geiser/emacs.scm b/geiser/emacs.scm
index f31bba9..c5772bd 100644
--- a/geiser/emacs.scm
+++ b/geiser/emacs.scm
@@ -469,10 +469,6 @@
;; Basically all non-core functions pass through geiser-eval
(define (geiser-eval module form . rest)
- ;; We can't allow nested module definitions in Chicken
- (define (form-has-module? form)
- (or (eq? (car form) 'module) (eq? (car form) 'define-library)))
-
(define (form-has-safe-geiser? form)
(any (cut eq? (car form) <>)
'(geiser-no-values geiser-newline geiser-completions
@@ -483,25 +479,35 @@
(define (form-has-any-geiser? form)
(string-has-prefix? (->string (car form)) "geiser-"))
+
+ (define (form-defines-any-module? form)
+ (or
+ ;; Geiser seems to send buffers as (begin ..buffer contents..)
+ (and (eq? (car form) 'begin)
+ (form-defines-any-module? (cadr form)))
+ (any (cut eq? (car form) <>)
+ '(module define-library))))
+
+ (define (module-matches-defined-module? module)
+ (any (cut eq? module <>) (list-modules)))
(when (and module (not (symbol? module)))
(error "Module should be a symbol"))
-
+
;; All calls start at toplevel
- (let* ((is-module? (form-has-module? form))
- (is-geiser? (form-has-any-geiser? form))
- (is-safe-geiser? (form-has-safe-geiser? form))
- (host-module (and (not is-module?)
- (not is-geiser?)
- (any (cut equal? module <>) (list-modules))
+ (let* ((is-safe-geiser? (form-has-safe-geiser? form))
+ (host-module (and (not is-safe-geiser?)
+ (not (form-has-any-geiser? form))
+ (not (form-defines-any-module? form))
+ (module-matches-defined-module? module)
module))
(thunk (lambda () (eval form))))
- (write-to-log `[[REQUEST host-module ,host-module is-safe-geiser?
,is-safe-geiser?]])
+ (write-to-log `[[REQUEST]])
(write-to-log form)
(if is-safe-geiser?
- (call-with-result host-module (lambda () (memoize form thunk)))
+ (call-with-result #f (lambda () (memoize form thunk)))
(begin
(clear-memo)
(call-with-result host-module thunk)))))