Skip to content

Commit 6114fae

Browse files
committed
Ensure print-method for unreadable symbols preserves metadata
1 parent 97411f6 commit 6114fae

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Changes can be:
1515

1616
* 🔌 Make websocket reconnect automatically on close to avoid having to reload the page
1717
* 💫 Cache expressions that return `nil` in memory
18+
* 🐜 Ensure custom `print-method` supporting unreadable symbols preserves metadata
1819

1920
## 0.13.842 (2023-03-07)
2021

src/nextjournal/clerk/viewer.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
#?(:clj
344344
(defmethod print-method clojure.lang.Keyword [o w]
345345
(if (roundtrippable? o)
346-
(.write w (str o))
346+
(print-simple o w)
347347
(.write w (pr-str (->viewer-eval (if-let [ns (namespace o)]
348348
(list 'keyword ns (name o))
349349
(list 'keyword (name o)))))))))
@@ -352,7 +352,7 @@
352352
(defmethod print-method clojure.lang.Symbol [o w]
353353
(if (or (roundtrippable? o)
354354
(= (name o) "?@")) ;; splicing reader conditional, see issue #338
355-
(.write w (str o))
355+
(print-simple o w)
356356
(.write w (pr-str (->viewer-eval (if-let [ns (namespace o)]
357357
(list 'symbol ns (name o))
358358
(list 'symbol (name o)))))))))

test/nextjournal/clerk/viewer_test.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,11 @@
354354
(pr-str (symbol "~")))))
355355

356356
(testing "splicing reader conditional prints normally (issue #338)"
357-
(is (= "?@" (pr-str (symbol "?@"))))))
357+
(is (= "?@" (pr-str (symbol "?@")))))
358+
359+
(testing "custom print-method for symbol preserves metadata"
360+
(is (-> (binding [*print-meta* true]
361+
(pr-str '[^:foo bar])) read-string first meta :foo))))
358362

359363
(deftest removed-metadata
360364
(is (= "(do 'this)"

0 commit comments

Comments
 (0)