rewrite-clj 2024-07-19

having updated a part of a map using rewrite-clj, how do I pprint the result out so that the formatting that was there before is preserved and the new key in the map is pretty-printed too ? Currently I'm able to update the map and output the result, but the new key isn't pretty-printed

Hi @octo221! Rewrite-clj preserves existing whitespace but doesn't automatically format/pretty-print changes you make. If you share a code snippet, the result you are getting, and the result you'd like, I can probably show you something that will work. For a more generic approach, some folks just run their rewrite-clj-changed code through cljfmt or zprint.

(-> 
    "{:a 3
      :c 5 
      :x 
        {:y 2}
      }"
    z/of-string
    (z/find-value z/next :x)
    z/next
    (z/edit (fn [m] (assoc m :z {:d 1 :e 9})))
    z/root-string)
"{:a 3\n:c 5 \n:x \n {:y 2, :z {:d 1, :e 9}}\n}" I would like the map in :z to be pretty-printed with each key on a separate line

Also you might consider https://github.com/borkdude/rewrite-edn which does some formatting.

I'm pretty sure I've answered this one before, https://clojurians.slack.com/archives/CHB5Q2XUJ/p1632608106050800 is conceptually the same, I think. Does it help?

If not, lemme know and I can help with your specific example.

ok I see the principle - thank you

You are very welcome! Drop by if you get stuck.