8000
It would be great to be able to limit the width of lines when pretty-printing edn, so that eg
{:foo {:bar [42 43]}
became
{:foo {:bar [42 43]}}
depending on the max-width specified.
Discussion: https://clojurians.slack.com/archives/CM5HRADAA/p1710930246744919
Fix #151: add --print-width option
I'm playing around with this option, but I'm not sure if it would fit your needs this way. E.g., I'm using fipp (an EDN pretty printer):
$ cat deps.edn | clj -M -e "(require '[fipp.edn :as e]) (e/pprint (clojure.edn/read-string (slurp *in*)) {:width 20})" {:paths ["src" "resources"], :deps {org.clojure/clojure {:mvn/version "1.11.1"}, mvxcvi/puget {:mvn/version "1.3.4"}, rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}, commons-io/commons-io {:mvn/version "2.11.0"}, org.babashka/cli {:mvn/version "0.8.58"}, com.cognitect/transit-clj {:mvn/version "1.0.333"}, clj-commons/clj-yaml {:mvn/version "1.0.26"}, cheshire/cheshire {:mvn/version "5.11.0"}, org.babashka/sci {:mvn/version "0.8.41"}, com.rpl/specter {:mvn/version "1.1.4"}, camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}}, :aliases {:test {:extra-paths ["test"], :extra-deps {clj-commons/conch {:mvn/version "0.9.2"}}}}, :tools/usage {:ns-default jet.main}}
as you can see it still is more than 20 characters wide but the output does change when I set it to 200
Bummer ... seems to work pretty well with clojure.pprint/pprint (see below, docs here).
clojure.pprint/pprint
But I guess there's performance reasons that you're not using it? FWIW, I can always pipe through the snippet below, when I need to.
cat deps.edn | clj -M -e "(require '[clojure.pprint :as pprint]) (binding [pprint/*print-right-margin* 15] (pprint/pprint (clojure.edn/read-string (slurp *in*))))" {:paths ["src" "resources"], :deps {org.clojure/clojure #:mvn{:version "1.11.1"}, mvxcvi/puget #:mvn{:version "1.3.4"}, rewrite-clj/rewrite-clj #:mvn{:version "1.1.47"}, commons-io/commons-io [snip]
You can also do that with babashka for faster startup
I'm not exactly sure why I used fipp instead of pprint, I think it was because pprint didn't work properly with graalvm a long time ago.
Activity
[-]Limit line-width with pretty-printed output[/-][+]Limit line-width whenpretty-printing edn[/+][-]Limit line-width whenpretty-printing edn[/-][+]Limit line-width when pretty-printing edn[/+]Fix #151: add --print-width option
borkdude commentedon Mar 22, 2024
I'm playing around with this option, but I'm not sure if it would fit your needs this way. E.g., I'm using fipp (an EDN pretty printer):
as you can see it still is more than 20 characters wide but the output does change when I set it to 200
grav commentedon Apr 2, 2024
Bummer ... seems to work pretty well with
clojure.pprint/pprint(see below, docs here).But I guess there's performance reasons that you're not using it? FWIW, I can always pipe through the snippet below, when I need to.
borkdude commentedon Apr 2, 2024
You can also do that with babashka for faster startup
borkdude commentedon Apr 2, 2024
I'm not exactly sure why I used fipp instead of pprint, I think it was because pprint didn't work properly with graalvm a long time ago.