Liking cljdoc? Tell your friends :D

rewrite-cljc.zip

A rich API for navigating and updating Clojure/ClojureScripti/EDN source code via a zipper tree.

The zipper holds a tree of nodes representing source code. It also holds your current location while navigating through the tree and any pending changes you have made. Changes are applied back into the tree when invoking root functions.

Although they are preserved, whitespace and comment nodes are normally skipped when navigating through the tree. There are times when you will want to include whitespace and comment nodes, and as you see below, provisions are available to do so.

It is good to remember that while some function names convey mutation, we are never changing anything, we are instead returning modified copies.

Some conventions in the code and docstrings:

  • zloc is the used as the argument name for our zipper
  • "current node in zloc" is shorthand for: node at current location in zipper zloc

Because this API contains many functions, we offer the following categorized listing:

Create a zipper edn edn* of-string of-file

Move left right up down prev next leftmost rightmost

Move without skipping whitespace and comments left* right* up* down* prev* next* leftmost* rightmost*

Whitespace/comment aware skip skip skip-whitespace skip-whitespace-left

Test for whitespace whitespace? linebreak? whitespace-or-comment?

Test location leftmost? rightmost? end?

Test data type seq? list? vector? set? map?

Find find find-next find-depth-first find-next-depth-first find-tag find-next-tag find-value find-next-value find-token find-next-token find-last-by-pos find-tag-by-pos

Inspect node position position-span tag length

Convert sexpr [[child-sexpr]]

Update replace edit splice prefix suffix insert-right insert-left insert-child insert-space-left insert-space-right insert-newline-left insert-newline-right append-child remove remove-preserve-newline root

Update without whitespace treatment replace* edit* insert-left* insert-right* insert-child* append-child* remove*

Isolated update without changing location edit-node subedit-node subzip prewalk postwalk edit-> edit->> subedit-> subedit->>

Sequence operations map map-keys map-vals get assoc

Stringify string root-string

Output print print-root

A rich API for navigating and updating Clojure/ClojureScripti/EDN source code via a zipper tree.

The zipper holds a tree of nodes representing source code. It also holds your current location while navigating
through the tree and any pending changes you have made. Changes are applied back into the tree
when invoking root functions.

Although they are preserved, whitespace and comment nodes are normally skipped when navigating through the tree.
There are times when you will want to include whitespace and comment nodes, and as you see below, provisions are
available to do so.

It is good to remember that while some function names convey mutation, we are never changing anything, we are
instead returning modified copies.

Some conventions in the code and docstrings:
- `zloc` is the used as the argument name for our zipper
- "current node in `zloc`" is shorthand for: node at current location in zipper `zloc`

Because this API contains many functions, we offer the following categorized listing:

**Create a zipper**
[[edn]]
[[edn*]]
[[of-string]]
[[of-file]]

**Move**
[[left]]
[[right]]
[[up]]
[[down]]
[[prev]]
[[next]]
[[leftmost]]
[[rightmost]]

**Move without skipping whitespace and comments**
[[left*]]
[[right*]]
[[up*]]
[[down*]]
[[prev*]]
[[next*]]
[[leftmost*]]
[[rightmost*]]

**Whitespace/comment aware skip**
[[skip]]
[[skip-whitespace]]
[[skip-whitespace-left]]

**Test for whitespace**
[[whitespace?]]
[[linebreak?]]
[[whitespace-or-comment?]]

**Test location**
[[leftmost?]]
[[rightmost?]]
[[end?]]

**Test data type**
[[seq?]]
[[list?]]
[[vector?]]
[[set?]]
[[map?]]

**Find**
[[find]]
[[find-next]]
[[find-depth-first]]
[[find-next-depth-first]]
[[find-tag]]
[[find-next-tag]]
[[find-value]]
[[find-next-value]]
[[find-token]]
[[find-next-token]]
[[find-last-by-pos]]
[[find-tag-by-pos]]

**Inspect**
[[node]]
[[position]]
[[position-span]]
[[tag]]
[[length]]

**Convert**
[[sexpr]]
[[child-sexpr]]

