ethan-leba / tree-edit

🌲 Structural editing in Emacs for any™ language!
GNU General Public License v3.0
395 stars 16 forks source link

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

Closed nobellium1997 closed 2 years ago

nobellium1997 commented 2 years ago

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:

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 6d8e495169d4e6bb98b3cd1a1a0a06cc806c5e59

ethan-leba commented 2 years ago

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))
nobellium1997 commented 2 years ago

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!

ethan-leba commented 2 years ago

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