rewrite-clj.zip

->root-string

deprecated in 0.4.0

(->root-string zloc)

DEPRECATED. Use root-string instead.

->string

deprecated in 0.4.0

(->string zloc)

DEPRECATED. Use string instead.

append-child

(append-child zloc item)

Insert item as last child of the current node. Will insert a space if necessary.

append-newline

deprecated in 0.5.0

(append-newline zloc & [n])

Append a newline node representing the given number of linebreaks (default: 1).

DEPRECATED: use ‘insert-newline-right’ instead.

append-space

deprecated in 0.5.0

(append-space zloc & [n])

Append a whitespace node representing the given number of spaces (default: 1).

DEPRECATED: use ‘insert-space-right’ instead.

assoc

(assoc zloc k v)

Set map/seq element to the given value.

child-sexprs

added in 0.4.4

(child-sexprs zloc)

Get children as s-expressions.

down

(down zloc)

Move down to next non-whitespace/non-comment location.

down*

(down* G__1672)

Directly call ‘rewrite-clj.custom-zipper.core/down’ on the given arguments.

edit

(edit zloc f & args)

Apply the given function to the s-expression at the given location, using its result to replace the node there. (The result will be coerced to a node if possible.)

edit*

(edit* loc f & args)

Directly call ‘rewrite-clj.custom-zipper.core/edit’ on the given arguments.

edit->

macro

(edit-> zloc & body)

Like ->, applying the given function to the current zipper location. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) as the original node.

edit->>

macro

(edit->> zloc & body)

Like ->>, applying the given function to the current zipper location. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) as the original node.

edit-node

(edit-node zloc f)

Apply the given function to the current zipper location. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) as the original node.

edn

(edn node)(edn node {:keys [track-position?], :as options})

Create zipper over the given Clojure/EDN node and move to the first non-whitespace/non-comment child.

If :track-position? is set, this will create a custom zipper that will return the current row/column using rewrite-clj.zip/position. (Note that this custom zipper will be incompatible with clojure.zip’s functions.)

edn*

(edn* node)(edn* node {:keys [track-position?]})

Create zipper over the given Clojure/EDN node.

If :track-position? is set, this will create a custom zipper that will return the current row/column using rewrite-clj.zip/position. (Note that this custom zipper will be incompatible with clojure.zip’s functions.)

end?

(end? zloc)

Check whether the given node is at the end of the depth-first traversal.

find

(find zloc p?)(find zloc f p?)

Find node satisfying the given predicate by repeatedly applying the given movement function to the initial zipper location.

find-depth-first

(find-depth-first zloc p?)

Find node satisfying the given predicate by traversing the zipper in a depth-first way.

find-next

(find-next zloc p?)(find-next zloc f p?)

Find node other than the current zipper location matching the given predicate by applying the given movement function to the initial zipper location.

find-next-depth-first

(find-next-depth-first zloc p?)

Find node other than the current zipper location matching the given predicate by traversing the zipper in a depth-first way.

find-next-tag

(find-next-tag zloc t)(find-next-tag zloc f t)

Find node other than the current zipper location with the given tag by repeatedly applying the given movement function to the initial zipper location.

find-next-token

(find-next-token zloc p?)(find-next-token zloc f p?)

Find next token node matching the given predicate by applying the given movement function to the initial zipper location, defaulting to right.

find-next-value

(find-next-value zloc v)(find-next-value zloc f v)

Find next token node whose value matches the given one by applying the given movement function to the initial zipper location, defaulting to right.

find-tag

(find-tag zloc t)(find-tag zloc f t)

Find node with the given tag by repeatedly applying the given movement function to the initial zipper location.

find-token

(find-token zloc p?)(find-token zloc f p?)

Find token node matching the given predicate by applying the given movement function to the initial zipper location, defaulting to right.

find-value

(find-value zloc v)(find-value zloc f v)

Find token node whose value matches the given one by applying the given movement function to the initial zipper location, defaulting to right.

get

(get zloc k)

If a map is given, get element with the given key; if a seq is given, get nth element.

insert-child

(insert-child zloc item)

Insert item as first child of the current node. Will insert a space if necessary.

insert-left

(insert-left zloc item)

Insert item to the right of the left location. Will insert a space if necessary.

insert-left*

(insert-left* G__1701 G__1702)

Directly call ‘rewrite-clj.custom-zipper.core/insert-left’ on the given arguments.

insert-right

(insert-right zloc item)

Insert item to the right of the current location. Will insert a space if necessary.

insert-right*

(insert-right* G__1705 G__1706)

Directly call ‘rewrite-clj.custom-zipper.core/insert-right’ on the given arguments.

left

(left zloc)

Move left to next non-whitespace/non-comment location.

left*

(left* G__1691)

Directly call ‘rewrite-clj.custom-zipper.core/left’ on the given arguments.

leftmost

(leftmost zloc)

Move to the leftmost non-whitespace/non-comment location.

leftmost*

(leftmost* G__1696)

Directly call ‘rewrite-clj.custom-zipper.core/leftmost’ on the given arguments.

leftmost?

(leftmost? zloc)

Check if the given location represents the leftmost non-whitespace/ non-comment one.

length

(length zloc)

Get length of printable string for the given zipper location.

linebreak?

(linebreak? zloc)

list?

(list? zloc)

map

(map f zloc)

Apply function to all value nodes in the given seq node. Iterates over value nodes of maps but over each element of a seq.

map-keys

(map-keys f zloc)

Apply function to all key nodes of the given map node.