**Update**
[[replace]]
[[edit]]
[[splice]]
[[prefix]]
[[suffix]]
[[insert-right]]
[[insert-left]]
[[insert-child]]
[[insert-space-left]]
[[insert-space-right]]
[[insert-newline-left]]
[[insert-newline-right]]
[[append-child]]
[[remove]]
[[remove-preserve-newline]]
[[root]]

**Update without whitespace treatment**
[[replace*]]
[[edit*]]
[[insert-left*]]
[[insert-right*]]
[[insert-child*]]
[[append-child*]]
[[remove*]]

**Isolated update without changing location**
[[edit-node]]
[[subedit-node]]
[[subzip]]
[[prewalk]]
[[postwalk]]
[[edit->]]
[[edit->>]]
[[subedit->]]
[[subedit->>]]

**Sequence operations**
[[map]]
[[map-keys]]
[[map-vals]]
[[get]]
[[assoc]]

**Stringify**
[[string]]
[[root-string]]

**Output**
[[print]]
[[print-root]]
raw docstring

->root-stringclj/sdeprecated

(->root-string zloc)

DEPRECATED. Renamed to root-string.

DEPRECATED. Renamed to [[root-string]].
sourceraw docstring

->stringclj/sdeprecated

(->string zloc)

DEPRECATED. Renamed to string.

DEPRECATED. Renamed to [[string]].
sourceraw docstring

append-childclj/s

(append-child zloc item)

Return zipper with item appended as last child of the current node in zloc. Will insert a space if necessary.

Return zipper with `item` appended as last child of the current node in `zloc`.
Will insert a space if necessary.
sourceraw docstring

append-child*clj/s

(append-child* zloc item)

Raw version of append-child.

Returns zipper with item inserted as the rightmost child of the current node in zloc, without moving.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[append-child]].

Returns zipper with `item` inserted as the rightmost child of the current node in `zloc`,
  without moving.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

append-newlineclj/sdeprecated

(append-newline zloc & [n])

DEPRECATED: renamed to insert-newline-right.

DEPRECATED: renamed to [[insert-newline-right]].
sourceraw docstring

append-spaceclj/sdeprecated

(append-space zloc & [n])

DEPRECATED: renamed to insert-space-right.

DEPRECATED: renamed to [[insert-space-right]].
sourceraw docstring

assocclj/s

(assoc zloc k v)

Returns zipper with key k set to value v when current node in zloc is a map node. Returns zipper with index k set to value v when current node in zloc is a sequence.

Returns zipper with key `k` set to value `v` when current node in `zloc` is a map node.
Returns zipper with index `k` set to value `v` when current node in `zloc` is a sequence.
sourceraw docstring

child-sexprsclj/s

(child-sexprs zloc)

Return s-expression of children of current node in zloc.

Return s-expression of children of current node in `zloc`.
sourceraw docstring

downclj/s

(down zloc)

Return zipper with location moved down to next non-whitespace/non-comment node in zloc.

Return zipper with location moved down to next non-whitespace/non-comment node in `zloc`.
sourceraw docstring

down*clj/s

(down* zloc)

Raw version of down.

Returns zipper with the location at the leftmost child of current node in zloc, or nil if no children.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[down]].

Returns zipper with the location at the leftmost child of current node in `zloc`, or
  nil if no children.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

editclj/s

(edit zloc f & args)

Return zipper with the current node in zloc replaced with the result of:

(f (s-expression node) args)

The result of f will be coerced to a node if possible.

Return zipper with the current node in `zloc` replaced with the result of:

(`f` (s-expression node) `args`)

The result of `f` will be coerced to a node if possible.
sourceraw docstring

edit*clj/s

(edit* zloc f & args)

Raw version of edit.

Returns zipper with value of (f current-node args) replacing current node in zloc

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[edit]].

Returns zipper with value of `(f current-node args)` replacing current node in `zloc`

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

edit->clj/smacro

(edit-> zloc & body)

Like ->, threads zloc through forms. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) as incoming zloc.

Like `->`, threads `zloc` through forms.
The resulting zipper will be located at the same path (i.e. the same
number of downwards and right movements from the root) as incoming `zloc`.
sourceraw docstring

edit->>clj/smacro

(edit->> zloc & body)

Like ->>, threads zloc through forms. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) as incoming zloc.

Like `->>`, threads `zloc` through forms.
The resulting zipper will be located at the same path (i.e. the same
number of downwards and right movements from the root) as incoming `zloc`.
sourceraw docstring

