# Igniter.Code.Common.move\_to\_cursor returns error

**URL:** <https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806>\
**Category:** Questions\
**Tags:** ash, igniter\
**Created:** [May 9, 2025, 2:12pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806 "2025-05-09T14:12:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenchild](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zenchild/32/35073_2.png) [@zenchild](https://forum.elixirforum.com/u/zenchild)\
**Post date:** [May 9, 2025, 2:12pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/1 "2025-05-09T14:12:58Z")

</div>

I’m trying to get `Igniter.Code.Common.move_to_cursor` to work for some code patching and I’m having trouble. I keep getting an `:error` returned. I then tried to run the demo code from [the docs](https://hexdocs.pm/igniter/0.5.50/Igniter.Code.Common.html#move_to_cursor/2) and that is also returning `:error`. Is there any work-arounds or maybe I’m just doing something wrong (probably 🙂 )?

Igniter version: `igniter 0.5.50`  
Elixir version: `Elixir 1.18.1 (compiled with Erlang/OTP 27)`  
OS: OSX

```elixir
zipper =
  """
  if true do
    10
  end
  """
  |> Sourceror.Zipper.zip()

pattern =
  """
  if __ do
    __cursor__ ()
  end
  """

Igniter.Code.Common.move_to_cursor(zipper, pattern)
# returns :error

```

Many thanks for any help.

Cheers,

Dan

---

<div class="post-metadata">

**Author:** ![zenchild](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zenchild/32/35073_2.png) [@zenchild](https://forum.elixirforum.com/u/zenchild)\
**Post date:** [May 9, 2025, 4:04pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/2 "2025-05-09T16:04:32Z")

</div>

It appears to maybe just be an error in the documentation, I was able to get the example to work by parsing the string first.

```elixir
zipper =
  """
  if true do
    10
  end
  """
  |> Sourceror.parse_string!()
  |> Sourceror.Zipper.zip()

```

---

<div class="post-metadata">

**Author:** ![zachdaniel](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/32/31980_2.png) [@zachdaniel](https://forum.elixirforum.com/u/zachdaniel)\
**Post date:** [May 9, 2025, 5:56pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/3 "2025-05-09T17:56:37Z")

</div>

Yep! Error in the docs. Could you open an issue or a PR to address?

---

<div class="post-metadata">

**Author:** ![zenchild](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zenchild/32/35073_2.png) [@zenchild](https://forum.elixirforum.com/u/zenchild)\
**Post date:** [May 9, 2025, 6:27pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/4 "2025-05-09T18:27:57Z")

</div>

Will do! 👍 And thanks for Igniter! @zachdaniel

On a separate note, I’m struggling a bit finding the right way to add a function above another and skipping the documentation. Do you have a good recipe for this? I am able to add code before the function, but it’s still after the function docs.

For example:

```elixir
defmodule MyModule do
  .... stuff here

  @doc """
  Some docs
  
  blah, blah, blah
  """
  def my_function() do
    do_things
  end
end

```

Thanks for any guidance.

Cheers,

Dan

---

<div class="post-metadata">

**Author:** ![zachdaniel](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/32/31980_2.png) [@zachdaniel](https://forum.elixirforum.com/u/zachdaniel)\
**Post date:** [May 9, 2025, 7:49pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/5 "2025-05-09T19:49:29Z")

</div>

It’s a bit tough TBH. Probably what you’d need to do is move to the function, and then move up past any known module attributes like `@doc`, `@spec` etc. We could internalize that complexity into a helper like `move_to_function_and_attrs` into igniter.

---

<div class="post-metadata">

**Author:** ![zenchild](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zenchild/32/35073_2.png) [@zenchild](https://forum.elixirforum.com/u/zenchild)\
**Post date:** [May 9, 2025, 7:56pm UTC](https://forum.elixirforum.com/t/igniter-code-common-move-to-cursor-returns-error/70806/6 "2025-05-09T19:56:24Z")

</div>

Thanks for the tips. I’m just going to put it below a know function for now. 👍
