rewrite-clj

https://github.com/clj-commons/rewrite-clj
2019-04-17T01:02:56.001300Z

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?

lread 2019-04-17T01:51:00.006100Z

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

2019-04-17T02:26:28.007300Z

that looks quite promising! going to take closer look. thanks 🙂

2019-04-17T06:03:38.009800Z

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.

2019-04-17T06:04:05.010100Z

is this by design?

lread 2019-04-17T10:02:47.015600Z

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.

lread 2019-04-17T10:15:46.017Z

maybe you found the first bug in the rewrite-cljs update? that would be pretty cool!

lread 2019-04-17T10:30:36.019500Z

once I get meat on all the bones, I’ll release an alpha.... but am currently still restructuring.

2019-04-17T10:35:41.021700Z

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 🙂

lread 2019-04-17T12:30:09.024900Z

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!