edit-nodeclj/s

(edit-node zloc f)

Return zipper applying function f to zloc. The resulting zipper will be located at the same path (i.e. the same number of downwards and right movements from the root) incoming zloc.

Return zipper applying function `f` to `zloc`. The resulting
zipper will be located at the same path (i.e. the same number of
downwards and right movements from the root) incoming `zloc`.
sourceraw docstring

ednclj/s

(edn node)
(edn node options)

Create and return zipper from Clojure/ClojureScript/EDN node (likely parsed by [[rewrite-cljc.parse]]) and move to the first non-whitespace/non-comment child.

Set :track-position? in options to enable ones-based row/column tracking. See rewrite-cljc.zip/position.

NOTE: when position tracking is enabled, clojure.zip is not interchangeable with rewrite-cljc.zip, you must use rewrite-cljc.zip.

Create and return zipper from Clojure/ClojureScript/EDN `node` (likely parsed by [[rewrite-cljc.parse]])
and move to the first non-whitespace/non-comment child.

Set `:track-position?` in `options` to enable ones-based row/column tracking.
See [[rewrite-cljc.zip/position]].

NOTE: when position tracking is enabled, `clojure.zip` is not interchangeable with `rewrite-cljc.zip`, you must use `rewrite-cljc.zip`.
sourceraw docstring

edn*clj/s

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

Create and return zipper from Clojure/ClojureScript/EDN node (likely parsed by [[rewrite-cljc.parse]]).

Set :track-position? in options to enable ones-based row/column tracking. See rewrite-cljc.zip/position.

NOTE: when position tracking is enabled, clojure.zip is not interchangeable with rewrite-cljc.zip, you must use rewrite-cljc.zip.

Create and return zipper from Clojure/ClojureScript/EDN `node` (likely parsed by [[rewrite-cljc.parse]]).

Set `:track-position?` in `options` to enable ones-based row/column tracking.
See [[rewrite-cljc.zip/position]].

NOTE: when position tracking is enabled, `clojure.zip` is not interchangeable with `rewrite-cljc.zip`, you must use `rewrite-cljc.zip`.
sourceraw docstring

end?clj/s

(end? zloc)

Return true if zloc is at end of depth-first traversal.

Return true if `zloc` is at end of depth-first traversal.
sourceraw docstring

findclj/s

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

Return the first node satisfying predicate p? seaching from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first node satisfying predicate `p?` seaching from the current node
in `zloc` traversing by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-depth-firstclj/s

(find-depth-first zloc p?)

Return first node satisfying predicate p? searching depth-first from the current node in zloc.

Return first node satisfying predicate `p?` searching depth-first from
the current node in `zloc`.
sourceraw docstring

find-last-by-posclj/s

(find-last-by-pos zloc pos)
(find-last-by-pos zloc pos p?)

Return the last node spanning position pos that satisfies predicate p? searching depth-first from the current node in zloc.

NOTE: Does not ignore whitespace/comment nodes.

Return the last node spanning position `pos` that satisfies predicate `p?`
 searching depth-first from the current node in `zloc`.

NOTE: Does not ignore whitespace/comment nodes.
sourceraw docstring

find-nextclj/s

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

Return the first node satisfying predicate p? searching one movement f from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first node satisfying predicate `p?` searching one movement `f` from the current
node in `zloc` traversing by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-next-depth-firstclj/s

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

Return the first node satisfying predicate p? searching depth-first from one node after the current node in zloc

Return the first node satisfying predicate `p?` searching depth-first from one
node after the current node in `zloc`
sourceraw docstring

find-next-tagclj/s

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

Return the first node with tag t searching one movement f from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first node with tag `t` searching one movement `f` from the current
node in `zloc` traversing by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-next-tokenclj/s

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

Return the first token node satisfying predicate p? searching from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first token node satisfying predicate `p?` searching from the current node in `zloc` traversing
by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-next-valueclj/s

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

Return the first token node with value v searching one movement f from the current node in zloc traversing by function f.

v can be a single value or a set. When v is a set matches on any value in set.

f defaults to rewrite-cljc.zip/right

Return the first token node with value `v` searching one movement `f` from the current node in `zloc` traversing
by function `f`.

