Skip to content

(:replace)

marks a selection for replacement with literal text or captured values

clojure
(:replace val? sub? reconcile?)

Where:

  1. val: what to replace (omit to replace whatever is matched at this position) *
  2. sub: replacement text (omit to delete the matched value) *
  3. reconcile: undefined *

Behavior

  • When sub is omitted, the matched value is dropped (deleted) from the output.
  • Supports regex capture groups ($1, $2, etc.) from pattern-based selectors.
  • Supports named captures via (:capture name ...) which can be referenced as $name in the substitution string.
  • Captures are scoped per match - each match site maintains isolated capture values.

Examples

Replace all instances of a deprecated API call with its modern equivalent.

clojure
(:replace (call oldAPI) "newAPI()")

Selects in lines { 1 } but not in { }:

typescript
x(oldAPI())
y(process())

Drop the second argument from specific function calls during refactoring.

clojure
(call processData (:replace (arg 2)))

Selects in lines { 1 } but not in { }:

typescript
processData(input, legacy)
otherCall(a, b)

Rename string literals using regex capture groups.

clojure
(:replace (str /old_(.+)/) "new_$1")

Selects in lines { 1, 2 } but not in { }:

typescript
const key = "old_users"
const other = "old_settings"

Reorder function arguments by capturing and rearranging them.

clojure
(call log
  (arg 1
    (:and
      (:capture first)
      (:replace _ "$rest, $first")))
  (arg 2.. (:capture rest (:into))))

Selects in lines { 1 } but not in { }:

typescript
log("a", "b", "c")

Add a parameter to function calls using captures from other arguments.

clojure
(call fetch
  (:and
    (arg 1 (:capture url (str)))
    (arg 2 (:replace _ "$url_config"))))

Selects in lines { 1 } but not in { }:

typescript
fetch("/api", options)

Arguments

val

inherit

sub

• String

Does NOT support: CompositionFree-form SelectionRefinementReplacement

reconcile

"auto"
"right"
"left"

Does NOT support: CompositionFree-form SelectionRefinementReplacement

Copyright © 2022-present Semantic Works, Inc.