|
267 | 267 | "Returns true if x is not nil, false otherwise." |
268 | 268 | [x] (not (nil? x))) |
269 | 269 |
|
| 270 | +(defn- pr-opts-fnl [opts] |
| 271 | + (if-not (nil? opts) |
| 272 | + (:flush-on-newline opts) |
| 273 | + *flush-on-newline*)) |
| 274 | + |
| 275 | +(defn- pr-opts-readably [opts] |
| 276 | + (if-not (nil? opts) |
| 277 | + (:readably opts) |
| 278 | + *print-readably*)) |
| 279 | + |
| 280 | +(defn- pr-opts-meta [opts] |
| 281 | + (if-not (nil? opts) |
| 282 | + (:meta opts) |
| 283 | + *print-meta*)) |
| 284 | + |
| 285 | +(defn- pr-opts-dup [opts] |
| 286 | + (if-not (nil? opts) |
| 287 | + (:dup opts) |
| 288 | + *print-dup*)) |
| 289 | + |
| 290 | +(defn- pr-opts-len [opts] |
| 291 | + (if-not (nil? opts) |
| 292 | + (:print-length opts) |
| 293 | + *print-length*)) |
| 294 | + |
270 | 295 | (defn object? |
271 | 296 | "Returns true if x's constructor is Object" |
272 | 297 | [x] |
|
907 | 932 | [^not-native obj] |
908 | 933 | (let [sb (StringBuffer.) |
909 | 934 | writer (StringBufferWriter. sb)] |
910 | | - (-pr-writer obj writer (pr-opts)) |
| 935 | + (-pr-writer obj writer nil) |
911 | 936 | (-flush writer) |
912 | 937 | (.toString sb))) |
913 | 938 |
|
@@ -10441,13 +10466,13 @@ reduces them without incurring seq initialization" |
10441 | 10466 | (-write writer "#") |
10442 | 10467 | (do |
10443 | 10468 | (-write writer begin) |
10444 | | - (if (zero? (:print-length opts)) |
| 10469 | + (if (zero? (pr-opts-len opts)) |
10445 | 10470 | (when (seq coll) |
10446 | 10471 | (-write writer (or (:more-marker opts) "..."))) |
10447 | 10472 | (do |
10448 | 10473 | (when (seq coll) |
10449 | 10474 | (print-one (first coll) writer opts)) |
10450 | | - (loop [coll (next coll) n (dec (:print-length opts))] |
| 10475 | + (loop [coll (next coll) n (dec (pr-opts-len opts))] |
10451 | 10476 | (if (and coll (or (nil? n) (not (zero? n)))) |
10452 | 10477 | (do |
10453 | 10478 | (-write writer sep) |
@@ -10491,7 +10516,7 @@ reduces them without incurring seq initialization" |
10491 | 10516 | (declare print-map) |
10492 | 10517 |
|
10493 | 10518 | (defn print-meta? [opts obj] |
10494 | | - (and (boolean (get opts :meta)) |
| 10519 | + (and (boolean (pr-opts-meta opts)) |
10495 | 10520 | (implements? IMeta obj) |
10496 | 10521 | (not (nil? (meta obj))))) |
10497 | 10522 |
|
@@ -10544,7 +10569,7 @@ reduces them without incurring seq initialization" |
10544 | 10569 | (pr-sequential-writer writer pr-writer "#js [" " " "]" opts obj) |
10545 | 10570 |
|
10546 | 10571 | (string? obj) |
10547 | | - (if (:readably opts) |
| 10572 | + (if (pr-opts-readably opts) |
10548 | 10573 | (-write writer (quote-string obj)) |
10549 | 10574 | (-write writer obj)) |
10550 | 10575 |
|
@@ -10643,57 +10668,61 @@ reduces them without incurring seq initialization" |
10643 | 10668 | ([] (newline nil)) |
10644 | 10669 | ([opts] |
10645 | 10670 | (string-print "\n") |
10646 | | - (when (get opts :flush-on-newline) |
| 10671 | + (when (pr-opts-fnl opts) |
10647 | 10672 | (flush)))) |
10648 | 10673 |
|
10649 | 10674 | (defn pr-str |
10650 | 10675 | "pr to a string, returning it. Fundamental entrypoint to IPrintWithWriter." |
10651 | 10676 | [& objs] |
10652 | | - (pr-str-with-opts objs (pr-opts))) |
| 10677 | + (pr-str-with-opts objs nil)) |
10653 | 10678 |
|
10654 | 10679 | (defn prn-str |
10655 | 10680 | "Same as pr-str followed by (newline)" |
10656 | 10681 | [& objs] |
10657 | | - (prn-str-with-opts objs (pr-opts))) |
| 10682 | + (prn-str-with-opts objs nil)) |
10658 | 10683 |
|
10659 | 10684 | (defn pr |
10660 | 10685 | "Prints the object(s) using string-print. Prints the |
10661 | 10686 | object(s), separated by spaces if there is more than one. |
10662 | 10687 | By default, pr and prn print in a way that objects can be |
10663 | 10688 | read by the reader" |
10664 | 10689 | [& objs] |
10665 | | - (pr-with-opts objs (pr-opts))) |
| 10690 | + (pr-with-opts objs nil)) |
10666 | 10691 |
|
10667 | 10692 | (def ^{:doc |
10668 | 10693 | "Prints the object(s) using string-print. |
10669 | 10694 | print and println produce output for human consumption."} |
10670 | 10695 | print |
10671 | 10696 | (fn cljs-core-print [& objs] |
10672 | | - (pr-with-opts objs (assoc (pr-opts) :readably false)))) |
| 10697 | + (binding [*print-readably* false] |
| 10698 | + (pr-with-opts objs nil)))) |
10673 | 10699 |
|
10674 | 10700 | (defn print-str |
10675 | 10701 | "print to a string, returning it" |
10676 | 10702 | [& objs] |
10677 | | - (pr-str-with-opts objs (assoc (pr-opts) :readably false))) |
| 10703 | + (binding [*print-readably* false] |
| 10704 | + (pr-str-with-opts objs nil))) |
10678 | 10705 |
|
10679 | 10706 | (defn println |
10680 | 10707 | "Same as print followed by (newline)" |
10681 | 10708 | [& objs] |
10682 | | - (pr-with-opts objs (assoc (pr-opts) :readably false)) |
| 10709 | + (binding [*print-readably* false] |
| 10710 | + (pr-with-opts objs nil)) |
10683 | 10711 | (when *print-newline* |
10684 | | - (newline (pr-opts)))) |
| 10712 | + (newline nil))) |
10685 | 10713 |
|
10686 | 10714 | (defn println-str |
10687 | 10715 | "println to a string, returning it" |
10688 | 10716 | [& objs] |
10689 | | - (prn-str-with-opts objs (assoc (pr-opts) :readably false))) |
| 10717 | + (binding [*print-readably* false] |
| 10718 | + (prn-str-with-opts objs nil))) |
10690 | 10719 |
|
10691 | 10720 | (defn prn |
10692 | 10721 | "Same as pr followed by (newline)." |
10693 | 10722 | [& objs] |
10694 | | - (pr-with-opts objs (pr-opts)) |
| 10723 | + (pr-with-opts objs nil) |
10695 | 10724 | (when *print-newline* |
10696 | | - (newline (pr-opts)))) |
| 10725 | + (newline nil))) |
10697 | 10726 |
|
10698 | 10727 | (defn- strip-ns |
10699 | 10728 | [named] |
|
0 commit comments