`v` can be a single value or a set. When `v` is a set matches on any value in set.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-tagclj/s

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

Return the first node with tag t searching from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first node with tag `t` searching from the current node in `zloc` traversing by
function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-tag-by-posclj/s

(find-tag-by-pos zloc pos t)

Return the last node spanning position pos with tag t searching depth-first from the current node in zloc.

Return the last node spanning position `pos` with tag `t` searching depth-first from the current node in `zloc`.
sourceraw docstring

find-tokenclj/s

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

Return the first token node satisfying predicate p? searching from the current node in zloc traversing by function f.

f defaults to rewrite-cljc.zip/right

Return the first token node satisfying predicate `p?` searching from the current node in `zloc` traversing
by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

find-valueclj/s

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

Return the first token node with value v searching one movement f from the current node in zloc traversing by function f.

v can be a single value or a set. When v is a set matches on any value in set.

f defaults to rewrite-cljc.zip/right

Return the first token node with value `v` searching one movement `f` from the current node in `zloc` traversing
by function `f`.

`v` can be a single value or a set. When `v` is a set matches on any value in set.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

getclj/s

(get zloc k)

Returns value node mapped to key k when current node in zloc is a map node. Returns nth k value node when current node in zloc is a sequence node.

Returns value node mapped to key `k` when current node in `zloc` is a map node.
Returns nth `k` value node when current node in `zloc` is a sequence node.
sourceraw docstring

insert-childclj/s

(insert-child zloc item)

Return zipper with item inserted as the first child of the current node in zloc.

Return zipper with `item` inserted as the first child of the current node in `zloc`.
sourceraw docstring

insert-child*clj/s

(insert-child* zloc item)

Raw version of insert-child.

Returns zipper with item inserted as the leftmost child of the current node in zloc, without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[insert-child]].

Returns zipper with `item` inserted as the leftmost child of the current node in `zloc`,
  without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

insert-leftclj/s

(insert-left zloc item)

Return zipper with item inserted to the left of the current node in zloc. Will insert a space if necessary.

Return zipper with `item` inserted to the left of the current node in `zloc`.
Will insert a space if necessary.
sourceraw docstring

insert-left*clj/s

(insert-left* zloc item)

Raw version of insert-left.

Returns zipper with item inserted as the left sibling of current node in zloc, without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[insert-left]].

Returns zipper with `item` inserted as the left sibling of current node in `zloc`,
 without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

insert-newline-leftclj/s

(insert-newline-left zloc)
(insert-newline-left zloc n)

Return zipper with n newlines node inserted to the left of the current node in zloc. n defaults to 1.

Return zipper with `n` newlines node inserted to the left of the current node in `zloc`.
`n` defaults to 1.
sourceraw docstring

insert-newline-rightclj/s

(insert-newline-right zloc)
(insert-newline-right zloc n)

Return zipper with n newlines node inserted to the right of the current node in zloc. n defaults to 1.

Return zipper with `n` newlines node inserted to the right of the current node in `zloc`.
`n` defaults to 1.
sourceraw docstring

insert-rightclj/s

(insert-right zloc item)

Return zipper with item inserted to the right of the current node in zloc. Will insert a space if necessary.

Return zipper with `item` inserted to the right of the current node in `zloc`.
Will insert a space if necessary.
sourceraw docstring

insert-right*clj/s

(insert-right* zloc item)

Raw version of insert-right.

Returns zipper with item inserted as the right sibling of the current node in zloc, without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[insert-right]].

Returns zipper with `item` inserted as the right sibling of the current node in `zloc`,
  without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

insert-space-leftclj/s

(insert-space-left zloc)
(insert-space-left zloc n)

Return zipper with n space whitespace node inserted to the left of the current node in zloc. n defaults to 1.

Return zipper with `n` space whitespace node inserted to the left of the current node in `zloc`.
`n` defaults to 1.
sourceraw docstring

insert-space-rightclj/s

(insert-space-right zloc)
(insert-space-right zloc n)

Return zipper with n space whitespace node inserted to the right of the current node in zloc. n defaults to 1.

Return zipper with `n` space whitespace node inserted to the right of the current node in `zloc`.
`n` defaults to 1.
sourceraw docstring

leftclj/s

(left zloc)

