summaryrefslogtreecommitdiff
path: root/scheme/chicken
diff options
context:
space:
mode:
authorDan Leslie <dan@ironoxide.ca>2015-12-05 07:24:59 -0800
committerDan Leslie <dan@ironoxide.ca>2015-12-05 07:24:59 -0800
commitf1f69cf0a60c6f70dee5745bbecced1a54393520 (patch)
treedc990cde84b45a0972482f5f2e9d90cb6b094199 /scheme/chicken
parent49da44f6373718400833585dd494a35f71205d6e (diff)
downloadgeiser-guile-f1f69cf0a60c6f70dee5745bbecced1a54393520.tar.gz
geiser-guile-f1f69cf0a60c6f70dee5745bbecced1a54393520.tar.bz2
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
Diffstat (limited to 'scheme/chicken')
-rw-r--r--scheme/chicken/geiser/emacs.scm32
1 files changed, 19 insertions, 13 deletions
diff --git a/scheme/chicken/geiser/emacs.scm b/scheme/chicken/geiser/emacs.scm
index f31bba9..c5772bd 100644
--- a/scheme/chicken/geiser/emacs.scm
+++ b/scheme/chicken/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)))))