Fork me on GitHub
#rewrite-clj
<
2021-09-24
>
yogthos17:09:51

ah totally missed that 🙂

lread20:09:59

No problemo @yogthos, it is getting to be a rather lengthy doc. Lemme know if you happen to find anything confusing in docs and I’ll try to make things clearer.

yogthos20:09:43

awesome thanks, I’ll mention if I run into anything I can’t figure out

yogthos20:09:03

a few more examples of doing different transforms could be handy, for example I needed to inject new require statements, and this is what I settled on

(defn append-requires [zloc requires ctx]
  (let [zloc-ns         (z/find-value zloc z/next 'ns)
        zloc-require    (z/up (z/find-value zloc-ns z/next :require))
        updated-require (reduce
                          (fn [zloc child]
                            ;;TODO formatting
                            (if (require-exists? (z/sexpr zloc) child)
                              zloc
                              (z/append-child zloc child)))
                          zloc-require
                          requires)]
    (loop [z-loc updated-require]
      (if-let [parent (z/up z-loc)]
        (recur parent)
        z-loc))))

yogthos20:09:38

one thing I couldn’t get to work was injecting a new line for each child

lread20:09:12

Yeah that’s a good idea. Some more simple examples of usage would be helfpul.

lread20:09:09

Did the insert-newline-* zipper fns not work for you? Or was it sensible indentation you were hoping for?