editscript icon indicating copy to clipboard operation
editscript copied to clipboard

Support for structural editing operations

Open or opened this issue 3 years ago • 2 comments

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]]]

or avatar Apr 24 '22 13:04 or

interesting idea, I will think about it.

huahaiy avatar Apr 24 '22 18:04 huahaiy

Our current definition of diff size is the number of nodes in the diff data structure. The structural editing examples you show above do not actually reduce the diff size, but increase them.

huahaiy avatar Aug 13 '22 01:08 huahaiy