Skip to content

Commit f07521c

Browse files
[pp] Print short record names by default
1 parent 1fc3b38 commit f07521c

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master (unreleased)
44

5+
- [#360](https://github.com/clojure-emacs/orchard/pull/360): Pretty-print: print short record names by default.
6+
57
## 0.37.0 (2025-09-19)
68

79
- [#353](https://github.com/clojure-emacs/orchard/pull/353): Stacktrace: flag Clojure functions as duplicate.

src/orchard/pp.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@
123123
prefix."
124124
[coll]
125125
(if (record? coll)
126-
[(str "#" (.getName (class coll)) "{") coll]
126+
[(str "#" (if print/*short-record-names*
127+
(.getSimpleName (class coll))
128+
(.getName (class coll))) "{") coll]
127129
;; If all keys in the map share a namespace and *print-
128130
;; namespace-maps* is true, print the map using map namespace
129131
;; syntax (e.g. #:a{:b 1} instead of {:a/b 1}). If the map is

src/orchard/print.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
- print `::alias/foo` instead of `:ns.aliases.in.pov.ns/foo`"
6060
nil)
6161

62+
(def ^:dynamic *short-record-names*
63+
"When true, only simple record classnames will be displayed instead of FQNs."
64+
true)
65+
6266
(defn- print-coll-item
6367
"Print an item in the context of a collection. When printing a map, don't print
6468
`[]` characters around map entries."
@@ -168,7 +172,9 @@
168172

169173
(defmethod print :record [x, ^Writer w]
170174
(.write w "#")
171-
(.write w (.getSimpleName (class x)))
175+
(.write w (if *short-record-names*
176+
(.getSimpleName (class x))
177+
(.getName (class x))))
172178
(print-map x w))
173179

174180
(defmethod print :array [x, ^Writer w]

test/orchard/pp_test.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
"(1 1 1 1 1)" (java.util.ArrayList. ^java.util.Collection (repeat 5 1))
249249
"{:a 1, :b 2}" (let [^java.util.Map x {:a 1 :b 2}]
250250
(java.util.HashMap. x))
251-
"#orchard.print_test.TestRecord{:a 1, :b 2, :c 3, :d 4}" (orchard.print-test/->TestRecord 1 2 3 4)
251+
"#TestRecord{:a 1, :b 2, :c 3, :d 4}" (orchard.print-test/->TestRecord 1 2 3 4)
252252
"[1 2 3 4]" (long-array [1 2 3 4])
253253
"[]" (long-array [])
254254
"[0 1 2 3 4]" (into-array Long (range 5))
@@ -281,3 +281,17 @@
281281
(testing "writer won't go much over total-length"
282282
(is (= 2003 (count (binding [print/*max-total-length* 2000]
283283
(print/print-str orchard.print-test/infinite-map)))))))
284+
285+
(deftest short-record-names-test
286+
(testing "*short-record-names* controls how records are printed"
287+
(is (= "#TestRecord{:a (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14),
288+
:b (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14),
289+
:c 3,
290+
:d 4}"
291+
(sut/pprint-str (orchard.print-test/->TestRecord (range 15) (range 15) 3 4))))
292+
(binding [print/*short-record-names* false]
293+
(is (= "#orchard.print_test.TestRecord{:a (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14),
294+
:b (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14),
295+
:c 3,
296+
:d 4}"
297+
(sut/pprint-str (orchard.print-test/->TestRecord (range 15) (range 15) 3 4)))))))

test/orchard/print_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,10 @@
182182
(are [kw repr] (= repr (sut/print-str kw))
183183
::foo ":orchard.print-test/foo"
184184
::t/foo ":clojure.test/foo"))))
185+
186+
(deftest short-record-names-test
187+
(testing "*short-record-names* controls how records are printed"
188+
(is (= "#TestRecord{:a 1, :b 2, :c 3, :d 4}" (sut/print-str (->TestRecord 1 2 3 4))))
189+
(binding [sut/*short-record-names* false]
190+
(is (= "#orchard.print_test.TestRecord{:a 1, :b 2, :c 3, :d 4}"
191+
(sut/print-str (->TestRecord 1 2 3 4)))))))

0 commit comments

Comments
 (0)