[Top][All Lists]

[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 17:31:27 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> 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;
> Oh, I think you're right, this is even more likely the reason for
> those boundaries.

I'm getting slower better at reading Emacs source code:-) I really need
to bite the bullet and learn C.

>> 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.
> Indeed, removing those boundaries after the fact seems
> difficult/tricky/risky.
> I'm not sure exactly what are your design constraints,

I am trying to address a bug in lentic (available in all good
repositories!). Lentic picks up the change in one buffer on the a-c-f
and percolates it too another (or potentially any number of others).

> but I can see a few alternatives: - disable undo in the "other buffer"
> (*scratch* in your example, tho I suspect it's a different buffer in
> your real case).

This fails for me, unfortunately, the user might want to undo in the
other buffer. A priori, though, it seems to be a nice idea. I tried this
code for instance:

#+BEGIN_SRC emacs-lisp
  (defvar-local fix-test-on nil)
  (defun fix-test-after-change-function (&rest _)
    (when fix-test-on
      (let (
            (undo-inhibit-record-point t)
            (get-buffer "*scratch*")
          (insert "a")))))

  (add-hook 'after-change-functions 'fix-test-after-change-function)

And that doesn't have the problem because the inhibit stops record_point
from ever setting the undo_boundary.

> - delay the modification of the other buffer (e.g. record in a-c-f the
>   boundaries of the affected text, and process them later from
>   post-command-hook).  Not sure if this would really help.

Unfortunately that wont work since there there can be many changes on
a-c-f for a single p-c-h call. So, I'd have to amalgamate all the

> - change your a-c-f so it records the buffer-undo-list at the beginning,
>   and it removes the added boundary (if any) at the end.

The a-c-f doesn't work, unfortunately because the nil boundary is not
present till sometime after the a-c-f has been called (when? not sure).

I did think of doing this with the pre/post-command-hook -- so, take the
car of the b-u-l on the pre-c-h, then on the post-c-h, scan till I get
to the old car and delete all nils placed there.

I can see a few problems with this. First, it will also remove any
undo-boundaries added by explict calls to undo-boundary; perhaps not a
huge problem as there do not appear to be that many of them in the lisp
code base. Second, it's still not going to work for self-insert-command
because each of these are independent commands. Third, I seem to be
reimplementing the undo system which feels ugly.

Still, at the moment, this appears to be my only way forward.


reply via email to

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