On Oct 24, 12:18 pm, "Stuart Sierra" <[EMAIL PROTECTED]> wrote:
> I've attached a patch to add *print-str-length* that does the same
> thing for strings:
Okay, NOW I've attached a patch.
-Stuart
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: src/clj/clojure/boot.clj
===================================================================
--- src/clj/clojure/boot.clj (revision 1077)
+++ src/clj/clojure/boot.clj (working copy)
@@ -3451,6 +3451,15 @@
is nil indicating no limit."}
*print-level* nil)
+(def
+ #^{:doc "*print-str-length* controls the maximum length of a
+ string the printer will print. If it is bound to logical false,
+ there is no limit. Otherwise, it must be bound to an integer
+ indicating the maximum length of string to print. Longer strings
+ will be truncated with '...' to represent the remaining
+ characters."}
+*print-str-length* nil)
+
(defn- print-sequential [#^String begin, print-one, #^String sep, #^String end, sequence, #^Writer w]
(binding [*print-level* (and *print-level* (dec *print-level*))]
(if (and *print-level* (neg? *print-level*))
@@ -3545,12 +3554,15 @@
(defmethod print-method String [#^String s, #^Writer w]
(if *print-readably*
- (do (.append w \")
- (dotimes n (count s)
- (let [c (.charAt s n)
- e (char-escape-string c)]
- (if e (.write w e) (.append w c))))
- (.append w \"))
+ (let [s (if (and *print-str-length* (> (count s) *print-str-length*))
+ (str (subs s 0 *print-str-length*) "...")
+ s)]
+ (do (.append w \")
+ (dotimes n (count s)
+ (let [c (.charAt s n)
+ e (char-escape-string c)]
+ (if e (.write w e) (.append w c))))
+ (.append w \")))
(.write w s))
nil)
Index: src/jvm/clojure/lang/Repl.java
===================================================================
--- src/jvm/clojure/lang/Repl.java (revision 1077)
+++ src/jvm/clojure/lang/Repl.java (working copy)
@@ -26,6 +26,7 @@
static final Var warn_on_reflection = RT.var("clojure", "*warn-on-reflection*");
static final Var print_meta = RT.var("clojure", "*print-meta*");
static final Var print_length = RT.var("clojure", "*print-length*");
+static final Var print_str_length = RT.var("clojure", "*print-str-length*");
static final Var print_level = RT.var("clojure", "*print-level*");
static final Var star1 = RT.var("clojure", "*1");
static final Var star2 = RT.var("clojure", "*2");
@@ -47,6 +48,7 @@
warn_on_reflection, warn_on_reflection.get(),
print_meta, print_meta.get(),
print_length, print_length.get(),
+ print_str_length, print_str_length.get(),
print_level, print_level.get(),
star1, null,
star2, null,