[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: track-changes and undo
From: |
Joost Kremers |
Subject: |
Re: track-changes and undo |
Date: |
Mon, 22 Apr 2024 23:41:01 +0200 |
User-agent: |
mu4e 1.12.2; emacs 29.3 |
On Mon, Apr 22 2024, Stefan Monnier wrote:
> The gain from `track-changes` is just to provide you with the "before"
> string for deletions so it takes care of reading it in
> `before-change-functions` and then providing it to you in the
> `after-change-functions` (with the advantage that it detects/handles the
> various corner cases where that pairing fails).
I think I'll try and see if I can make it work with the `:immediate` option.
It would of course mean that the buffer is modified inside
`after-change-functions`, which you warn against, but it looks like that's the
only way.
> One other thing that you might have trouble to reproduce with
> `track-changes` is the following test:
>
> (and (= beg (point-min)) (= end (point-max)))
>
> that you have in `cm-before-change`. I'm not completely sure what this
> is for, tho. Is it for `revert-buffer`?
I honestly don't remember... Based on the comment, it looks like
`switch-to-buffer` triggers `before-change-functions`, but a) that doesn't make
much sense; and b) the code seems to work just fine without that line. (I even
fired up a Vagrant box with an old Ubuntu release with Emacs 24, which would be
the most recent version when I wrote that code).
> [ I tend to do "destructive reads", so the patch below is the result of
> reading that part of your code. ]
Thanks.
> +(define-minor-mode cm-follow-changes ;FIXME: Shouldn't it end in `mode'?
> + "Minor mode to follow changes."
> + :global nil
> + (if cm-follow-changes
> + (progn
> + (add-hook 'before-change-functions #'cm-before-change t t)
> + (add-hook 'after-change-functions #'cm-after-change nil t))
> + (remove-hook 'before-change-functions #'cm-before-change t)
> + (remove-hook after-change-functions #'cm-after-change t)))
Making it a minor mode makes sense, of course. And don't ask me why I used
`add-to-list` instead of `add-hook`. 🤔
--
Joost Kremers
Life has its moments