Permalink
Browse files

Bind print vars when loading a file

fixes NREPL-41
  • Loading branch information...
1 parent aad7b65 commit 11e3993746950640cb8173fbcd3b074c53b26ce0 @trptcolin trptcolin committed Mar 22, 2013
@@ -36,13 +36,15 @@ be loaded."} file-contents (atom {}))
(keys file-contents))]
(assoc (apply dissoc file-contents expired-keys)
file-key file))))
- (pr-str `(try
- (clojure.lang.Compiler/load
- (java.io.StringReader. (@@(var file-contents) '~file-key))
- ~file-path
- ~file-name)
- (finally
- (swap! @(var file-contents) dissoc '~file-key))))))
+ (binding [*print-length* nil
+ *print-level* nil]
+ (pr-str `(try
+ (clojure.lang.Compiler/load
+ (java.io.StringReader. (@@(var file-contents) '~file-key))
+ ~file-path
+ ~file-name)
+ (finally
+ (swap! @(var file-contents) dissoc '~file-key)))))))
(defn ^{:dynamic true} load-file-code
"Given the contents of a file, its _source-path-relative_ path,
@@ -56,7 +58,11 @@ be loaded."} file-contents (atom {}))
[file file-path file-name]
(apply format
"(clojure.lang.Compiler/load (java.io.StringReader. %s) %s %s)"
- (map pr-str [file file-path file-name])))
+ (map (fn [item]
+ (binding [*print-length* nil
+ *print-level* nil]
+ (pr-str item)))
+ [file file-path file-name])))
(defn wrap-load-file
"Middleware that evaluates a file's contents, as per load-file,
@@ -6,7 +6,7 @@
clojure.test)
(:require [clojure.tools.nrepl :as nrepl]))
-(use-fixtures :once repl-server-fixture)
+(use-fixtures :each repl-server-fixture)
(def-repl-test load-code-with-debug-info
(doall (nrepl/message timeout-session
@@ -44,4 +44,17 @@
(nrepl/code
(-> #'clojure.tools.nrepl.load-file-sample/dfunction
meta
- (select-keys [:file :line])))))))
+ (select-keys [:file :line])))))))
+
+(def-repl-test load-file-with-print-vars
+ (set! *print-length* 3)
+ (set! *print-level* 3)
+ (doall
+ (nrepl/message session {:op "load-file"
+ :file "(def a (+ 1 (+ 2 (+ 3 (+ 4 (+ 5 6))))))
+ (def b 2) (def c 3) (def ^{:internal true} d 4)"
+ :file-path "path/from/source/root.clj"
+ :file-name "root.clj"}))
+
+ (is (= [4]
+ (repl-values session (nrepl/code d)))))
@@ -14,7 +14,9 @@
[f]
(with-open [server (server/start-server)]
(binding [*server* server]
- (f))))
+ (f)
+ (set! *print-length* nil)
+ (set! *print-level* nil))))
(use-fixtures :each repl-server-fixture)

3 comments on commit 11e3993

Thanks for fixing this -- any chance of a release? :)

Being able to turn use custom print-length bindings could greatly reduce the number of times one has to restart emacs after an accidental large bit of REPL output causes it to hang...

Member

trptcolin replied May 9, 2013

I think @cemerick has another fix baking that he'd like to get in first, and due to some nasty business with Nexus that I don't fully understand, the release process is more heavyweight than usual for the moment, hence the delay.

Member

cemerick replied May 10, 2013

FYI, putting a release together now.

Please sign in to comment.