weechat.el
weechat.el copied to clipboard
Undo
trafficstars
I use undo a lot, but when I use undo in weechat.el buffers, it often ends up undoing lines of chat. Of course, I can simply redo to bring them back again, but it seems like it shouldn't be possible at all.
A simple solution would be to just disable undo completely for all weechat buffers, but it seems like it should be possible to simply prevent Emacs from recording anything in the undo history. As noted here, that seems to be the case, however it does come with the caveat that doing this will cause any buffer positions in the undo list to be out of sync with the new content of the buffer.
For a solution, my thinking is:
- Don't disable undo completely
- When chat lines are inserted into the buffer, prevent them from being added to undo by using the trick linked above
- Manually update buffer positions in the undo to point them back to the correct locations. This seems like the trickiest part but it should just be a matter of adding the length of the inserted text to the positions in the undo-list. The Emacs manual even describes the undo-list structure here.
- When the user presses
RETto send a line of text, clear undo history so the buffer-undo-list-correcting-function in the previous step has less to process. We might as well do this anyway since obviously you can't undo text after you've sent it.