all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: phillip.lord@newcastle.ac.uk (Phillip Lord)
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: disabling undo boundaries
Date: Mon, 11 May 2015 17:31:27 +0100	[thread overview]
Message-ID: <87h9rjhy8w.fsf@newcastle.ac.uk> (raw)
In-Reply-To: <jwv4mnj2nxm.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 11 May 2015 10:45:49 -0400")

Stefan Monnier <monnier@iro.umontreal.ca> 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)
            )
        (with-current-buffer
            (get-buffer "*scratch*")
          (insert "a")))))

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

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
changes.


> - 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.

Phil



  reply	other threads:[~2015-05-11 16:31 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-10 21:43 disabling undo boundaries Phillip Lord
2015-05-11  1:42 ` Stefan Monnier
2015-05-11 11:46   ` Phillip Lord
2015-05-11 14:45     ` Stefan Monnier
2015-05-11 16:31       ` Phillip Lord [this message]
2015-05-11 19:30         ` Stefan Monnier
2015-05-11 20:42           ` Phillip Lord
2015-05-11 22:23             ` Stefan Monnier
2015-05-12 11:52               ` Phillip Lord
2015-05-12 20:15                 ` Stefan Monnier
2015-05-12 20:59                   ` Phillip Lord
2015-05-13 12:32                     ` Stefan Monnier
2015-05-13 15:40                       ` Phillip Lord
2015-05-14 15:28                         ` Stefan Monnier
2015-05-15 12:27                           ` Phillip Lord
2015-05-15 18:08                             ` Stefan Monnier
2015-05-15 19:49                               ` Phillip Lord
2015-05-15 23:45                                 ` Stefan Monnier
2015-05-16 13:31                                   ` Phillip Lord
2015-05-19 11:59                                     ` Phillip Lord
2015-05-19 19:42                                       ` Stefan Monnier
2015-05-19 21:48                                         ` Phillip Lord
2015-05-20  2:00                                           ` Stefan Monnier
2015-05-20  7:45                                             ` Phillip Lord
2015-05-20 12:53                                               ` Stefan Monnier
2015-05-21 11:15                                                 ` Phillip Lord
2015-05-21 15:44                                                   ` Stefan Monnier
2015-05-21 17:03                                                     ` Phillip Lord
2015-05-27 11:46                                                       ` Phillip Lord
2015-06-29  0:46                                                         ` Stefan Monnier
2015-08-04 14:18                                                           ` Phillip Lord
2015-08-06 21:02                                                             ` Phillip Lord
2015-08-06 22:20                                                             ` Stefan Monnier
2015-08-07 13:40                                                               ` Phillip Lord
2015-08-07 13:59                                                                 ` David Kastrup
2015-08-07 21:10                                                                   ` Phillip Lord
2015-08-08  5:39                                                                     ` David Kastrup
2015-08-08  9:58                                                                       ` Phillip Lord
2015-08-07 17:10                                                                 ` Stefan Monnier
2015-08-08 21:28                                                                   ` Stefan Monnier
2015-08-09 15:39                                                                     ` Phillip Lord
2015-08-09 16:30                                                                       ` Stefan Monnier
2015-08-09 16:50                                                                         ` Phillip Lord
2015-08-09 17:40                                                                           ` Stefan Monnier
2015-08-10  9:27                                                                             ` Phillip Lord
2015-08-10 21:21                                                                               ` Phillip Lord
2015-08-12 21:15                                                                               ` Stefan Monnier
2015-08-12 22:34                                                                                 ` Phillip Lord
2015-08-13  2:23                                                                                   ` Stefan Monnier
2015-08-21  9:40                                                                                     ` Phillip Lord
2015-08-07 23:49                                                     ` Davis Herring
2015-08-08 10:01                                                       ` Phillip Lord

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=87h9rjhy8w.fsf@newcastle.ac.uk \
    --to=phillip.lord@newcastle.ac.uk \
    --cc=emacs-devel@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.