Return zipper with location moved left to next non-whitespace/non-comment node in zloc.

Return zipper with location moved left to next non-whitespace/non-comment node in `zloc`.
sourceraw docstring

left*clj/s

(left* zloc)

Raw version of left.

Returns zipper with location at the left sibling of the current node in zloc, or nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[left]].

Returns zipper with location at the left sibling of the current node in `zloc`, or nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

leftmostclj/s

(leftmost zloc)

Return zipper with location moved to the leftmost non-whitespace/non-comment node in zloc.

Return zipper with location moved to the leftmost non-whitespace/non-comment node in `zloc`.
sourceraw docstring

leftmost*clj/s

(leftmost* zloc)

Raw version of leftmost.

Returns zipper with location at the leftmost sibling of the current node in zloc, or self.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[leftmost]].

Returns zipper with location at the leftmost sibling of the current node in `zloc`, or self.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

leftmost?clj/s

(leftmost? zloc)

Return true if at leftmost non-whitespace/non-comment node in zloc.

Return true if at leftmost non-whitespace/non-comment node in `zloc`.
sourceraw docstring

lengthclj/s

(length zloc)

Return length of printable string of current node in zloc.

Return length of printable string of current node in `zloc`.
sourceraw docstring

linebreak?clj/s

(linebreak? zloc)

Returns true when the current node in zloc is a linebreak.

Returns true when the current node in `zloc` is a linebreak.
sourceraw docstring

list?clj/s

(list? zloc)

Returns true if current node in zloc is a list.

Returns true if current node in `zloc` is a list.
sourceraw docstring

mapclj/s

(map f zloc)

Returns zipper with function f applied to all value nodes of current node in zloc. Current node must be a sequence node.

Iterates over:

  • value nodes of maps
  • each element of a seq
Returns zipper with function `f` applied to all value nodes of current node in `zloc`.
Current node must be a sequence node.

Iterates over:
- value nodes of maps
- each element of a seq
sourceraw docstring

map-keysclj/s

(map-keys f zloc)

Returns zipper with function f applied to all key nodes of the current node in zloc. Current node must be map node.

Returns zipper with function `f` applied to all key nodes of the current node in `zloc`.
Current node must be map node.
sourceraw docstring

map-valsclj/s

(map-vals f zloc)

Returns zipper with function f applied to all value current node in zloc. Current node must be map node.

Returns zipper with function `f` applied to all value current node in `zloc`.
Current node must be map node.
sourceraw docstring

map?clj/s

(map? zloc)

Returns true if current node in zloc is a map.

Returns true if current node in `zloc` is a map.
sourceraw docstring

nextclj/s

(next zloc)

Return zipper with location moved to the next depth-first non-whitespace/non-comment node in zloc.

Return zipper with location moved to the next depth-first non-whitespace/non-comment node in `zloc`.
sourceraw docstring

next*clj/s

(next* {:keys [end?] :as zloc})

Raw version of next.

Returns zipper with location at the next depth-first location in the hierarchy in zloc. When reaching the end, returns a distinguished zipper detectable via end?. If already at the end, stays there.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[next]].

Returns zipper with location at the next depth-first location in the hierarchy in `zloc`.
  When reaching the end, returns a distinguished zipper detectable via [[end?]]. If already
  at the end, stays there.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

nodeclj/s

(node zloc)

Returns the current node in zloc.

Returns the current node in `zloc`.
sourceraw docstring

of-fileclj

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

Create and return zipper from all forms in Clojure/ClojureScript/EDN File f.

Set :track-position? in options to enable ones-based row/column tracking. See rewrite-cljc.zip/position.

NOTE: when position tracking is enabled, clojure.zip is not interchangeable with rewrite-cljc.zip, you must use rewrite-cljc.zip.

Create and return zipper from all forms in Clojure/ClojureScript/EDN File `f`.

Set `:track-position?` in `options` to enable ones-based row/column tracking.
See [[rewrite-cljc.zip/position]].

NOTE: when position tracking is enabled, `clojure.zip` is not interchangeable with `rewrite-cljc.zip`, you must use `rewrite-cljc.zip`.
sourceraw docstring

of-stringclj/s

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

Create and return zipper from all forms in Clojure/ClojureScript/EDN string s.

