all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joost Kremers <joostkremers@fastmail.fm>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'" <help-gnu-emacs@gnu.org>
Subject: Re: track-changes and undo
Date: Mon, 22 Apr 2024 23:41:01 +0200	[thread overview]
Message-ID: <86a5lloz2q.fsf@p200300d6272f172e0e35ca5d92eef483.dip0.t-ipconnect.de> (raw)
In-Reply-To: <jwvpluhmwgl.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 22 Apr 2024 08:38:14 -0400")

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



  reply	other threads:[~2024-04-22 21:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21  8:23 track-changes and undo Joost Kremers
2024-04-21 14:54 ` Stefan Monnier
2024-04-22  7:33   ` Joost Kremers
2024-04-22 12:38     ` Stefan Monnier
2024-04-22 21:41       ` Joost Kremers [this message]
2024-04-22 23:04         ` Stefan Monnier
2024-04-23  5:58           ` Eli Zaretskii
2024-04-23  7:06           ` Joost Kremers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86a5lloz2q.fsf@p200300d6272f172e0e35ca5d92eef483.dip0.t-ipconnect.de \
    --to=joostkremers@fastmail.fm \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.