I’d like to convert (my-function x) to simply x. However, I’d like to reasonably preserve the formatting of x even if it’s a map that spans multiple lines.
I’ve located the outer expr and inner x, but that barfs when I do (z/replace outer-loc (z/node inner-loc))
Hiya @joel380, I wonder if rewrite-clj.paredit/raise might work for you.
(require '[rewrite-clj.zip :as z]
'[rewrite-clj.paredit :as pe])
(-> "{:z (my-function x)}"
z/of-string
z/down
z/right
z/down
z/right ;; now at x node
pe/raise
z/root-string)
;; => "{:z x}"
(-> "{:z (my-function {:a 1
:b 2})}"
z/of-string
z/down
z/right
z/down
z/right ;; now at {:a 1 :b 2} node
pe/raise
z/root-string)
;; => "{:z {:a 1\n :b 2}}"
It won't adjust indentation, but it might do the trick.I was wondering if there was such a thing, ill give it a try.
Let us know if it works for you!
yes, it works reasonably well, thanks!