Set :track-position? in options to enable ones-based row/column tracking. See rewrite-cljc.zip/position.

NOTE: when position tracking is enabled, clojure.zip is not interchangeable with rewrite-cljc.zip, you must use rewrite-cljc.zip.

Create and return zipper from all forms in Clojure/ClojureScript/EDN string `s`.

Set `:track-position?` in `options` to enable ones-based row/column tracking.
See [[rewrite-cljc.zip/position]].

NOTE: when position tracking is enabled, `clojure.zip` is not interchangeable with `rewrite-cljc.zip`, you must use `rewrite-cljc.zip`.
sourceraw docstring

positionclj/s

(position zloc)

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

Returns the ones-based `[row col]` of the start of the current node in `zloc`.
sourceraw docstring

position-spanclj/s

(position-span zloc)

Returns the ones-based [[start-row start-col] [end-row end-col]] of the current node in zloc.

Returns the ones-based `[[start-row start-col] [end-row end-col]]` of the current node in `zloc`.
sourceraw docstring

postwalkclj/s

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

Return zipper modified by an isolated depth-first post-order traversal. Traversal starts at the current node in zloc and continues to the end of the isolated sub-tree. Function f is called on the zipper locations satisfying predicate p?, or all locations when p? is absent, and must return a valid zipper - modified or not.

Note that by default a newly created zipper automatically navigates to the first non-whitespace node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:

(-> (zip/of-string "my clojure forms")
    zip/up
    (zip/postwalk ...))

WARNING: when function f changes the location in the zipper, normal traversal will be affected.

Return zipper modified by an isolated depth-first post-order traversal.
Traversal starts at the current node in `zloc` and continues to the end of the isolated sub-tree.
Function `f` is called on the zipper locations satisfying predicate `p?`, or all locations when `p?` is absent,
and must return a valid zipper - modified or not.

Note that by default a newly created zipper automatically navigates to the first non-whitespace
node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:

```Clojure
(-> (zip/of-string "my clojure forms")
    zip/up
    (zip/postwalk ...))
```

WARNING: when function `f` changes the location in the zipper, normal traversal will be affected.
sourceraw docstring

prefixclj/s

(prefix zloc s)

Return zipper with the current node in zloc prefixed with string s. Operates on token node or a multi-line node, else exception is thrown. When multi-line, first line is prefixed.

Return zipper with the current node in `zloc` prefixed with string `s`.
Operates on token node or a multi-line node, else exception is thrown.
When multi-line, first line is prefixed.
sourceraw docstring

prepend-newlineclj/sdeprecated

(prepend-newline zloc & [n])

DEPRECATED: renamed to insert-newline-left.

DEPRECATED: renamed to [[insert-newline-left]].
sourceraw docstring

prepend-spaceclj/sdeprecated

(prepend-space zloc & [n])

DEPRECATED: renamed to insert-space-left.

DEPRECATED: renamed to [[insert-space-left]].
sourceraw docstring

prevclj/s

(prev zloc)

Return zipper with location moved to the previous depth-first non-whitespace/non-comment node in zloc.

Return zipper with location moved to the previous depth-first non-whitespace/non-comment node in `zloc`.
sourceraw docstring

prev*clj/s

(prev* zloc)

Raw version of prev.

Returns zipper with location at the previous depth-first location in the hierarchy in zloc. If already at the root, returns nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[prev]].

Returns zipper with location at the previous depth-first location in the hierarchy in `zloc`.
  If already at the root, returns nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

prewalkclj/s

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

Return zipper modified by an isolated depth-first pre-order traversal. Traversal starts at the current node in zloc and continues to the end of the isolated sub-tree. Function f is called on the zipper locations satisfying predicate p?, or all locations when p? is absent, and must return a valid zipper - modified or not.

Note that by default a newly created zipper automatically navigates to the first non-whitespace node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:

(-> (zip/of-string "my clojure forms")
    zip/up
    (zip/prewalk ...))

WARNING: when function f changes the location in the zipper, normal traversal will be affected.

Return zipper modified by an isolated depth-first pre-order traversal.
Traversal starts at the current node in `zloc` and continues to the end of the isolated sub-tree.
Function `f` is called on the zipper locations satisfying predicate `p?`, or all locations when `p?` is absent,
and must return a valid zipper - modified or not.

