From 42e442a75524980d1b7557ffc933c652f28fb916 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Wed, 17 Apr 2013 16:38:23 -0400 Subject: [PATCH] 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. (cherry picked from commit e311de0522318329a86669bf096d8ae75b085402) --- collects/tests/xrepl/xrepl.rkt | 13 +++++++++++++ collects/xrepl/xrepl.rkt | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/collects/tests/xrepl/xrepl.rkt b/collects/tests/xrepl/xrepl.rkt index 31205ea5c6..8c4db16c3a 100644 --- a/collects/tests/xrepl/xrepl.rkt +++ b/collects/tests/xrepl/xrepl.rkt @@ -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» @||}) diff --git a/collects/xrepl/xrepl.rkt b/collects/xrepl/xrepl.rkt index 64fed77671..58aba09515 100644 --- a/collects/xrepl/xrepl.rkt +++ b/collects/xrepl/xrepl.rkt @@ -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)]