I have a package that creates overlays as annotations. Part of the functionality is to delete annotations too. It turns out neither of these seems to be undoable. I.e. if you add an overlay to text, you cannot type C-/ to undo the addition, and if you accidentally delete an overlay you can not type C-/ to get it back.

Is it possible to add things to the undo list that would make this possible?

  • I have seen libraries that add functions to the buffer-undo-list, so you could add a function that adds/removes overlays. You can look at the multiple-cursors package, and a very old yasnippet package for some ideas. I had to deal with removing those functions from the buffer-undo-list when working on a custom version of undo-tree ... :) E.g., (apply activate-cursor-for-undo 40) and (apply deactivate-cursor-after-undo 38). Keep in mind that if you are adding markers, that may complicate the situation since those are apt to get garbage collected depending upon circumstances... – lawlist Sep 21 '17 at 2:58
  • I have a notation in my custom version of undo-tree that certain overlays in the buffer-undo-list also became non-existent and ended up looking like #<overlay in no buffer> as opposed to #<marker in no buffer>, so you may also need to play around with what circumstance the overlay information gets expunged and becomes ... in no buffer. Another forum participant will need to give you some additional, since I've never created these, and have only worked on dealing with the aftermath as it conflicts with prin1 functions that choke when encountering those specific examples. – lawlist Sep 21 '17 at 3:05
  • Thanks for the tip about the buffer-undo-list. It looks like (apply ...) is what I need to try. – John Kitchin Sep 21 '17 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.