Note that by default a newly created zipper automatically navigates to the first non-whitespace
node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:

```Clojure
(-> (zip/of-string "my clojure forms")
    zip/up
    (zip/prewalk ...))
```

WARNING: when function `f` changes the location in the zipper, normal traversal will be affected.
sourceraw docstring

printclj/s

(print zloc & [writer])

Print current node in zloc.

NOTE: Optional writer is currently ignored for ClojureScript.

Print current node in `zloc`.

NOTE: Optional `writer` is currently ignored for ClojureScript.
sourceraw docstring

(print-root zloc & [writer])

Zip up and print zloc from root node.

NOTE: Optional writer is currently ignored for ClojureScript.

Zip up and print `zloc` from root node.

NOTE: Optional `writer` is currently ignored for ClojureScript.
sourceraw docstring

removeclj/s

(remove zloc)

Return zipper with current node in zloc removed. Returned zipper location is moved to the first non-whitespace node preceding removed node in a depth-first walk. Removes 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 the removed node is at the rightmost location, both preceding and trailing spaces are removed, otherwise only trailing spaces are removed. 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.

Return zipper with current node in `zloc` removed. Returned zipper location
 is moved to the first non-whitespace node preceding removed node in a depth-first walk.
 Removes 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 the removed node is at the rightmost location, both preceding and trailing spaces are removed,
 otherwise only trailing spaces are removed. 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.
sourceraw docstring

remove*clj/s

(remove* zloc)

Raw version of remove.

Returns zipper with current node in zloc removed, with location at node that would have preceded it in a depth-first walk.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[remove]].

Returns zipper with current node in `zloc` removed, with location at node that would have preceded
  it in a depth-first walk.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

remove-preserve-newlineclj/s

(remove-preserve-newline zloc)

Same as remove but preserves newlines.

Same as [[remove]] but preserves newlines.
sourceraw docstring

replaceclj/s

(replace zloc value)

Return zipper with the current node in zloc replaced with value which will be coerced to a node if possible.

Return zipper with the current node in `zloc` replaced with `value`
which will be coerced to a node if possible.
sourceraw docstring

replace*clj/s

(replace* zloc node)

Raw version of replace.

Returns zipper with node replacing current node in zloc, without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[replace]].

Returns zipper with `node` replacing current node in `zloc`, without moving location.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

(right zloc)

Return zipper with location moved right to next non-whitespace/non-comment node in zloc.

Return zipper with location moved right to next non-whitespace/non-comment node in `zloc`.
sourceraw docstring

right*clj/s

(right* zloc)

Raw version of right.

Returns zipper with location at the right sibling of the current node in zloc, or nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[right]].

Returns zipper with location at the right sibling of the current node in `zloc`, or nil.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

rightmostclj/s

(rightmost zloc)

Return zipper with location moved to the rightmost non-whitespace/non-comment node in zloc.

Return zipper with location moved to the rightmost non-whitespace/non-comment node in `zloc`.
sourceraw docstring

rightmost*clj/s

(rightmost* zloc)

Raw version of rightmost.

Returns zipper with location at the rightmost sibling of the current node in zloc, or self.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[rightmost]].

Returns zipper with location at the rightmost sibling of the current node in `zloc`, or self.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

rightmost?clj/s

(rightmost? zloc)

Return true if at rightmost non-whitespace/non-comment node in zloc.

Return true if at rightmost non-whitespace/non-comment node in `zloc`.
sourceraw docstring

rootclj/s

(root {:keys [end?] :as zloc})

Zips all the way up zloc and returns zipper at the root node, reflecting any changes.

Zips all the way up `zloc` and returns zipper at the root node, reflecting any changes.
sourceraw docstring

root-stringclj/s

(root-string zloc)

Return string representing the zipped-up zloc zipper.

Return string representing the zipped-up `zloc` zipper.
sourceraw docstring

seq?clj/s

(seq? zloc)

Returns true if current node in zloc is a sequence.

Returns true if current node in `zloc` is a sequence.
sourceraw docstring

set?clj/s

(set? zloc)

Returns true if current node in zloc is a set.

Returns true if current node in `zloc` is a set.
sourceraw docstring

sexprclj/s

(sexpr zloc)

Return s-expression of current node in zloc.

