Comments created via comment-dwim not detected as changes
betaprior opened this issue · 8 comments
To reproduce: mark a line and comment via M-x comment-dwim. It is expected that this will be the last change for goto-chg, however goto-chg ignores this action and keeps going to the latest change where actual typing took place.
I cannot reproduce from that information alone. Make a step by step repro, with helpful ASCII art showing positions of point, what you expect and what you got.
I cannot reproduce that with Emacs 26.3. On the master branch however (see the orange thing in the mode line) I can. Chances are that something on master broke this barely functional package. Here's my repro for both versions and the values of buffer-undo-list
, with 26.3 on top and master at the bottom:
As expected, there was a change on master, comment-dwim uses combine-change-calls
resulting in that funny undo-list
entry with undo--wrap-and-run-primitive-undo
. Its last element resembles the one we need, so I wrote a hack detecting such entries and replacing them with the last item's range. This is a terrible hack, but it seems to resolve your issue. Can you please confirm whether it works for you?
Now, if you really want to do me a favor, consider reporting a bug or starting a discussion on emacs-devel how this kind of usage can be better supported by Emacs because the undo list is definitely not made for other things than undoing. Otherwise I suspect a future Emacs release will kill off this package for good...
@wasamasa thank you, it looks like the fix works! But I think I'm out of my depth addressing this on emacs-devel, not knowing anything about how undo is supposed to work and what exactly they did to break the package. I am willing to testify that goto-chg is the only navigation package of the many I've tried that actually does its job predictably and intuitively, and it would be a terrible shame if it got broken upstream.
It's not about undo being wrong, it's about using undo-list
for non-undo things being a fundamental mismatch. The intention of undo-list
is to undo things, not to guess what the buffer positions of the related changes are without ever performing these undo steps (which is what this package tries to do). As soon as an undo-entry tells you to execute a particular function to perform an undo, this means you can no longer reliably guess the position before that change. In this particular case I've managed to do this as Emacs has been nice enough to store that information, but there's no guarantee that this will always be the case. Therefore I believe there's merit in a general discussion how a better approach would look like that doesn't rely on how undo information is stored for a buffer.
I encountered the same problem that goto-last-change
cannot jump to the location commented by comment-dwim-2
.
@wasamasa: can you help to check?
I'm using the newest comment-dwim-2
, version 1.4.3, released on 20210101.1820, and the newest goto-chg
, version 1.7.5, released on 20220107.1733.
This is not the same problem (comment-dwim is one thing, an external package another one). Create a new issue, provide all information (Emacs version is lacking), provide minimized reproduction instructions, then we'll talk.