help-gnu-emacs
[Top][All Lists]
Advanced

[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 09:33:47 +0200
User-agent: mu4e 1.12.2; emacs 29.3

Hi Stefan,

> Very interesting point.  Indeed, this is missing.
> Hmm... not completely sure how to expose that info through this new API.
> Maybe a concrete example would help figure out how to make that work.
> Do you remember how you used (or why you needed) `undo-in-progress`?

The short version: The package makes it easier to add CriticMarkup to a
document, i.e., markup to indicate additions, deletions, etc. There are
keybindings for the various markups (`{++...++}` for additions, `{--...--}` for
deletions, etc.).

The follow-changes mode tries to do that automatically: if you delete a word,
instead of actually deleting it, the word is enclosed in deletion markup.

What actually happens in the current implementation is that the text is deleted
(as per normal) and then reinserted in the buffer with deletion markup around it
(in a function in `after-change-functions`).

Similarly for an addition, instead of just inserting the new text, it is
inserted and enclosed in addition markup. That part happens in
`before-change-functions` in the current implementation.

Both hook functions start with `(unless undo-in-progress...)`, so when a change
is triggered by undo, they don't do anything special, and Emacs Does The
Right Thing. The Right Thing here being removing the mark-up, keeping the text
if the original action was a deletion and removing the text if the original
action was an addition. I assume the right thing happens because the changes
made to the buffer in the hook functions are recorded in the same change that
triggers the hooks.

It's probably easier to understand when you look at the code: 

https://github.com/joostkremers/criticmarkup-emacs/blob/master/cm-mode.el#L863

Hope this makes it clearer...

Joost



-- 
Joost Kremers
Life has its moments



reply via email to

[Prev in Thread] Current Thread [Next in Thread]