Skip to content

Support for structural editing operations #27

Description

@or

Hey, great library, thanks for your work!

I'd like to create edit scripts for Clojure code patches. Would it be feasible to add operations for structural editing? I'm thinking mainly about the following ones, tho there are some others.

  1. wrap: expr -> (expr)
  2. raise: (foo expr bar) -> expr
  3. slurp: (foo) expr -> (foo expr)
  4. barf: (foo expr) -> (foo) expr

Each could work for vectors and sets as well.

Example:

(e/diff
   '(do
      (let [a 6])
      (+ a 9))
   '(do
      (let [a 6]
        (+ a 10))))
-> [[[1 2] :+ (+ a 10)] 
    [[2] :-]]

would result in a cheaper sequence of operations:

[[[1] :slurp]
 [[1 2 2] :r 10]]

Another example:

  (e/diff
   '(do
      (large-expr))
   '(do
      (let [a 6]
       (large-expr))))
-> [[[1] :r (let [a 6] (large-expr))]]

would become something like

[[[1] :wrap :list]
 [[1 0] :+ let]
 [[1 1] :+ [a 6]]]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions