Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit line-width when pretty-printing edn #151

Open
grav opened this issue Mar 20, 2024 · 4 comments
Open

Limit line-width when pretty-printing edn #151

grav opened this issue Mar 20, 2024 · 4 comments

Comments

@grav
Copy link

grav commented Mar 20, 2024

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

@grav grav changed the title Limit line-width with pretty-printed output Limit line-width whenpretty-printing edn Mar 20, 2024
@grav grav changed the title Limit line-width whenpretty-printing edn Limit line-width when pretty-printing edn Mar 20, 2024
borkdude added a commit that referenced this issue Mar 21, 2024
@borkdude
Copy link
Owner

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

@grav
Copy link
Author

grav commented 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.

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]

@borkdude
Copy link
Owner

borkdude commented Apr 2, 2024

You can also do that with babashka for faster startup

@borkdude
Copy link
Owner

borkdude commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants