ethan-leba/tree-edit

Raising outside of a wrapping statement leads to a user-ptrp, "Tree-edit could not restore location" error

nobellium1997 opened this issue · 3 comments

When raising inside of a wrapping statement, the location of the cursor gets put towards the end of the previous line which confuses tree-edit, forcing you to exit out of tree-edit state, reposition your cursor, and re-enable tree-edit state.

Repro steps:

  • Create an expression statement and wrap it inside another statement such as a for loop or while loop
  • Raise the expression statement

Example:

for x in [1,2,3]:
  print(x)

Raising the print call should repro the issue.

This is using emacs 28 on tree-editor commit 6d8e495

Thanks for the report!

Are you using a formatter on the after-change hook? Without a formatter, I'm able to reproduce the erroneous "could not restore" message, but not the cursor issue you're describing. I've noticed some formatters attempt to preserve the point location which conflicts with tree-edit's overlay. Unfortunately I can't think of any way to address this from the tree-edit directly. If that is what you're running into, you'll have to wrap the function like so:

(defun format-and-update-overlay ()
  (+format/buffer)
  (evil-tree-edit--update-overlay))

Ah I am not and I just saw the part in the getting started guide about adding a formatter as a hook. I think adding a formatter will probably help fix the issue I'm seeing so I'll just close this issue and if I do run into more problems, I'll give a heads up. Thanks for the help!

I think the formatter will make things worse actually, but I've got a fix coming for that shortly.