rewrite-clj.paredit
This namespace provides zipper operations for performing paredit type of operations on clojure/clojurescript forms.
You might find inspirational examples here: http://pub.gajendra.net/src/paredit-refcard.pdf
barf-backward
(barf-backward zloc)Push out the leftmost node of the current S-expression into outer left form
[1 2 [3 |4] 5] => [1 2 3 [|4] 5]
barf-forward
(barf-forward zloc)Push out the rightmost node of the current S-expression into outer right form
[1 2 [|3 4] 5] => [1 2 [|3] 4 5]
join
(join zloc)Join S-expression to the left and right of current loc. Also works for strings.
[[1 2] |[3 4]] => [[1 2 3 4]]- `[“Hello ” | “World”] => [“Hello World”]
kill-at-pos
(kill-at-pos zloc pos)In string and comment aware kill
Perform kill for given position pos Like kill, but:
- if inside string kills to end of string and stops there
- If inside comment kills to end of line (not including linebreak!)
pos should provide {:row :col } which are relative to the start of the given form the zipper represents zloc must be positioned at a node previous (given depth first) to the node at given pos
kill-one-at-pos
(kill-one-at-pos zloc pos)In string and comment aware kill for one node/word at given pos
(+ |100 100) => (+ |100)(for |(bar do)) => (foo)"|hello world" => "| world"; |hello world => ; |world
move-to-prev
(move-to-prev zloc)Move node at current location to the position of previous location given a depth first traversal
(+ 1 (+ 2 |3) 4) => (+ 1 (+ |3 2) 4)(+ 1 (+ 2 3) |4) => (+ 1 (+ 2 3 |4))
returns zloc after move or given zloc if a move isn’t possible
slurp-backward
(slurp-backward zloc)Pull in prev left outer node (if none at first level, tries next etc) into current S-expression
[1 2 [|3] 4 5] => [1 [2 |3] 4 5]
slurp-backward-fully
(slurp-backward-fully zloc)Pull in all left outer-nodes into current S-expression, but only the ones at the same level as the the first one.
[1 2 [|3] 4 5] => [[1 2 |3] 4 5]
slurp-forward
(slurp-forward zloc)Pull in next right outer node (if none at first level, tries next etc) into current S-expression
[1 2 [|3] 4 5] => [1 2 [|3 4] 5]
slurp-forward-fully
(slurp-forward-fully zloc)Pull in all right outer-nodes into current S-expression, but only the ones at the same level as the the first one.
[1 2 [|3] 4 5] => [1 2 [|3 4 5]]
splice-killing-backward
(splice-killing-backward zloc)Remove left siblings of current given node in S-Expression and unwrap remaining into enclosing S-expression
(foo (let ((x 5)) |(sqrt n)) bar) => (foo (sqrt n) bar)
splice-killing-forward
(splice-killing-forward zloc)Remove current given node and its right siblings in S-Expression and unwrap remaining into enclosing S-expression
(a (b c |d e) f) => (a b |c f)
split
(split zloc)Split current s-sexpression in two at given node zloc
[1 2 |3 4 5] => [1 2 3] [4 5]
split-at-pos
(split-at-pos zloc pos)In string aware split
Perform split at given position pos Like split, but:
- if inside string splits string into two strings
pos should provide {:row :col } which are relative to the start of the given form the zipper represents zloc must be positioned at a node previous (given depth first) to the node at given pos
wrap-around
(wrap-around zloc t)Wrap current node with a given type t (:vector, :list, :set, :map :fn)
|123 => [|123] ; given :vector|[1 [2]] => [|[1 [2]]]
wrap-fully-forward-slurp
(wrap-fully-forward-slurp zloc t)Create a new seq node of type t left of zloc then slurp fully into the new node
[1 |2 3 4] => [1 [|2 3 4]]