diff --git a/collects/racket/enter.rkt b/collects/racket/enter.rkt index f7c76267f6..1132847b6a 100644 --- a/collects/racket/enter.rkt +++ b/collects/racket/enter.rkt @@ -5,43 +5,49 @@ (provide enter!) (define-syntax (enter! stx) + (define (do-enter mod noise) + (unless (or (not (syntax-e mod)) (module-path? (syntax->datum mod))) + (raise-syntax-error #f "not a valid module path, and not #f" stx mod)) + (unless (memq (syntax-e noise) '(#:verbose #:quiet #:verbose-reload)) + (raise-syntax-error #f "not a valid verbosity keyword" stx noise)) + #`(do-enter! '#,mod '#,noise)) (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))] + [(enter! mod) (do-enter #'mod #'#:verbose-reload)] + [(enter! mod noise) (do-enter #'mod #'noise)] [_ (raise-syntax-error - #f "bad syntax; should be `(enter! )'" stx)])) + #f "bad syntax; should be `(enter! [noise-flag])'" + stx)])) (define orig-namespace (current-namespace)) -(define (do-enter! mod) +(define (do-enter! mod noise) (if mod - (begin - (enter-require mod) - (let ([ns (module->namespace mod)]) - (current-namespace ns) - (namespace-require 'racket/enter))) - (current-namespace orig-namespace))) + (begin (enter-require mod noise) + (let ([ns (module->namespace mod)]) + (current-namespace ns) + (namespace-require 'racket/enter))) + (current-namespace orig-namespace))) (struct mod (name timestamp depends)) (define loaded (make-hash)) -(define (enter-require mod) +(define (enter-require mod noise) ;; Collect dependencies while loading: (parameterize ([current-load/use-compiled - (enter-load/use-compiled (current-load/use-compiled) #f)]) + (enter-load/use-compiled (current-load/use-compiled) + #f noise)]) (dynamic-require mod #f)) ;; Reload anything that's not up to date: - (check-latest mod)) + (check-latest mod noise)) -(define (notify re? path) - (fprintf (current-error-port) " [~aloading ~a]\n" (if re? "re-" "") path)) - -(define ((enter-load/use-compiled orig re?) path name) +(define ((enter-load/use-compiled orig re? noise) path name) + (define notify + (if (case noise [(#:verbose-reload) re?] [(#:verbose) #t] [(#:quiet) #f]) + (lambda (path) + (fprintf (current-error-port) + " [~aloading ~a]\n" (if re? "re-" "") path)) + void)) (if name ;; Module load: (let* ([code (get-module-code @@ -49,10 +55,8 @@ (lambda (e) (parameterize ([compile-enforce-module-constants #f]) (compile e))) - (lambda (ext loader?) - (load-extension ext) - #f) - #:notify (lambda (chosen) (notify re? chosen)))] + (lambda (ext loader?) (load-extension ext) #f) + #:notify notify)] [dir (or (current-load-relative-directory) (current-directory))] [path (path->complete-path path dir)] [path (normal-case-path (simplify-path path))]) @@ -66,9 +70,7 @@ ;; Evaluate the module: (eval code)) ;; Not a module: - (begin - (notify re? path) - (orig path name)))) + (begin (notify path) (orig path name)))) (define (get-timestamp path) (file-or-directory-modify-seconds path #f @@ -78,7 +80,7 @@ (path-replace-suffix path #".ss") #f (lambda () -inf.0)) -inf.0)))) -(define (check-latest mod) +(define (check-latest mod noise) (define mpi (module-path-index-join mod #f)) (define done (make-hash)) (let loop ([mpi mpi]) @@ -95,6 +97,7 @@ (when (ts . > . (mod-timestamp mod)) (define orig (current-load/use-compiled)) (parameterize ([current-load/use-compiled - (enter-load/use-compiled orig #f)] + (enter-load/use-compiled orig #f noise)] [current-module-declare-name rpath]) - ((enter-load/use-compiled orig #t) npath (mod-name mod))))))))) + ((enter-load/use-compiled orig #t noise) + npath (mod-name mod))))))))) diff --git a/collects/scribblings/reference/enter.scrbl b/collects/scribblings/reference/enter.scrbl index 35d894de01..11273846d2 100644 --- a/collects/scribblings/reference/enter.scrbl +++ b/collects/scribblings/reference/enter.scrbl @@ -7,28 +7,33 @@ @note-init-lib[racket/enter] @defform*[[(enter! module-path) - (enter! #f)]]{ + (enter! #f) + (enter! module-path noise-flag)]]{ -Intended for use in a @tech{REPL}, such as when @exec{mzscheme} is -started in interactive mode. When a @scheme[module-path] is provided -(in the same sense as for @scheme[require]), the corresponding module +Intended for use in a @tech{REPL}, such as when @exec{racket} is +started in interactive mode. When a @racket[module-path] is provided +(in the same sense as for @racket[require]), the corresponding module is loaded or invoked, and the current @tech{namespace} is changed to -the body of the module via @scheme[module->namespace]. When -@scheme[#f] is provided, then the current @tech{namespace} is restored +the body of the module via @racket[module->namespace]. When +@racket[#f] is provided, then the current @tech{namespace} is restored to the original one. -If invoking @scheme[module-path] requires loading any files, then +If invoking @racket[module-path] requires loading any files, then modification dates of the files are recorded. If the file is modified, -then a later @scheme[enter!] re-loads the module from source; see also -@secref["module-redeclare"]. Similarly if a later @scheme[enter!] -transitively @scheme[require]s a modified module, then the required +then a later @racket[enter!] re-loads the module from source; see also +@secref["module-redeclare"]. Similarly if a later @racket[enter!] +transitively @racket[require]s a modified module, then the required module is re-loaded. Re-loading support works only for modules that are first loaded (either directly or indirectly through transitive -@scheme[require]s) via @scheme[enter!]. +@racket[require]s) via @racket[enter!]. -After switching namespaces to the designated module, @scheme[enter!] -automatically requires @scheme[racket/enter] into the namespace, so -that @scheme[enter!] can be used to switch namespaces again. +After switching namespaces to the designated module, @racket[enter!] +automatically requires @racket[racket/enter] into the namespace, so +that @racket[enter!] can be used to switch namespaces again. -When it loads or re-loads a module from a file, @scheme[enter!] prints -a message to @scheme[(current-error-port)].} +When @racket[enter!] loads or re-loads a module from a file, it can +print a message to @racket[(current-error-port)], as determined by the +optional @racket[noise-flag]. It can be @racket[#:verbose] to print a +message about such loads and re-loads, @racket[#:verbose-reload] to +print a message only for re-loaded modules, and it can be +@racket[#:quiet] for no printouts.}