-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
improvement: add move_to_cursor/2 #147
Conversation
That looks like a great idea. I was asking myself if we could use iex> Code.Fragment.container_cursor_to_quoted("if ... do")
{:ok, {:if, [line: 1], [{:..., [line: 1], []}, [do: {:__cursor__, [line: 1], []}]]}}
iex> Code.Fragment.container_cursor_to_quoted("... |> Enum.filter(")
{:ok,
{:|>, [line: 1],
[
{:..., [line: 1], []},
{{:., [line: 1], [{:__aliases__, [line: 1], [:Enum]}, :filter]}, [line: 1],
[{:__cursor__, [line: 1], []}]}
]}} The Zipper.move_to_cursor(zipper, "if ... do")
Zipper.move_to_cursor(zipper, "if :ignore do", skip: :ignore) |
Hmm....that is pretty nice. I like that better than |
curious to see if it will play out |
So, I've used |
I think a variation using |
Yes, with When {zipper, caputres} = Zipper.move_to_coursor_and_capture(zipper, "__cursor__ |> Enum.map(__map) |> Enum.join(__join) ")
captures.map #=> AST for Enum.map args
captures.join #=> AST ... But, one step at a time. |
When I first took a stab at this, I went with |
iex(1)> defmodule Thing do
...(1)> def thing(__), do: 10
...(1)> end
warning: unknown compiler variable "__" (expected one of __MODULE__, __ENV__, __DIR__, __CALLER__, __STACKTRACE__)
└─ iex:2: Thing.thing/1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking a lot about this, this implementation looks reasonable and is an improvement over the existing apis, so I feel good about merging it
We can always adjust it as we see people use it more and we discover more about its shortcomings
So, I'm sure that there will need to be lots of workshopping or even that the implementation should be fully changed, but this at a minimum starts the conversation :)
Its relatively simple, but does technically break if someone is using the variables/functions
___cursor___
or___skip___
(note the triple underscores).