From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#29118: 25.2.50; Undoing shell flush output results in weird state Date: Sun, 12 Nov 2017 13:30:22 -0500 Message-ID: <8760af2vup.fsf@users.sourceforge.net> References: <878tfe53fm.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1510511477 20713 195.159.176.226 (12 Nov 2017 18:31:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Nov 2017 18:31:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: 29118@debbugs.gnu.org, Barry OReilly , Stefan To: Allen Li Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 12 19:31:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDx2B-0004md-KP for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Nov 2017 19:31:07 +0100 Original-Received: from localhost ([::1]:50950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDx2H-0008O5-Gi for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Nov 2017 13:31:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDx2B-0008NY-Do for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 13:31:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDx26-0005xB-Ga for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 13:31:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56709) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDx26-0005x7-BU for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 13:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eDx26-00013w-2n for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 13:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Nov 2017 18:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29118 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 29118-submit@debbugs.gnu.org id=B29118.15105114344045 (code B ref 29118); Sun, 12 Nov 2017 18:31:02 +0000 Original-Received: (at 29118) by debbugs.gnu.org; 12 Nov 2017 18:30:34 +0000 Original-Received: from localhost ([127.0.0.1]:37157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDx1d-000136-Tq for submit@debbugs.gnu.org; Sun, 12 Nov 2017 13:30:34 -0500 Original-Received: from mail-io0-f196.google.com ([209.85.223.196]:52188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDx1a-00012m-K8; Sun, 12 Nov 2017 13:30:30 -0500 Original-Received: by mail-io0-f196.google.com with SMTP id g73so2776911ioj.8; Sun, 12 Nov 2017 10:30:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=vKdBGU+jACw0yEqaH2PJfYgttSGzU0QbW3h/ZTydcjw=; b=o4JILL5OVKkZNag2OcB2L9AZBUexVWEKprZiMNBFT7UgfeCEooQsoLZKORHUuz9QJf L/eFUBichQ3N0ItY7tnG6ioKzExOsb6IP9w2D2YzU+jQsZm5Hc4fR5+3Jzhm2ZJwpGHa 57DLykT21fexFkBLNAawiuGr1daTAcWxXUnFTYOlC59q5BJMxWkygNRs2zv7EwWEzIwk tCTqDWJEBVwIhxrtkFp2BBlU5921MiSTEGZ7/ayBfvhlawOgCJWp6EFAAmpdAo5xpidj 6YmGUQ8AeN7rl5iuJbZ9Tt4EHK182CfSTFlnGXwSPdVLNXLGLp+/msF3XAZ9hEy5JkhS WUJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=vKdBGU+jACw0yEqaH2PJfYgttSGzU0QbW3h/ZTydcjw=; b=dDv623JByMgDycI4UfNvG7SUAsxbstHolf0JrBM2X/35IqgQjkW0wQI2TKbwdgcZI5 3nMxuqbicGip93IgzPisTbkJXkN1IHAbyndycGZfLx2e7+bWGCFUxUJRzytS033G+Z7f 2LvEsoH2CoSIpN/cABSzoTk0ooPLKkyUTHmfkDwpcvD4N7BOBCIAp9GRx6p6mrgCcFbV LxpQd+yd6RF4pHK1sO8ncpOGU49ayIqwH2piX6/Xs9OeVeRiDb9ANCWjFOSwTbD6N5ze AZRX3uSO27nasYRaYPo40OW9zTk+iWdqVJwMvjTp4J4yTlBPQOKqyVbVHOVhNfM94Tng gc3Q== X-Gm-Message-State: AJaThX4bTXOj3CvUTDCHOnaLq30unttUx1A2ZGXI6DMqXH4ACD6uX0if u1ZqI/89jrd6oHVNn0VoxwBpSA== X-Google-Smtp-Source: AGs4zMZLcoKUxza7chS43gQz2vy1Ygqvb8P5WuxdtI8jdeiVA0jHVaDoRDdOWurWXg6q0NnpPp2z8A== X-Received: by 10.107.102.13 with SMTP id a13mr7538698ioc.185.1510511424486; Sun, 12 Nov 2017 10:30:24 -0800 (PST) Original-Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id b185sm6867509ioa.24.2017.11.12.10.30.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 12 Nov 2017 10:30:23 -0800 (PST) In-Reply-To: (Allen Li's message of "Fri, 10 Nov 2017 23:20:36 -0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:139810 Archived-At: found 29118 24.4 quit Allen Li writes: > 2. Changing the process-mark insertion type before undoing prevents the bug: > > (set-marker-insertion-type (process-mark (get-buffer-process > (current-buffer))) t) Ah, interesting. > However, you need to set it back to nil after undoing or all user > input will get inserted before process-mark. > > So one way to fix this would be to define a comint-undo that sets and > resets the process-mark insertion type. > That's probably not the most elegant solution. > > I think undo in general does not behave well with markers. undo will > always rely on the insertion type of the markers, > whereas the text to re-insert may well have been on either side of the marker. > > Perhaps undo should be improved to track which side of a marker > deleted text was at. 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). (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. 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