map-vals

(map-vals f zloc)

Apply function to all value nodes of the given map node.

map?

(map? zloc)

next

(next zloc)

Move to the next non-whitespace/non-comment location in a depth-first manner.

next*

(next* G__1719)

Directly call ‘rewrite-clj.custom-zipper.core/next’ on the given arguments.

node

(node G__1656)

Returns the node at loc

of-file

(of-file f)(of-file f options)

Create zipper from File.

of-string

(of-string s)(of-string s options)

Create zipper from String.

position

(position loc)

Returns the ones-based [row col] of the start of the current node

postwalk

added in 0.4.9

(postwalk zloc f)(postwalk zloc p? f)

Perform a depth-first post-order traversal starting at the given zipper location and apply the given function to each child node. If a predicate p? is given, only apply the function to nodes matching it.

prefix

(prefix zloc s)

prepend-newline

deprecated in 0.5.0

(prepend-newline zloc & [n])

Prepend a newline node representing the given number of linebreaks (default: 1).

DEPRECATED: use ‘insert-newline-left’ instead.

prepend-space

deprecated in 0.5.0

(prepend-space zloc & [n])

Prepend a whitespace node representing the given number of spaces (default: 1).

DEPRECATED: use ‘insert-space-left’ instead.

prev

(prev zloc)

Move to the next non-whitespace/non-comment location in a depth-first manner.

prev*

(prev* G__1726)

Directly call ‘rewrite-clj.custom-zipper.core/prev’ on the given arguments.

prewalk

(prewalk zloc f)(prewalk zloc p? f)

Perform a depth-first pre-order traversal starting at the given zipper location and apply the given function to each child node. If a predicate p? is given, only apply the function to nodes matching it.

print

(print zloc & [writer])

Print current zipper location.

print-root

(print-root zloc & [writer])

Zip up and print root node.

remove

(remove zloc)

Remove value at the given zipper location. Returns the first non-whitespace node that would have preceded it in a depth-first walk. Will remove whitespace appropriately.

[1  2  3]   => [1  3]
[1 2]       => [1]
[1 2]       => [2]
[1]         => []
[  1  ]     => []
[1 [2 3] 4] => [1 [2 3]]
[1 [2 3] 4] => [[2 3] 4]

If a node is located rightmost, both preceding and trailing spaces are removed, otherwise only trailing spaces are touched. This means that a following element (no matter whether on the same line or not) will end up in the same position (line/column) as the removed one, unless a comment lies between the original node and the neighbour.

remove*

(remove* G__1733)

Directly call ‘rewrite-clj.custom-zipper.core/remove’ on the given arguments.

replace

(replace zloc value)

Replace the node at the given location with one representing the given value. (The value will be coerced to a node if possible.)

replace*

(replace* G__1709 G__1710)

Directly call ‘rewrite-clj.custom-zipper.core/replace’ on the given arguments.

right

(right zloc)

Move right to next non-whitespace/non-comment location.

right*

(right* G__1683)

Directly call ‘rewrite-clj.custom-zipper.core/right’ on the given arguments.

rightmost

(rightmost zloc)

Move to the rightmost non-whitespace/non-comment location.

rightmost*

(rightmost* G__1688)

Directly call ‘rewrite-clj.custom-zipper.core/rightmost’ on the given arguments.

rightmost?

(rightmost? zloc)

Check if the given location represents the leftmost non-whitespace/ non-comment one.

root

(root G__1680)

zips all the way up and returns the root node, reflecting any changes.

root-string

added in 0.4.0

(root-string zloc)

Create string representing the zipped-up zipper.

seq?

(seq? zloc)

set?

(set? zloc)

sexpr

(sexpr zloc)

Get sexpr represented by the given node.

skip

(skip f p? zloc)

Perform the given movement while the given predicate returns true.

skip-whitespace

(skip-whitespace zloc)(skip-whitespace f zloc)

Perform the given movement (default: z/right) until a non-whitespace/ non-comment node is encountered.

skip-whitespace-left

(skip-whitespace-left zloc)

Move left until a non-whitespace/non-comment node is encountered.

splice

(splice zloc)

Splice the given node, i.e. merge its children into the current one (akin to Clojure’s unquote-splicing macro: ~@...).

  • if the node is not one that can have children, no modification will be performed.
  • if the node has no or only whitespace children, it will be removed.
  • otherwise, splicing will be performed, moving the zipper to the first non-whitespace child afterwards.

string

added in 0.4.0

(string zloc)

Create string representing the current zipper location.

subedit->

macro

(subedit-> zloc & body)

Like ->, applying modifications to the current sub-tree, zipping up to the current location afterwards.

subedit->>

macro

(subedit->> zloc & body)

Like ->>, applying modifications to the current sub-tree, zipping up to the current location afterwards.

subedit-node

(subedit-node zloc f)

Apply the given function to the current sub-tree. The resulting zipper will be located on the root of the modified sub-tree.

suffix

(suffix zloc s)

tag

(tag zloc)

Get tag of node at the current zipper location.

up

(up zloc)

Move up to next non-whitespace/non-comment location.

up*

(up* G__1677)

Directly call ‘rewrite-clj.custom-zipper.core/up’ on the given arguments.

value

deprecated in 0.4.0

(value zloc)

DEPRECATED. Return a tag/s-expression pair for inner nodes, or the s-expression itself for leaves.

vector?

(vector? zloc)

whitespace-or-comment?

(whitespace-or-comment? zloc)

whitespace?

(whitespace? zloc)