Return s-expression of current node in `zloc`.
sourceraw docstring

skipclj/s

(skip f p? zloc)

Return zipper with location moved to first location not satisfying predicate p? starting from the node in zloc and traversing by function f.

Return zipper with location moved to first location not satisfying predicate `p?` starting from the node in
`zloc` and traversing by function `f`.
sourceraw docstring

skip-whitespaceclj/s

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

Return zipper with location moved to first non-whitespace/non-comment starting from current node in zloc and traversing by function f.

f defaults to rewrite-cljc.zip/right

Return zipper with location moved to first non-whitespace/non-comment starting from current node in `zloc`
and traversing by function `f`.

`f` defaults to [[rewrite-cljc.zip/right]]
sourceraw docstring

skip-whitespace-leftclj/s

(skip-whitespace-left zloc)

Return zipper with location moved to first non-whitespace/non-comment starting from current node in zloc traversing left.

Return zipper with location moved to first non-whitespace/non-comment starting from current node in `zloc` traversing left.
sourceraw docstring

spliceclj/s

(splice zloc)

Return zipper with the children of the current node in zloc merged into itself. (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.
Return zipper with the children of the current node in `zloc` merged into itself.
(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.
sourceraw docstring

stringclj/s

(string zloc)

Return string representing the current node in zloc.

Return string representing the current node in `zloc`.
sourceraw docstring

subedit->clj/smacro

(subedit-> zloc & body)

Like ->, threads zloc, as an isolated sub-tree through forms, then zips up to, and locates at, the root of the modified sub-tree.

Like `->`, threads `zloc`, as an isolated sub-tree through forms, then zips
up to, and locates at, the root of the modified sub-tree.
sourceraw docstring

subedit->>clj/smacro

(subedit->> zloc & body)

Like ->. Threads zloc, as an isolated sub-tree through forms, then zips up to, and locates at, the root of the modified sub-tree.

Like `->`. Threads `zloc`, as an isolated sub-tree through forms, then zips
up to, and locates at, the root of the modified sub-tree.
sourceraw docstring

subedit-nodeclj/s

(subedit-node zloc f)

Return zipper replacing current node in zloc with result of f applied to said node as an isolated sub-tree. The resulting zipper will be located on the root of the modified sub-tree.

Return zipper replacing current node in `zloc` with result of `f` applied to said node as an isolated sub-tree.
The resulting zipper will be located on the root of the modified sub-tree.
sourceraw docstring

subzipclj/s

(subzip zloc)

Create and return a zipper whose root is the current node in zloc.

Create and return a zipper whose root is the current node in `zloc`.
sourceraw docstring

suffixclj/s

(suffix zloc s)

Return zipper with the current node in zloc suffixed with string s. Operates on token node or a multi-line node, else exception is thrown. When multi-line, last line is suffixed.

Return zipper with the current node in `zloc` suffixed with string `s`.
Operates on token node or a multi-line node, else exception is thrown.
When multi-line, last line is suffixed.
sourceraw docstring

tagclj/s

(tag zloc)

Return tag of current node in zloc.

Return tag of current node in `zloc`.
sourceraw docstring

upclj/s

(up zloc)

Return zipper with location moved up to next non-whitespace/non-comment node in zloc.

Return zipper with location moved up to next non-whitespace/non-comment node in `zloc`.
sourceraw docstring

up*clj/s

(up* zloc)

Raw version of up.

Returns zipper with the location at the parent of current node in zloc, or nil if at the top.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.

Raw version of [[up]].

Returns zipper with the location at the parent of current node in `zloc`, or nil if at
  the top.

NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes.
sourceraw docstring

valueclj/sdeprecated

(value zloc)

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

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

vector?clj/s

(vector? zloc)

Returns true if current node in zloc is a vector.

Returns true if current node in `zloc` is a vector.
sourceraw docstring

whitespace-or-comment?clj/s

(whitespace-or-comment? zloc)

Returns true when current node in zloc is whitespace or a comment.

Returns true when current node in `zloc` is whitespace or a comment.
sourceraw docstring

whitespace?clj/s

(whitespace? zloc)

Returns true when the current the node in zloc is a Clojure whitespace (which includes the comma).

Returns true when the current the node in `zloc` is a Clojure whitespace (which includes the comma).
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close