emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unbalanced change hooks (part 2)


From: Alan Mackenzie
Subject: Re: Unbalanced change hooks (part 2)
Date: Mon, 1 Aug 2016 20:52:23 +0000
User-agent: Mutt/1.5.24 (2015-08-30)

Hello, Eli.

On Mon, Aug 01, 2016 at 10:39:03PM +0300, Eli Zaretskii wrote:
> > Date: Mon, 1 Aug 2016 17:15:52 +0000
> > Cc: address@hidden, address@hidden, address@hidden
> > From: Alan Mackenzie <address@hidden>

> > How about the following idea: we create a special purpose undo list
> > separate from the existing one.  Every change is recorded on this list,
> > regardless of whether or not main undo is disabled.  After each
> > invocation of after-change-functions the list is emptied.

> >     (defmacro with-change-undone (&rest forms) ...)

> > An after-change-function can invoke the macro `with-change-undone' which
> > would undo the changes, execute the &rest forms, then redo the changes.

> > Surely this would satisfy both of us, no?

> Sounds gross, but if this is the only way to solve this problem, and
> you can live with it, so can I.

> I do suggest to wait with conclusions for a while, perhaps a better
> idea will come up.

Slightly less gross, perhaps:
(i) Abandon the use of before-change-functions.
(ii) Enable undo in pre-command-hook, if necessary.
(iii) At each after-change-functions call:
  a - Analyze buffer-undo-list down as far as (or pos (next-nil)), and
    revert the insertion or deletion which as been made, taking
    particular care over coalesced multiple insertions/deletions.
  b - (setq pos (current-position-in-undo-list))
  c - Perform what used to be before-change actions.
  d - restore the insertion/deletion.
  e - Perform the normal after-change functions.
(iv) Disable undo in post-command-hook, if appropriate.

This is less gross in that it uses the standard undo list rather than
creating a new special purpose one.  It would also be usable in existing
Emacsen.  But I still say it would be preferable to have a function
`old-string' callable from after-change-functions rather than having to
mess around with the undo list in (ii), (iii)a, and (iv).

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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