unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Allen Li <vianchielfaura@gmail.com>
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: 29118@debbugs.gnu.org, Barry OReilly <gundaetiapo@gmail.com>,
	Stefan <monnier@iro.umontreal.ca>
Subject: bug#29118: 25.2.50; Undoing shell flush output results in weird state
Date: Mon, 13 Nov 2017 00:29:10 -0800	[thread overview]
Message-ID: <CAJr1M6e4GE8CvUvLWE_bKR9b5oMnAQscEAZgCd4m=kFg1BkKoA@mail.gmail.com> (raw)
In-Reply-To: <8760af2vup.fsf@users.sourceforge.net>

On Sun, Nov 12, 2017 at 10:30 AM, Noam Postavsky
<npostavs@users.sourceforge.net> wrote:
> Hmm, as far as I can tell, in this case the text was inserted on the
> "normal" side of the marker, but then the marker is moved afterwards.
> So I'm not sure if such tracking would help.
>
>     (defun comint-output-filter (process string)
>        ...
>             ;; insert-before-markers is a bad thing. XXX
>             ;; Luckily we don't have to use it any more, we use
>             ;; window-point-insertion-type instead.
>             (insert string)
>
>             ;; Advance process-mark
>             (set-marker (process-mark process) (point))
>
>
> However, while looking at the undo code, I noticed that it checks for
> valid marker adjustments by checking that the marker position is the
> same as the POSITION of the deletion record.  However, for a negative
> POSITION (indicating text was at the end of the deleted text) this
> comparison will always be false (markers can't have negative positions).

I was mistaken, undo does track marker movement correctly; or mostly
correctly, excluding this bug.

>
>   (defun primitive-undo (n list)
>     ...
>             (`(,(and string (pred stringp)) . ,(and pos (pred integerp)))
>                    ...
>                    (and (eq (marker-buffer m) (current-buffer))
>                         (= pos m) ; <<<<<<<<<<<< Always nil for negative `pos'
>                         (push marker-adj valid-marker-adjustments))))
>
> I don't see why the position of point should affect the adjustment of
> other markers.  This seems to have been added by [1: 37ea8275f7] to fix
> Bug#16818.  Before that, if I understand correctly, all marker
> adjustments were applied without checking location at all.  And indeed,
> this bug does not occur in Emacs 24.3.

I agree with your analysis.  The intent of the code is to make sure that
the marker hasn't been moved from the original location before trying to
restore it.  In that case, comparing against the absolute value of pos
makes sense, as we use the sign to carry extra information in band that
is not relevant to the marker adjustment.

> So I would suggest the following patch, which does seem to actually fix
> this bug.  It might break some other things though; I have not tested it
> apart from the scenario in this bug.  I'm adding the participants of
> Bug#16818 to Cc, in the hope they might have some more insight.
>
> --- i/lisp/simple.el
> +++ w/lisp/simple.el
> @@ -2579,7 +2579,7 @@ primitive-undo
>                 (let* ((marker-adj (pop list))
>                        (m (car marker-adj)))
>                   (and (eq (marker-buffer m) (current-buffer))
> -                      (= pos m)
> +                      (= (abs pos) m)
>                        (push marker-adj valid-marker-adjustments))))
>               ;; Insert string and adjust point
>               (if (< pos 0)
>
> [1: 37ea8275f7]: 2014-03-24 22:47:39 -0400
>   Undo in region after markers in undo history relocated
>   https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=37ea8275f7faad1192ddaba9f4a0789580675e17

I have added this to my trusty personal monkeypatch library.  I can
confirm that it fixes the current bug.  I can use this patch for a while
and see if I run into any obvious issues.  The patch seems quite
straightforward and correct, but perhaps I am naive.





  reply	other threads:[~2017-11-13  8:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 21:25 bug#29118: 25.2.50; Undoing shell flush output results in weird state Allen Li
2017-11-10  1:26 ` Noam Postavsky
2017-11-10  8:10   ` Eli Zaretskii
2017-11-12  2:12     ` Noam Postavsky
2017-11-12  4:47       ` Eli Zaretskii
2017-11-26 19:59       ` bug#29461: Wishlist: better facilities for debugging undo problems Noam Postavsky
2017-11-11  7:20   ` bug#29118: 25.2.50; Undoing shell flush output results in weird state Allen Li
2017-11-12 18:30     ` Noam Postavsky
2017-11-13  8:29       ` Allen Li [this message]
2017-11-13 13:26       ` Stefan Monnier
2017-11-15 13:05         ` Noam Postavsky

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJr1M6e4GE8CvUvLWE_bKR9b5oMnAQscEAZgCd4m=kFg1BkKoA@mail.gmail.com' \
    --to=vianchielfaura@gmail.com \
    --cc=29118@debbugs.gnu.org \
    --cc=gundaetiapo@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=npostavs@users.sourceforge.net \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).