given row, column info and a zipper created with track-position? true, is there an easy way to end up at the loc within the zipper that corresponds to (or surrounds) the given row, column?
there are some find functions in rewrite-cljs that are not in rewrite-clj... I have ported them over to cljc using the track-position of the custom-zipper. This is not released yet and will at least be reorganized, but this work in progress might be of interest https://github.com/lread/rewrite-cljs-playground/blob/e615c42a42f27cceccdc920ebb322b6bf1253093/src/cljc/rewrite_clj/impl/zip/find.cljc#L51
that looks quite promising! going to take closer look. thanks 🙂
in the cljc-spike-2 branch of the aforementioned repository, given:
(require '[rewrite-clj.zip :as rz])
(def a-form "(defn hi-fn\n [x]\n (+ x 1))")
why is it that:
(-> a-form (rz/of-string {:track-position? true}) (rz/find-last-by-pos [2 4]) rz/string)
(-> a-form (rz/of-string {:track-position? true}) (rz/find-last-by-pos [2 5]) rz/string)
both return "x"?
also i noticed that:
(-> a-form (rz/of-string {:track-position? true}) (rz/find-last-by-pos [1 14]) rz/string)
returns "\n" -- here 14 is a position beyond the end of the row in question.is this by design?
probably? I did not design these fns, just transcribed them. That said, I could have made errors transcribing... I’ll put it on my todos to have a look.
maybe you found the first bug in the rewrite-cljs update? that would be pretty cool!
once I get meat on all the bones, I’ll release an alpha.... but am currently still restructuring.
thanks for the responses. fwiw, it appears that something similar to the "x" example case also occurs with the last element of (+ x 1):
(-> a-form (rz/of-string {:track-position? true}) (rz/find-last-by-pos [3 8]) rz/string)
(-> a-form (rz/of-string {:track-position? true}) (rz/find-last-by-pos [3 9]) rz/string)
here, both return "1".
looking forward to the alpha, but no pressure 🙂thanks, I’ll add your examples to my notes. I’m enjoying the journey quite a bit, and do look forward to your continued feedback and help!