summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2013-06-10 00:06:55 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2013-06-10 00:06:55 +0200
commit7b1a1d046059eb2ce68ea02706a0e7494c39684f (patch)
tree8a72cf5b83d913cc29802ecc4d1083b5c8386423
parentbba166c3ccb136fa8321ad9acc9cfd48a5fed357 (diff)
downloadgeiser-guile-7b1a1d046059eb2ce68ea02706a0e7494c39684f.tar.gz
geiser-guile-7b1a1d046059eb2ce68ea02706a0e7494c39684f.tar.bz2
racket: new ,geiser-load command in REPL
... and used also internally for C-c C-k, although it doesn't yet work as well as i wanted when it comes to load modules. The reason is probably in geiser/enter, where we don't record modification times per submodule but per path, which is not correct in the presence of submodules.
-rw-r--r--elisp/geiser-racket.el68
-rw-r--r--elisp/geiser-syntax.el3
-rw-r--r--scheme/racket/geiser/eval.rkt8
-rw-r--r--scheme/racket/geiser/user.rkt34
4 files changed, 65 insertions, 48 deletions
diff --git a/elisp/geiser-racket.el b/elisp/geiser-racket.el
index 0d32790..5cd93dc 100644
--- a/elisp/geiser-racket.el
+++ b/elisp/geiser-racket.el
@@ -113,13 +113,41 @@ using start-geiser, a procedure in the geiser/server module."
;;; Evaluation support:
+(defconst geiser-racket--module-re
+ "^(module[+*]? +\\([^ ]+\\)\\W+\\([^ ]+\\)?")
+
+(defun geiser-racket--explicit-module ()
+ (save-excursion
+ (ignore-errors
+ (while (not (zerop (geiser-syntax--nesting-level)))
+ (backward-up-list)))
+ (and (looking-at geiser-racket--module-re)
+ (let ((mod (match-string-no-properties 1))
+ (lang (match-string-no-properties 2)))
+ (cons (geiser-syntax--form-from-string mod)
+ (geiser-syntax--form-from-string lang))))))
+
(defun geiser-racket--language ()
+ (or (cdr (geiser-racket--explicit-module))
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward "^#lang +\\([^ ]+\\)" nil t)
+ (geiser-syntax--form-from-string (match-string-no-properties 1))))
+ "#f"))
+
+(defun geiser-racket--implicit-module ()
(save-excursion
(goto-char (point-min))
- (if (re-search-forward
- "^\\(?:#lang\\|(module +[^ ]+?\\) +\\([^ ]+?\\|([^)]+)\\) *$" nil t)
- (car (geiser-syntax--read-from-string (match-string-no-properties 1)))
- "#f")))
+ (when (re-search-forward "^#lang " nil t)
+ (buffer-file-name))))
+
+(defun geiser-racket--find-module ()
+ (let ((bf (geiser-racket--implicit-module))
+ (sub (car (geiser-racket--explicit-module))))
+ (cond ((and (not bf) (not sub)) nil)
+ ((and (not bf) sub) sub)
+ (sub `(submod (file ,bf) ,sub))
+ (t bf))))
(defun geiser-racket--enter-command (module)
(when (or (stringp module) (listp module))
@@ -136,40 +164,12 @@ using start-geiser, a procedure in the geiser/server module."
(geiser-racket--language)
(mapconcat 'identity (cdr args) " ")))
((load-file compile-file)
- (format ",geiser-eval geiser/main racket (geiser:%s %s)"
- proc (car args)))
+ (format ",geiser-load %S" (geiser-racket--find-module)))
((no-values) ",geiser-no-values")
(t (format ",apply geiser:%s (%s)" proc (mapconcat 'identity args " ")))))
-(defconst geiser-racket--module-re
- "^(module[+*]? +\\([^ ]+\\)")
-
-(defun geiser-racket--explicit-module ()
- (save-excursion
- (ignore-errors
- (while (not (zerop (geiser-syntax--nesting-level)))
- (backward-up-list)))
- (and (looking-at geiser-racket--module-re)
- (ignore-errors
- (car (geiser-syntax--read-from-string
- (match-string-no-properties 1)))))))
-
-(defun geiser-racket--implicit-module ()
- (save-excursion
- (goto-char (point-min))
- (when (re-search-forward "^#lang " nil t)
- (buffer-file-name))))
-
-(defun geiser-racket--find-module ()
- (let ((bf (geiser-racket--implicit-module))
- (sub (geiser-racket--explicit-module)))
- (cond ((and (not bf) (not sub)) :f)
- ((and (not bf) sub) sub)
- (sub `(submod (file ,bf) ,sub))
- (t bf))))
-
(defun geiser-racket--get-module (&optional module)
- (cond ((null module) (geiser-racket--find-module))
+ (cond ((null module) (or (geiser-racket--find-module) :f))
((symbolp module) module)
((and (stringp module) (file-name-absolute-p module)) module)
((stringp module) (make-symbol module))
diff --git a/elisp/geiser-syntax.el b/elisp/geiser-syntax.el
index 42e265e..d790734 100644
--- a/elisp/geiser-syntax.el
+++ b/elisp/geiser-syntax.el
@@ -202,6 +202,9 @@ implementation-specific entries for font-lock-keywords.")
(save-excursion (insert string))
(cons (ignore-errors (geiser-syntax--read)) (point))))))
+(defun geiser-syntax--form-from-string (s)
+ (car (geiser-syntax--read-from-string s)))
+
(defsubst geiser-syntax--form-after-point (&optional boundary)
(let ((geiser-syntax--read/buffer-limit (and (numberp boundary) boundary)))
(save-excursion (values (geiser-syntax--read) (point)))))
diff --git a/scheme/racket/geiser/eval.rkt b/scheme/racket/geiser/eval.rkt
index 9b510cf..752a405 100644
--- a/scheme/racket/geiser/eval.rkt
+++ b/scheme/racket/geiser/eval.rkt
@@ -1,6 +1,6 @@
;;; eval.rkt -- evaluation
-;; Copyright (C) 2009, 2010, 2011, 2012 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2011, 2012, 2013 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
@@ -15,8 +15,8 @@
load-file
macroexpand
add-to-load-path
- make-repl-reader)
-
+ make-repl-reader
+ call-with-result)
(require geiser/enter geiser/modules geiser/images)
(require errortrace/errortrace-lib)
@@ -50,7 +50,7 @@
(parameterize ([current-error-port (current-output-port)])
(with-handlers ([exn? set-last-error])
(call-with-values thunk set-last-result)))))])
- (append last-result `((output . ,output)))))
+ (append last-result `(,(cons 'output output)))))
(define (eval-in form spec lang)
(write (call-with-result
diff --git a/scheme/racket/geiser/user.rkt b/scheme/racket/geiser/user.rkt
index 5ce003d..cd3fea6 100644
--- a/scheme/racket/geiser/user.rkt
+++ b/scheme/racket/geiser/user.rkt
@@ -48,6 +48,9 @@
[(symbol? parent) mod]
[else #f]))))
+(define (module-error stx mod)
+ (raise-syntax-error #f "Invalid module path" stx mod))
+
(define (enter! mod stx)
(cond [(not mod)
(current-namespace top-namespace)
@@ -56,7 +59,7 @@
[(path-string? mod) (do-enter `(file ,mod) mod)]
[(file-mod? mod) (do-enter mod (cadr mod))]
[(submod-path mod) => (lambda (m) (do-enter m m))]
- [else (raise-syntax-error #f "Invalid module path" stx mod)]))
+ [else (module-error stx mod)]))
(define orig-loader (current-load/use-compiled))
(define geiser-loader (module-loader orig-loader))
@@ -66,15 +69,25 @@
(define (eval-here form) (eval form geiser-main))
(let* ([mod (read)]
[lang (read)]
- [form (read)])
- (datum->syntax #f
- (list 'quote
- (cond [(equal? form '(unquote apply))
- (let* ([proc (eval-here (read))]
- [args (map eval-here (read))]
- [ev (lambda () (apply proc args))])
- (eval-in `(,ev) mod lang))]
- [else ((geiser:eval lang) form mod)])))))
+ [form (read)]
+ [res (cond [(equal? form '(unquote apply))
+ (let* ([proc (eval-here (read))]
+ [args (map eval-here (read))]
+ [ev (lambda () (apply proc args))])
+ (eval-in `(,ev) mod lang))]
+ [else ((geiser:eval lang) form mod)])])
+ (datum->syntax #f (list 'quote res))))
+
+(define (geiser-load stx)
+ (let* ([mod (read)]
+ [res (call-with-result
+ (lambda ()
+ (enter-module (cond [(file-mod? mod) mod]
+ [(path-string? mod) `(file ,mod)]
+ [(submod-path mod)]
+ [else (module-error stx mod)]))
+ (void)))])
+ (datum->syntax stx (list 'quote res))))
(define ((geiser-read prompt))
(prompt)
@@ -88,6 +101,7 @@
[(start-geiser) (datum->syntax #f `(list 'port ,(start-geiser)))]
[(enter) (enter! (read) #'cmd)]
[(geiser-eval) (geiser-eval)]
+ [(geiser-load) (geiser-load #'cmd)]
[(geiser-no-values) (datum->syntax #f (void))]
[(add-to-load-path) (add-to-load-path (read))]
[(set-image-cache) (image-cache (read))]