summaryrefslogtreecommitdiff
path: root/scheme/racket/geiser
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2010-05-24 00:03:30 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2010-05-24 00:03:30 +0200
commit2d30daecad657d692a7f3cb66deb496630362600 (patch)
tree6b4f7e2cc66633465715696ec89f018dcb2b2f20 /scheme/racket/geiser
parent0b491101472741c3728b6ccf80c121d66e90f94e (diff)
downloadgeiser-chez-2d30daecad657d692a7f3cb66deb496630362600.tar.gz
geiser-chez-2d30daecad657d692a7f3cb66deb496630362600.tar.bz2
Racket: PLT implementation renamed to Racket.
Diffstat (limited to 'scheme/racket/geiser')
-rw-r--r--scheme/racket/geiser/autodoc.rkt189
-rw-r--r--scheme/racket/geiser/completions.rkt31
-rw-r--r--scheme/racket/geiser/enter.rkt103
-rw-r--r--scheme/racket/geiser/eval.rkt81
-rw-r--r--scheme/racket/geiser/locations.rkt54
-rw-r--r--scheme/racket/geiser/main.rkt47
-rw-r--r--scheme/racket/geiser/modules.rkt150
-rw-r--r--scheme/racket/geiser/user.rkt56
-rw-r--r--scheme/racket/geiser/utils.rkt27
9 files changed, 738 insertions, 0 deletions
diff --git a/scheme/racket/geiser/autodoc.rkt b/scheme/racket/geiser/autodoc.rkt
new file mode 100644
index 0000000..0bb850d
--- /dev/null
+++ b/scheme/racket/geiser/autodoc.rkt
@@ -0,0 +1,189 @@
+;;; autodoc.rkt -- suport for autodoc echo
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sun May 03, 2009 14:45
+
+#lang racket
+
+(provide autodoc update-signature-cache get-help)
+
+(require geiser/utils geiser/modules geiser/locations scheme/help)
+
+(define (get-help symbol mod)
+ (with-handlers ((exn? (lambda (_)
+ (eval `(help ,symbol)))))
+ (eval `(help ,symbol #:from ,(ensure-module-spec mod)))))
+
+(define (autodoc ids)
+ (if (not (list? ids))
+ '()
+ (map (lambda (id) (or (autodoc* id) (list id))) ids)))
+
+(define (autodoc* id)
+ (and
+ (symbol? id)
+ (let* ((loc (symbol-location* id))
+ (name (car loc))
+ (path (cdr loc))
+ (sgns (and path (find-signatures path name id)))
+ (sgns (and sgns (if (list? sgns) sgns '()))))
+ (and sgns
+ `(,id
+ (name . ,name)
+ (args ,@(map format-signature sgns))
+ (module . ,(module-path-name->name path)))))))
+
+(define (format-signature sign)
+ (if (signature? sign)
+ `((required ,@(signature-required sign))
+ (optional ,@(signature-optional sign)
+ ,@(let ((rest (signature-rest sign)))
+ (if rest (list "...") '())))
+ (key ,@(signature-keys sign)))
+ '()))
+
+(define signatures (make-hash))
+
+(define-struct signature (required optional keys rest))
+
+(define (find-signatures path name local-name)
+ (let ((path (if (path? path) (path->string path) path)))
+ (hash-ref! (hash-ref! signatures
+ path
+ (lambda () (parse-signatures path)))
+ name
+ (lambda () (infer-signatures local-name)))))
+
+(define (parse-signatures path)
+ (let ((result (make-hasheq)))
+ (with-handlers ((exn? (lambda (e) result)))
+ (with-input-from-file path
+ (lambda ()
+ (parameterize ((read-accept-reader #t))
+ (let loop ((stx (read-syntax path)))
+ (cond ((eof-object? stx) void)
+ ((syntax->datum stx) =>
+ (lambda (datum)
+ (parse-datum! datum result)
+ (loop (read-syntax path))))
+ (else void)))))))
+ result))
+
+(define (parse-datum! datum store)
+ (with-handlers ((exn? (lambda (_) void)))
+ (match datum
+ (`(module ,name ,lang (#%module-begin . ,forms))
+ (for-each (lambda (f) (parse-datum! f store)) forms))
+ (`(module ,name ,lang . ,forms)
+ (for-each (lambda (f) (parse-datum! f store)) forms))
+ (`(define ((,name . ,formals) . ,_) . ,_)
+ (add-signature! name formals store))
+ (`(define (,name . ,formals) . ,_)
+ (add-signature! name formals store))
+ (`(define ,name (lambda ,formals . ,_))
+ (add-signature! name formals store))
+ (`(define ,name (case-lambda ,clauses ...))
+ (for-each (lambda (c) (add-signature! name (car c) store))
+ (reverse clauses)))
+ (`(define-for-syntax (,name . ,formals) . ,_)
+ (add-signature! name formals store))
+ (`(define-for-syntax ,name (lambda ,formals . ,_))
+ (add-signature! name formals store))
+ (`(define-syntax-rule (,name . ,formals) . ,_)
+ (add-signature! name formals store))
+ (`(define-syntax ,name (syntax-rules ,specials . ,clauses))
+ (for-each (lambda (c) (add-signature! name (cdar c) store))
+ (reverse clauses)))
+ (`(define-syntax ,name (lambda ,_ (syntax-case ,_ . ,clauses)))
+ (for-each (lambda (c) (add-signature! name (cdar c) store))
+ (reverse clauses)))
+ (_ void))))
+
+(define (add-signature! name formals store)
+ (when (symbol? name)
+ (hash-set! store
+ name
+ (cons (parse-formals formals)
+ (hash-ref store name '())))))
+
+(define (parse-formals formals)
+ (let loop ((formals formals) (req '()) (opt '()) (keys '()))
+ (cond ((null? formals)
+ (make-signature (reverse req) (reverse opt) (reverse keys) #f))
+ ((symbol? formals)
+ (make-signature (reverse req) (reverse opt)
+ (reverse keys) formals))
+ ((pair? (car formals)) (loop (cdr formals)
+ req
+ (cons (car formals) opt)
+ keys))
+ ((keyword? (car formals)) (let* ((kname
+ (keyword->symbol (car formals)))
+ (arg-id (cadr formals))
+ (name (if (pair? arg-id)
+ (list kname
+ (cadr arg-id))
+ kname)))
+ (loop (cddr formals)
+ req
+ opt
+ (cons name keys))))
+ (else (loop (cdr formals) (cons (car formals) req) opt keys)))))
+
+(define (infer-signatures name)
+ (define syntax-tag (cons 1 0))
+ (define error-tag (cons 1 1))
+ (define generic-signature (make-signature '(...) '() '() #f))
+ (let ((value (with-handlers ((exn:fail:syntax? (lambda (_) syntax-tag))
+ (exn:fail:contract:variable? (lambda (_)
+ error-tag)))
+ (namespace-variable-value name))))
+ (cond ((procedure? value) (arity->signatures (procedure-arity value)))
+ ((eq? value syntax-tag) (list generic-signature))
+ ((eq? value error-tag) #f)
+ (else 'variable))))
+
+(define (arity->signatures arity)
+ (define (args fst count)
+ (let* ((letts (list->vector '(#\x #\y #\z #\u #\v #\w #\r #\s)))
+ (len (vector-length letts))
+ (lett (lambda (n) (vector-ref letts (modulo n len)))))
+ (map (lambda (n) (string->symbol (format "~a" (lett n))))
+ (build-list count (lambda (n) (+ n fst))))))
+ (define (arity->signature arity)
+ (cond ((number? arity)
+ (make-signature (args 0 arity) '() '() #f))
+ ((arity-at-least? arity)
+ (make-signature (args 0 (arity-at-least-value arity))
+ '() '() 'rest))))
+ (define (conseq? lst)
+ (cond ((< (length lst) 2) (number? (car lst)))
+ ((and (number? (car lst))
+ (number? (cadr lst))
+ (eqv? (+ 1 (car lst)) (cadr lst)))
+ (conseq? (cdr lst)))
+ (else #f)))
+ (cond ((and (list? arity) (conseq? arity))
+ (let ((mi (apply min arity))
+ (ma (apply max arity)))
+ (list (make-signature (args 0 mi) (args mi (- ma mi)) '() #f))))
+ ((list? arity) (map arity->signature arity))
+ (else (list (arity->signature arity)))))
+
+(define (update-signature-cache path . form)
+ (when (and (string? path)
+ (or (null? form)
+ (and (list? (car form))
+ (not (null? (car form)))
+ (memq (caar form)
+ '(define-syntax-rule
+ define-syntax define set! define-struct)))))
+ (hash-remove! signatures path)))
+
+;;; autodoc.rkt ends here
diff --git a/scheme/racket/geiser/completions.rkt b/scheme/racket/geiser/completions.rkt
new file mode 100644
index 0000000..4cbc09f
--- /dev/null
+++ b/scheme/racket/geiser/completions.rkt
@@ -0,0 +1,31 @@
+;;; completions.rkt -- completion support
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sun Apr 26, 2009 19:02
+
+#lang racket
+
+(provide symbol-completions
+ module-completions)
+
+(require srfi/13 geiser/utils geiser/modules)
+
+(define (filter-prefix prefix lst sort?)
+ (filter (lambda (s) (string-prefix? prefix s))
+ (if sort? (sort lst string<?) lst)))
+
+(define (symbol-completions prefix)
+ (filter-prefix prefix
+ (map symbol->string (namespace-mapped-symbols))
+ #t))
+
+(define (module-completions prefix)
+ (filter-prefix prefix (module-list) #f))
+
+;;; completions.rkt ends here
diff --git a/scheme/racket/geiser/enter.rkt b/scheme/racket/geiser/enter.rkt
new file mode 100644
index 0000000..eff37f6
--- /dev/null
+++ b/scheme/racket/geiser/enter.rkt
@@ -0,0 +1,103 @@
+;;; enter.rkt -- custom module loaders
+
+;; Copyright (C) 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Wed Mar 31, 2010 21:53
+
+#lang racket/base
+
+(require syntax/modcode
+ (for-syntax scheme/base))
+
+(provide get-namespace enter-module module-loader module-loaded?)
+
+(define-struct mod (name timestamp depends))
+
+(define loaded (make-hash))
+
+(define (module-loaded? path)
+ (with-handlers ((exn? (lambda (_) #f)))
+ (let ((rp (module-path-index-resolve (module-path-index-join path #f))))
+ (hash-has-key? loaded (resolved-module-path-name rp)))))
+
+(define (enter-module mod)
+ (dynamic-require mod #f)
+ (check-latest mod))
+
+(define (module-loader orig)
+ (enter-load/use-compiled orig #f))
+
+(define (notify re? path)
+ (when re?
+ (fprintf (current-error-port) " [re-loading ~a]\n" path)))
+
+(define inhibit-eval (make-parameter #f))
+
+(define (get-namespace mod)
+ (parameterize ([inhibit-eval #t])
+ (module->namespace mod)))
+
+(define ((enter-load/use-compiled orig re?) path name)
+ (when (inhibit-eval)
+ (raise (make-exn:fail "namespace not found"
+ (current-continuation-marks))))
+ (if name
+ ;; Module load:
+ (let ([code (get-module-code path "compiled" compile
+ (lambda (ext loader?)
+ (load-extension ext)
+ #f)
+ #:notify (lambda (chosen)
+ (notify re? chosen)))]
+ [path (normal-case-path
+ (simplify-path
+ (path->complete-path path
+ (or (current-load-relative-directory)
+ (current-directory)))))])
+ ;; Record module timestamp and dependencies:
+ (let ([mod (make-mod name
+ (get-timestamp path)
+ (if code
+ (apply append
+ (map cdr (module-compiled-imports code)))
+ null))])
+ (hash-set! loaded path mod))
+ ;; Evaluate the module:
+ (eval code))
+ ;; Not a module:
+ (begin
+ (notify re? path)
+ (orig path name))))
+
+(define (get-timestamp path)
+ (file-or-directory-modify-seconds path #f (lambda () -inf.0)))
+
+(define (check-latest mod)
+ (let ([mpi (module-path-index-join mod #f)]
+ [done (make-hash)])
+ (let loop ([mpi mpi])
+ (let* ([rpath (module-path-index-resolve mpi)]
+ [path (resolved-module-path-name rpath)])
+ (when (path? path)
+ (let ([path (normal-case-path path)])
+ (unless (hash-ref done path #f)
+ (hash-set! done path #t)
+ (let ([mod (hash-ref loaded path #f)])
+ (when mod
+ (for-each loop (mod-depends mod))
+ (let ([ts (get-timestamp path)])
+ (when (ts . > . (mod-timestamp mod))
+ (let ([orig (current-load/use-compiled)])
+ (parameterize ([current-load/use-compiled
+ (enter-load/use-compiled orig #f)]
+ [current-module-declare-name rpath])
+ ((enter-load/use-compiled orig #t)
+ path
+ (mod-name mod)))))))))))))))
+
+;;; enter.rkt ends here
diff --git a/scheme/racket/geiser/eval.rkt b/scheme/racket/geiser/eval.rkt
new file mode 100644
index 0000000..e0bcffa
--- /dev/null
+++ b/scheme/racket/geiser/eval.rkt
@@ -0,0 +1,81 @@
+;;; eval.rkt -- evaluation
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sun Apr 26, 2009 00:44
+
+#lang racket
+
+(provide eval-in
+ compile-in
+ load-file
+ compile-file
+ macroexpand
+ make-repl-reader)
+
+(require scheme/enter geiser/modules geiser/autodoc)
+
+(define last-result (void))
+
+(define namespace->module-name
+ (compose module-path-name->name namespace->module-path-name))
+
+(define last-namespace (make-parameter (current-namespace)))
+
+(define (exn-key e)
+ (vector-ref (struct->vector e) 0))
+
+(define (set-last-error e)
+ (set! last-result `((error (key . ,(exn-key e)))))
+ (display (exn-message e)))
+
+(define (write-value v)
+ (with-output-to-string
+ (lambda () (write v))))
+
+(define (set-last-result . vs)
+ (set! last-result `((result ,@(map write-value vs)))))
+
+(define (call-with-result thunk)
+ (set-last-result (void))
+ (let ((output
+ (with-output-to-string
+ (lambda ()
+ (with-handlers ((exn? set-last-error))
+ (call-with-values thunk set-last-result))))))
+ (append last-result `((output . ,output)))))
+
+(define (eval-in form spec lang)
+ (call-with-result
+ (lambda ()
+ (update-signature-cache spec form)
+ (eval form (module-spec->namespace spec lang)))))
+
+(define compile-in eval-in)
+
+(define (load-file file)
+ (call-with-result
+ (lambda ()
+ (load-module file (current-output-port) (last-namespace))
+ (update-signature-cache file))))
+
+(define compile-file load-file)
+
+(define (macroexpand form . all)
+ (let ((all (and (not (null? all)) (car all))))
+ (with-output-to-string
+ (lambda ()
+ (pretty-print (syntax->datum ((if all expand expand-once) form)))))))
+
+(define (make-repl-reader builtin-reader)
+ (lambda (ns)
+ (last-namespace ns)
+ (printf "racket@~a" (namespace->module-name ns))
+ (builtin-reader)))
+
+;;; eval.rkt ends here
diff --git a/scheme/racket/geiser/locations.rkt b/scheme/racket/geiser/locations.rkt
new file mode 100644
index 0000000..b4c0f37
--- /dev/null
+++ b/scheme/racket/geiser/locations.rkt
@@ -0,0 +1,54 @@
+;;; locations.rkt -- locating symbols
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sun Apr 26, 2009 19:43
+
+#lang racket
+
+(provide symbol-location
+ symbol-location*
+ module-location
+ symbol-module-name
+ symbol-module-path-name)
+
+(require geiser/utils geiser/modules)
+
+(define (symbol-location* sym)
+ (let* ((id (namespace-symbol->identifier sym))
+ (binding (and id (identifier-binding id))))
+ (if (list? binding)
+ (cons
+ (cadr binding)
+ (resolved-module-path-name
+ (module-path-index-resolve (car binding))))
+ (cons sym #f))))
+
+(define (make-location name path line)
+ (list (cons 'name name)
+ (cons 'file (if (path? path) (path->string path) '()))
+ (cons 'line (or line '()))))
+
+(define (symbol-location sym)
+ (let* ((loc (symbol-location* sym))
+ (name (car loc))
+ (path (cdr loc)))
+ (if path
+ (make-location name path #f)
+ (module-location sym))))
+
+(define symbol-module-path-name (compose cdr symbol-location*))
+
+(define symbol-module-name
+ (compose module-path-name->name symbol-module-path-name))
+
+(define (module-location sym)
+ (make-location sym (module-spec->path-name sym) 1))
+
+
+;;; locations.rkt ends here
diff --git a/scheme/racket/geiser/main.rkt b/scheme/racket/geiser/main.rkt
new file mode 100644
index 0000000..de1c21c
--- /dev/null
+++ b/scheme/racket/geiser/main.rkt
@@ -0,0 +1,47 @@
+;;; main.rkt -- exported interface for emacs
+
+;; Copyright (C) 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Wed Mar 31, 2010 21:14
+
+#lang racket/base
+
+(provide geiser:eval
+ geiser:compile
+ geiser:load-file
+ geiser:compile-file
+ geiser:macroexpand
+ geiser:completions
+ geiser:module-completions
+ geiser:symbol-location
+ geiser:module-location
+ geiser:module-exports
+ geiser:autodoc
+ geiser:help)
+
+(require geiser/eval
+ geiser/modules
+ geiser/completions
+ geiser/locations
+ geiser/autodoc)
+
+(define (geiser:eval lang)
+ (lambda (form spec) (eval-in form spec lang)))
+(define geiser:compile compile-in)
+(define geiser:load-file load-file)
+(define geiser:compile-file compile-file)
+(define geiser:autodoc autodoc)
+(define geiser:help get-help)
+(define geiser:completions symbol-completions)
+(define geiser:module-completions module-completions)
+(define geiser:symbol-location symbol-location)
+(define geiser:module-location module-location)
+(define geiser:module-exports module-exports)
+(define geiser:macroexpand macroexpand)
+
+;;; main.rkt ends here
diff --git a/scheme/racket/geiser/modules.rkt b/scheme/racket/geiser/modules.rkt
new file mode 100644
index 0000000..0de316c
--- /dev/null
+++ b/scheme/racket/geiser/modules.rkt
@@ -0,0 +1,150 @@
+;;; modules.rkt -- module metadata
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Wed May 06, 2009 02:35
+
+#lang racket
+
+(provide load-module
+ ensure-module-spec
+ module-spec->namespace
+ namespace->module-path-name
+ module-path-name->name
+ module-spec->path-name
+ module-list
+ module-exports)
+
+(require srfi/13 syntax/modresolve syntax/modcode geiser/enter)
+
+(define (ensure-module-spec spec)
+ (cond ((symbol? spec) spec)
+ ((not (string? spec)) #f)
+ (else `(file ,spec))))
+
+(define (module-spec->namespace spec (lang #f))
+ (let ((spec (ensure-module-spec spec))
+ (try-lang (lambda (_)
+ (with-handlers ((exn? (const (current-namespace))))
+ (and lang
+ (begin
+ (load-module lang #f (current-namespace))
+ (module->namespace lang)))))))
+ (or (and spec
+ (with-handlers ((exn? try-lang)) (get-namespace spec)))
+ (current-namespace))))
+
+(define nowhere (open-output-nowhere))
+
+(define (load-module spec (port #f) (ns #f))
+ (parameterize ((current-error-port (or port nowhere)))
+ (enter-module (ensure-module-spec spec))
+ (when (namespace? ns)
+ (current-namespace ns))))
+
+(define (namespace->module-path-name ns)
+ (let ((rmp (variable-reference->resolved-module-path
+ (eval '(#%variable-reference) ns))))
+ (and (resolved-module-path? rmp)
+ (resolved-module-path-name rmp))))
+
+(define (module-spec->path-name spec)
+ (with-handlers ((exn? (lambda (_) #f)))
+ (let ((ns (module-spec->namespace (ensure-module-spec spec))))
+ (namespace->module-path-name ns))))
+
+(define (module-path-name->name path)
+ (cond ((path? path)
+ (let* ((path (path->string path))
+ (cpaths (map (compose path->string path->directory-path)
+ (current-library-collection-paths)))
+ (prefix-len (lambda (p)
+ (let ((pl (string-length p)))
+ (if (= pl (string-prefix-length p path))
+ pl
+ 0))))
+ (lens (map prefix-len cpaths))
+ (real-path (substring path (apply max lens))))
+ (if (absolute-path? real-path)
+ (call-with-values (lambda () (split-path path))
+ (lambda (_ basename __) (path->string basename)))
+ (regexp-replace "\\.[^./]*$" real-path ""))))
+ ((eq? path '#%kernel) "(kernel)")
+ ((string? path) path)
+ ((symbol? path) (symbol->string path))
+ (else "")))
+
+(define (skippable-dir? path)
+ (call-with-values (lambda () (split-path path))
+ (lambda (_ basename __)
+ (member (path->string basename) '(".svn" "compiled")))))
+
+(define path->symbol (compose string->symbol path->string))
+
+(define (path->entry path)
+ (let ((ext (filename-extension path)))
+ (and ext
+ (or (bytes=? ext #"rkt") (bytes=? ext #"ss"))
+ (let ((path (path->string path)))
+ (substring path 0 (- (string-length path) 3))))))
+
+(define (visit-module-path path kind acc)
+ (case kind
+ ((file) (let ((entry (path->entry path)))
+ (if entry (cons entry acc) acc)))
+ ((dir) (cond ((skippable-dir? path) (values acc #f))
+ ((or (file-exists? (build-path path "main.rkt"))
+ (file-exists? (build-path path "main.ss")))
+ (cons (path->string path) acc))
+ (else acc)))
+ (else acc)))
+
+(define (find-modules path acc)
+ (if (directory-exists? path)
+ (parameterize ((current-directory path))
+ (fold-files visit-module-path acc))
+ acc))
+
+(define (known-modules)
+ (sort (foldl find-modules '() (current-library-collection-paths)) string<?))
+
+(define module-cache #f)
+(define (update-module-cache)
+ (when (not module-cache) (set! module-cache (known-modules))))
+
+(define (module-list)
+ (update-module-cache)
+ module-cache)
+
+(define (module-exports mod)
+ (define (extract-ids ls)
+ (append-map (lambda (idls)
+ (map car (cdr idls)))
+ ls))
+ (define (classify-ids ids ns)
+ (let loop ((ids ids) (procs '()) (vars '()))
+ (cond ((null? ids)
+ `((procs ,@(reverse procs)) (vars ,@(reverse vars))))
+ ((procedure?
+ (namespace-variable-value (car ids) #t (const #f) ns))
+ (loop (cdr ids) (cons (car ids) procs) vars))
+ (else (loop (cdr ids) procs (cons (car ids) vars))))))
+ (let-values (((reg syn)
+ (module-compiled-exports
+ (get-module-code (resolve-module-path mod #f)))))
+ (let ((syn (extract-ids syn))
+ (reg (extract-ids reg)))
+ `((syntax ,@syn) ,@(classify-ids reg (module-spec->namespace mod))))))
+
+(define (startup)
+ (thread update-module-cache)
+ (void))
+
+(startup)
+
+;;; modules.rkt ends here
diff --git a/scheme/racket/geiser/user.rkt b/scheme/racket/geiser/user.rkt
new file mode 100644
index 0000000..3c1d93e
--- /dev/null
+++ b/scheme/racket/geiser/user.rkt
@@ -0,0 +1,56 @@
+;;; user.rkt -- global bindings visible to geiser users
+
+;; Copyright (C) 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Wed Mar 31, 2010 22:24
+
+#lang racket/base
+
+(provide enter!)
+
+(require geiser/enter geiser/eval (for-syntax scheme/base))
+
+(define-syntax (enter! stx)
+ (syntax-case stx ()
+ [(enter! mod)
+ (if (or (not (syntax-e #'mod))
+ (module-path? (syntax->datum #'mod)))
+ #'(do-enter! 'mod)
+ (raise-syntax-error
+ #f
+ "not a valid module path, and not #f"
+ stx
+ #'mod))]
+ [_ (raise-syntax-error
+ #f
+ "bad syntax; should be `(enter! <module-path-or-#f>)'"
+ stx)]))
+
+(define orig-namespace (current-namespace))
+
+(define (do-enter! mod)
+ (if mod
+ (begin
+ (enter-module mod)
+ (let ([ns (module->namespace mod)])
+ (current-namespace ns)
+ (namespace-require 'geiser/user)))
+ (current-namespace orig-namespace)))
+
+
+(define orig-loader (current-load/use-compiled))
+
+(define (init)
+ (compile-enforce-module-constants #f)
+ (current-load/use-compiled (module-loader orig-loader))
+ (current-prompt-read (compose (make-repl-reader (current-prompt-read))
+ current-namespace)))
+
+(init)
+
+;;; user.rkt ends here
diff --git a/scheme/racket/geiser/utils.rkt b/scheme/racket/geiser/utils.rkt
new file mode 100644
index 0000000..730a396
--- /dev/null
+++ b/scheme/racket/geiser/utils.rkt
@@ -0,0 +1,27 @@
+;;; utils.rkt -- generic utilities
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sun May 03, 2009 03:09
+
+#lang racket
+
+(provide pair->list
+ keyword->symbol
+ symbol->keyword)
+
+(define (pair->list pair)
+ (let loop ((d pair) (s '()))
+ (cond ((null? d) (reverse s))
+ ((symbol? d) (reverse (cons d s)))
+ (else (loop (cdr d) (cons (car d) s))))))
+
+(define keyword->symbol (compose string->symbol keyword->string))
+(define (symbol->keyword sym) (string->keyword (format "~a" sym)))
+
+;;; utils.rkt ends here