From f1f69cf0a60c6f70dee5745bbecced1a54393520 Mon Sep 17 00:00:00 2001 From: Dan Leslie Date: Sat, 5 Dec 2015 07:24:59 -0800 Subject: 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 --- scheme/chicken/geiser/emacs.scm | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'scheme/chicken') 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))))) -- cgit v1.2.3