|
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 |
|
@@ -10464,13 +10489,13 @@ reduces them without incurring seq initialization" |
10464 | 10489 | (-write writer "#") |
10465 | 10490 | (do |
10466 | 10491 | (-write writer begin) |
10467 | | - (if (zero? (:print-length opts)) |
| 10492 | + (if (zero? (pr-opts-len opts)) |
10468 | 10493 | (when (seq coll) |
10469 | 10494 | (-write writer (or (:more-marker opts) "..."))) |
10470 | 10495 | (do |
10471 | 10496 | (when (seq coll) |
10472 | 10497 | (print-one (first coll) writer opts)) |
10473 | | - (loop [coll (next coll) n (dec (:print-length opts))] |
| 10498 | + (loop [coll (next coll) n (dec (pr-opts-len opts))] |
10474 | 10499 | (if (and coll (or (nil? n) (not (zero? n)))) |
10475 | 10500 | (do |
10476 | 10501 | (-write writer sep) |
@@ -10514,7 +10539,7 @@ reduces them without incurring seq initialization" |
10514 | 10539 | (declare print-map) |
10515 | 10540 |
|
10516 | 10541 | (defn print-meta? [opts obj] |
10517 | | - (and (boolean (get opts :meta)) |
| 10542 | + (and (boolean (pr-opts-meta opts)) |
10518 | 10543 | (implements? IMeta obj) |
10519 | 10544 | (not (nil? (meta obj))))) |
10520 | 10545 |
|
@@ -10567,7 +10592,7 @@ reduces them without incurring seq initialization" |
10567 | 10592 | (pr-sequential-writer writer pr-writer "#js [" " " "]" opts obj) |
10568 | 10593 |
|
10569 | 10594 | (string? obj) |
10570 | | - (if (:readably opts) |
| 10595 | + (if (pr-opts-readably opts) |
10571 | 10596 | (-write writer (quote-string obj)) |
10572 | 10597 | (-write writer obj)) |
10573 | 10598 |
|
@@ -10666,57 +10691,61 @@ reduces them without incurring seq initialization" |
10666 | 10691 | ([] (newline nil)) |
10667 | 10692 | ([opts] |
10668 | 10693 | (string-print "\n") |
10669 | | - (when (get opts :flush-on-newline) |
| 10694 | + (when (pr-opts-fnl opts) |
10670 | 10695 | (flush)))) |
10671 | 10696 |
|
10672 | 10697 | (defn pr-str |
10673 | 10698 | "pr to a string, returning it. Fundamental entrypoint to IPrintWithWriter." |
10674 | 10699 | [& objs] |
10675 | | - (pr-str-with-opts objs (pr-opts))) |
| 10700 | + (pr-str-with-opts objs nil)) |
10676 | 10701 |
|
10677 | 10702 | (defn prn-str |
10678 | 10703 | "Same as pr-str followed by (newline)" |
10679 | 10704 | [& objs] |
10680 | | - (prn-str-with-opts objs (pr-opts))) |
| 10705 | + (prn-str-with-opts objs nil)) |
10681 | 10706 |
|
10682 | 10707 | (defn pr |
10683 | 10708 | "Prints the object(s) using string-print. Prints the |
10684 | 10709 | object(s), separated by spaces if there is more than one. |
10685 | 10710 | By default, pr and prn print in a way that objects can be |
10686 | 10711 | read by the reader" |
10687 | 10712 | [& objs] |
10688 | | - (pr-with-opts objs (pr-opts))) |
| 10713 | + (pr-with-opts objs nil)) |
10689 | 10714 |
|
10690 | 10715 | (def ^{:doc |
10691 | 10716 | "Prints the object(s) using string-print. |
10692 | 10717 | print and println produce output for human consumption."} |
10693 | 10718 | print |
10694 | 10719 | (fn cljs-core-print [& objs] |
10695 | | - (pr-with-opts objs (assoc (pr-opts) :readably false)))) |
| 10720 | + (binding [*print-readably* false] |
| 10721 | + (pr-with-opts objs nil)))) |
10696 | 10722 |
|
10697 | 10723 | (defn print-str |
10698 | 10724 | "print to a string, returning it" |
10699 | 10725 | [& objs] |
10700 | | - (pr-str-with-opts objs (assoc (pr-opts) :readably false))) |
| 10726 | + (binding [*print-readably* false] |
| 10727 | + (pr-str-with-opts objs nil))) |
10701 | 10728 |
|
10702 | 10729 | (defn println |
10703 | 10730 | "Same as print followed by (newline)" |
10704 | 10731 | [& objs] |
10705 | | - (pr-with-opts objs (assoc (pr-opts) :readably false)) |
| 10732 | + (binding [*print-readably* false] |
| 10733 | + (pr-with-opts objs nil)) |
10706 | 10734 | (when *print-newline* |
10707 | | - (newline (pr-opts)))) |
| 10735 | + (newline nil))) |
10708 | 10736 |
|
10709 | 10737 | (defn println-str |
10710 | 10738 | "println to a string, returning it" |
10711 | 10739 | [& objs] |
10712 | | - (prn-str-with-opts objs (assoc (pr-opts) :readably false))) |
| 10740 | + (binding [*print-readably* false] |
| 10741 | + (prn-str-with-opts objs nil))) |
10713 | 10742 |
|
10714 | 10743 | (defn prn |
10715 | 10744 | "Same as pr followed by (newline)." |
10716 | 10745 | [& objs] |
10717 | | - (pr-with-opts objs (pr-opts)) |
| 10746 | + (pr-with-opts objs nil) |
10718 | 10747 | (when *print-newline* |
10719 | | - (newline (pr-opts)))) |
| 10748 | + (newline nil))) |
10720 | 10749 |
|
10721 | 10750 | (defn- strip-ns |
10722 | 10751 | [named] |
|
0 commit comments