This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-04
Channels
- # announcements (7)
- # babashka (32)
- # beginners (106)
- # bristol-clojurians (10)
- # cider (6)
- # clj-kondo (5)
- # cljdoc (10)
- # clojure (110)
- # clojure-australia (10)
- # clojure-dev (6)
- # clojure-europe (12)
- # clojure-nl (2)
- # clojure-norway (16)
- # clojure-spec (9)
- # clojure-uk (59)
- # clojurescript (105)
- # community-development (2)
- # conjure (46)
- # cursive (12)
- # data-science (1)
- # datalog (26)
- # datomic (37)
- # docker (4)
- # emacs (10)
- # events (1)
- # fulcro (8)
- # graalvm (2)
- # jobs (1)
- # jobs-discuss (1)
- # malli (24)
- # meander (13)
- # off-topic (52)
- # pathom (4)
- # polylith (17)
- # proletarian (4)
- # react (1)
- # rewrite-clj (4)
- # shadow-cljs (56)
- # sql (21)
- # xtdb (14)
Hi @whatacold! I’ll have a peek and get back to you!
(Maybe interesting aside: Your sample reminded me of https://github.com/lread/test-doc-blocks, which is not at all what you are looking for or asking about, but will test code snippits found in documentation)
So I had a peek @whatacold. The following might (?) be tripping you up:
• z/right
will return nil
when there is no next sibling
• z/end?
will return true
when at (not past) the last node (https://github.com/clj-commons/rewrite-clj/issues/155). It will also return true
for a nil
input.
What do you think of this instead?
(loop [zloc zloc]
(let [zloc (some-> zloc
(z/insert-right* (n/comment-node "; test"))
(z/insert-right* (n/newlines 1)))
next-sib (z/right zloc)]
(if next-sib
(recur next-sib)
(z/print-root zloc))))
Outputs:
(defn my-function [a]
(* a 3))
;; test
(my-function 7)
;; test
Notes:
• I switched to using node creation functions, a personal preference which I find more explicit for this use case.
• Switched from insert-right
to insert-right*
. The *
version does no extra automagic whitespace handling which is what you’d want when inserting whitespace/comment nodes, I think.👍 3