Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for structural editing operations #27

Open
or opened this issue Apr 24, 2022 · 2 comments
Open

Support for structural editing operations #27

or opened this issue Apr 24, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@or
Copy link

or commented Apr 24, 2022

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]]]
@huahaiy
Copy link
Contributor

huahaiy commented Apr 24, 2022

interesting idea, I will think about it.

@huahaiy
Copy link
Contributor

huahaiy commented Aug 13, 2022

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 huahaiy added the enhancement New feature or request label Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants