Subject: Re: bug#23906: 25.0.95; Undo boundary after process output is not consistent

From: Stefan Monnier <[email-masked]>
Date: Tue, 12 Jul 2016 17:20:47 -0400

> Yes, I also understood it this way. Just to clearify: Eventually, there
> actually must be a %@ as real text in the buffer, because otherwise what
> the Prolog process emits will make the buffer no longer a valid Prolog
> program. So, what the Prolog process emits must not only *appear* as
> "commented out" in the buffer, but must actually *be* commented out.

Yes, but the real "%@" will only be inserted into the buffer when actual
process output comes along (which you already do anyway, IIUC).

> A text property may get us over the initial %@ until process output
> arrives, but at that point we will have to actually insert %@ into the
> buffer, so that the query result does not interfere with the program
> when users save it, or simply reconsult the buffer plus answer.

That's right.

> This is certainly doable, but not sufficient. An interaction with the
> Prolog process can span several answers and even involve user input, and
> I want all this to be removed again on undo. Please see below for more.

Hmm... So are you saying that you want a single undo step to undo
something that corresponds to "some process output plus some user
input"?  This seems incompatible with the desire you expressed earlier
to insert undo-boundaries whenever the user actually inserts
something in the buffer (or did I misunderstand it?):

    Please note in this case that, as explained above, the output
    normally is inserted continuously in a loop, but it is possible to
    break out of the loop with C-g and edit text elsewhere in the
    buffer, and in that case I still would like the normal undo
    behaviour for user input.

Tho I guess you might be able to distinguish the two cases based on the C-g.
Hmm... probably doable, but sounds delicate.

> And for such smaller peeks at the current results, I frequently need to
> undo the whole interaction, and it is valuable during develpoment that
> undo is extremely consistent in what it does. It is irritating to
> always use C-/ for undo, except for 1 out of 10 times in such cases.

So it's not absolutely indispensable, but it's indeed more annoying than
in the "usual" comint case because undo is used more often and even
repeatedly, so predictability is more important than usual.
I see, makes sense.

>> Using Viper's approach, you could for example throw away the
>> undo-boundaries added since the last process-send-string.  I'd expect
>> you'd do it right when you see Prolog's prompt.  So if you undo while
>> Prolog is still in the middle of responding you might only undo parts of
>> the current response (like now), but once a response is complete it will
>> always be undone as an indivisible step.
> This sounds like a great approach, thank you! I will try this.

In case you haven't found it yet, "grep undo-boundary
lisp/emulation/viper*.el" gets you straight to the relevant code (in
emacs-25 or more recent).  Maybe we should add some support in some
"core" file (subr.el or something) for that operation.

        Stefan