Improve some printouts.

Specifically the one from ,rr.  Also make ,switch syntax error more
friendly.  Also, test for the recent xrepl fix, including its printout.
This commit is contained in:
Eli Barzilay 2013-04-17 16:38:23 -04:00
parent ff461c0bee
commit e311de0522
2 changed files with 25 additions and 8 deletions

View File

@ -188,5 +188,18 @@
json/main> «,sh echo $F»
@|collects|/json/main.rkt
json/main> «,top»
-> «(display-to-file "#lang racket\n(provide x)\n(define x 1)\n"
"xrepl-test.rkt" #:exists 'truncate)»
-> «,rr "xrepl-test.rkt"» first load
; requiring "xrepl-test.rkt"
-> «x»
1
-> «(display-to-file "#lang racket\n(provide x)\n(define x 2)\n"
"xrepl-test.rkt" #:exists 'truncate)»
-> «,rr xrepl-test.rkt»
; reloading "xrepl-test.rkt"
-> «,rm xrepl-test.rkt»
-> «x»
2
-> «,ex»
@||})

View File

@ -110,15 +110,18 @@
[best (if (< (string-length best) (string-length x)) best x)])
best)))
(define (get-prefix* path)
(define x (path->string path))
(define x (if (string? path) path (path->string path)))
(define y (->relname path))
(if (equal? x y)
(format "~s" (choose-path x))
(regexp-replace #rx"[.]rkt$" y "")))
(match mod
[(? symbol?) (symbol->string mod)]
[(list 'quote (? symbol? s)) (format "'~a" s)]
[_ (get-prefix* mod)]))
(let loop ([mod mod])
(match mod
[(? symbol?) (symbol->string mod)]
[(list 'quote (? symbol? s)) (format "'~a" (loop s))]
[(list 'file (? string? s)) (loop (string->path s))]
[(or (? path?) (? string?)) (get-prefix* mod)]
[_ (error 'xrepl "internal error; ~v" mod)])))
(define (here-source) ; returns a path, a symbol, or #f (= not in a module)
(variable-reference->module-source
@ -749,14 +752,15 @@
(for ([mod (in-list last-rr-modules)])
(define resolved ((current-module-name-resolver) mod #f #f #f))
(define path (resolved-module-path-name resolved))
(define disp (module-displayable-name mod))
(if (hash-ref rr-modules resolved #f)
;; reload
(begin (printf "; reloading ~a\n" path)
(begin (printf "; reloading ~a\n" disp)
(parameterize ([current-module-declare-name resolved])
(load/use-compiled path)))
;; require
(begin (hash-set! rr-modules resolved #t)
(printf "; requiring ~a\n" path)
(printf "; requiring ~a\n" disp)
;; (namespace-require mod)
(eval #`(require #,mod)))))))
@ -1063,7 +1067,7 @@
(current-namespace-name name)
(current-namespace (car (hash-ref namespaces name)))))
(define (syntax-error)
(cmderror "syntax error, see ,help switch-namespace"))
(cmderror "syntax error, see \",help ~s\"" (current-command)))
(match (getarg 'sexpr 'list)
[(list) (cmderror "what do you want to do?")]
[(list '?) (list-namespaces)]