Oops, accidentally hit send early (and with the wrong address): On Wed, Aug 8, 2018 at 11:02 AM Jason Felice <jason.m.fel...@gmail.com> wrote:
> On Wed, Aug 8, 2018 at 1:01 AM Bram Moolenaar <b...@moolenaar.net> wrote: > >> You mean that setline() now starts a new undoable change? Yeah, I've >> been wondering if that is a problem. Unfortunately it won't be easy to >> make this work, since edit() keeps its undo information locally, and >> other places making changes would need to access that to know what to >> do. > > So, I've tried a new work-around, but can't get this to work, either: Handle InsertEnter and InsertLeave, and record changenr() on InsertEnter. On InsertLeave, grab the contents of the buffer, undo back to the recorded changenr() and use setline() to replace the buffer. In theory, this should fork an undo branch that looks like we want it to and put us there. The first problem is that InsertEnter happens after the buffer has been changed for things like 'O'. I think I have a work-around here: if the recorded changenr() is the same on InsertEnter and the first TextChangedI, subtract one from it. The second problem is that I can't seem to reliably go to a change number. I'm not sure I understand why, but I think the clue is that `:undo N` says it goes to a change *after* N. Is there not a way to reliably go to a change number? If I try to subtract one from N, I get an error when I try to go to -1 for the first change in the buffer. If I handle the zero case specially with :undo 0 | undo, it works for that case, but the other cases still seem to go to the wrong place. I've looked at the comments at the top of undo.c, which tell me what the structures look like, but I think I need to know what invariants they have - what state are they kept in during insert and normal modes? Has anyone written anything about that? -Jason -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.