emacs-devel
[Top][All Lists]
Advanced

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

Re: disabling undo boundaries


From: Phillip Lord
Subject: Re: disabling undo boundaries
Date: Mon, 11 May 2015 12:46:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> I am wondering why the "nil" undo-boundaries get inserted when I change
>> *a different* buffer. This does not really make sense to me, and is
>> causing breakage in my package.
>
> The 3 separate undo entries you're seeing are actually the "normal"
> outcome (one undo-boundary per buffer-modifying command).
>
> self-insert-command has special ad-hoc code to try and merge sequences
> of single-char insertions by removing the previous undo-boundary.
> Which is why you normally only see a single undo entry.
>
> In your second case, I suspect that this ad-hoc code doesn't get to do
> what it's intended to do, because it does not recognize the
> undo-boundary that is candidate for removal as being "an undo-boundary
> we've auto-inserted".  So, self-insert-command thinks that this
> undo-boundary may have been inserted by an explicit call to
> `undo-boundary' at the end of the previous command, in which case it
> should not be removed.
>
> The relevant code is in the remove_excessive_undo_boundaries function,
> in src/cmds.c.


Unfortunately, this is a general problem. Try enabling the a-c-f I sent
previously, and then run "fill-paragraph" on an overly long line.


With after-change-hook disabled....

Now is the winter of our discontent made glorious summer by the sun over york, 
whether it is

M-q

Now is the winter of our discontent made glorious summer by the sun over york,
whether it is

C-/

Now is the winter of our discontent made glorious summer by the sun over york, 
whether it is


With after-change-hook enabled...

Now is the winter of our discontent made glorious summer by the sun over york, 
whether it is

M-q

Now is the winter of our discontent made glorious summer by the sun over york,
whether it is

C-/

Now is the winter of our discontent made glorious summer by the sun over york,
 whether it is

C-/

Now is the winter of our discontent made glorious summer by the sun over york,
whether it is

So, I have to do two undo's rather than one.

The problem seems to come from here in record_point, in undo.c


  if ((current_buffer != last_undo_buffer)
      /* Don't call Fundo_boundary for the first change.  Otherwise we
         risk overwriting last_boundary_position in Fundo_boundary with
         PT of the current buffer and as a consequence not insert an
         undo boundary because last_boundary_position will equal pt in
         the test at the end of the present function (Bug#731).  */
      && (MODIFF > SAVE_MODIFF))
    Fundo_boundary ();
  last_undo_buffer = current_buffer;


The a-c-f call causes an undo-able in scratch which means that
"current-buffer != last_undo_buffer" succeeds, which forces an
Fundo_boundary call on the NEXT call to record_point which is why I
cannot see this boundary on a-c-f.

The best thing that I can think of at the moment is to use
post-command-hook to clean up the excessive undo-boundaries, but I am
not sure how I am going to work out which ones are "real" and which ones
not. The obvious solution (delete all those adding since the last
command) will fail for both self-insert-command's logic and anywhere
else that undo-boundary has been explicitly called.

Better ideas welcome.

Phil



reply via email to

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