GNU bug report logs - #32278
27.0.50; replace-buffer-contents calls change functions with wrong arguments

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Michał Kondraciuk <k.michal@HIDDEN>; dated Thu, 26 Jul 2018 12:06:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 32278 <at> debbugs.gnu.org:


Received: (at 32278) by debbugs.gnu.org; 27 Jul 2018 11:25:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jul 27 07:25:05 2018
Received: from localhost ([127.0.0.1]:59651 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1fj0ro-0000Nv-RD
	for submit <at> debbugs.gnu.org; Fri, 27 Jul 2018 07:25:05 -0400
Received: from sender-pp-092.zoho.com ([135.84.80.237]:25308)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <k.michal@HIDDEN>) id 1fj0rm-0000NM-CC
 for 32278 <at> debbugs.gnu.org; Fri, 27 Jul 2018 07:25:02 -0400
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; 
 h=subject:to:cc:references:from:message-id:date:user-agent:mime-version:in-reply-to:content-type;
 b=Rocny5DhaBnWCrIffa2Lv5WakclQbzjkCh9uOQE8msMcfTb/MOsG+HEmnFpuiZ01CQLRQSkHrJ+j
 emr5SjqR2UXriIArTrxbz9xwKTR8iNlRjqVYIkxtWkJu45MxZM96  
Received: from [192.168.0.87] (84-10-171-192.static.chello.pl [84.10.171.192])
 by mx.zohomail.com with SMTPS id 1532690675853797.294481800686;
 Fri, 27 Jul 2018 04:24:35 -0700 (PDT)
Subject: Re: bug#32278: 27.0.50; replace-buffer-contents calls change
 functions with wrong arguments
To: Eli Zaretskii <eliz@HIDDEN>
References: <96205085-151d-5021-d0bc-44b22df363cf@HIDDEN>
 <83in51ro16.fsf@HIDDEN>
From: =?UTF-8?Q?Micha=c5=82_Kondraciuk?= <k.michal@HIDDEN>
Message-ID: <1ef81ec1-855d-50fe-e96f-4b3059b6dba6@HIDDEN>
Date: Fri, 27 Jul 2018 13:24:30 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.9.1
MIME-Version: 1.0
In-Reply-To: <83in51ro16.fsf@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-ZohoMailClient: External
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 32278
Cc: 32278 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On 07/27/2018 12:06 PM, Eli Zaretskii wrote:
> Thanks.  I just threw away the attempt to be smarter about where the
> changes are done, and went back to the original code that announces
> changes in the entire region.
> 
> If anyone wants to add smarter code, they should do this on master.

Thanks. Can you tell me if the workaround below (calling change functions manually) is 
correct/safe for emacs versions where this is not fixed? It's a function that 
non-destructively replaces region contents.

(defun my-replace-region (beg end text)
   "Replace region BEG END with TEXT.
As far as possible the replacement is non-destructive."
   (let ((source (current-buffer)))
     (with-temp-buffer
       (insert text)
       (let ((replacement (current-buffer)))
         (with-current-buffer source
           (save-restriction
             (widen)
             (narrow-to-region beg end)
             (let ((inhibit-modification-hooks t))
               (run-hook-with-args 'before-change-functions beg end)
               (replace-buffer-contents replacement)
               (run-hook-with-args 'after-change-functions beg
                                   (+ beg (length text)) (- end beg)))))))))







Information forwarded to bug-gnu-emacs@HIDDEN:
bug#32278; Package emacs. Full text available.

Message received at 32278 <at> debbugs.gnu.org:


Received: (at 32278) by debbugs.gnu.org; 27 Jul 2018 10:06:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jul 27 06:06:24 2018
Received: from localhost ([127.0.0.1]:59592 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1fizdg-0006rL-0M
	for submit <at> debbugs.gnu.org; Fri, 27 Jul 2018 06:06:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:41361)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1fizde-0006r9-HM
 for 32278 <at> debbugs.gnu.org; Fri, 27 Jul 2018 06:06:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1fizdW-0000Nw-4n
 for 32278 <at> debbugs.gnu.org; Fri, 27 Jul 2018 06:06:17 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:48760)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1fizdW-0000NY-1R; Fri, 27 Jul 2018 06:06:14 -0400
Received: from [176.228.60.248] (port=2060 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1fizdV-0000bI-54; Fri, 27 Jul 2018 06:06:13 -0400
Date: Fri, 27 Jul 2018 13:06:13 +0300
Message-Id: <83in51ro16.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: =?utf-8?Q?Micha=C5=82?= Kondraciuk <k.michal@HIDDEN>
In-reply-to: <96205085-151d-5021-d0bc-44b22df363cf@HIDDEN> (message from
 =?utf-8?Q?Micha=C5=82?= Kondraciuk on Wed, 25 Jul 2018 18:17:53 +0200)
Subject: Re: bug#32278: 27.0.50;
 replace-buffer-contents calls change functions with wrong arguments
References: <96205085-151d-5021-d0bc-44b22df363cf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2001:4830:134:3::e
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: 32278
Cc: 32278 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

> From: Michał Kondraciuk <k.michal@HIDDEN>
> Date: Wed, 25 Jul 2018 18:17:53 +0200
> 
> When I evaluate the sexp below in emacs -Q, I get unexpected arguments
> passed to change functions.
> 
>      (with-current-buffer "*scratch*"
>        (erase-buffer)
>        (insert "foo")
> 
>        (add-hook 'before-change-functions
>                  (lambda (&rest args) (message "before %s" args)) nil t)
>        (add-hook 'after-change-functions
>                  (lambda (&rest args) (message "after %s" args)) nil t)
> 
>        (with-temp-buffer
>          (insert "ffooo")
>          (let ((replacement (current-buffer)))
>            (with-current-buffer "*scratch*"
>              (replace-buffer-contents replacement)))))
> 
> The only messages I get are:
> 
>      before (4 4)
>      after (4 6 0)
> 
> I would expect something like:
> 
>      before (1 1)  ;before inserting f in front
>      after (1 2 0) ;after inserting f in front
>      before (5 5)  ;before inserting o at the end
>      after (5 6 0) ;after inserting o at the end
> 
> Or maybe something like this:
> 
>      before (1 4)
>      after (1 6 3)
> 
> Or anything else that would allow me to incrementally build a buffer
> with the same contents as source buffer using just change functions.

Thanks.  I just threw away the attempt to be smarter about where the
changes are done, and went back to the original code that announces
changes in the entire region.

If anyone wants to add smarter code, they should do this on master.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#32278; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 26 Jul 2018 12:05:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 26 08:05:03 2018
Received: from localhost ([127.0.0.1]:58439 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1fif0w-0002tz-R8
	for submit <at> debbugs.gnu.org; Thu, 26 Jul 2018 08:05:03 -0400
Received: from eggs.gnu.org ([208.118.235.92]:41305)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <k.michal@HIDDEN>) id 1fif0t-0002tR-Fb
 for submit <at> debbugs.gnu.org; Thu, 26 Jul 2018 08:04:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <k.michal@HIDDEN>) id 1fif0l-0000Od-G9
 for submit <at> debbugs.gnu.org; Thu, 26 Jul 2018 08:04:54 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:43919)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <k.michal@HIDDEN>) id 1fif0l-0000OL-CL
 for submit <at> debbugs.gnu.org; Thu, 26 Jul 2018 08:04:51 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60492)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <k.michal@HIDDEN>) id 1fif0i-0003Qj-4H
 for bug-gnu-emacs@HIDDEN; Thu, 26 Jul 2018 08:04:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <k.michal@HIDDEN>) id 1fif0f-0000Fb-3v
 for bug-gnu-emacs@HIDDEN; Thu, 26 Jul 2018 08:04:48 -0400
Received: from sender-pp-092.zoho.com ([135.84.80.237]:25446)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <k.michal@HIDDEN>) id 1fif0e-000094-R7
 for bug-gnu-emacs@HIDDEN; Thu, 26 Jul 2018 08:04:45 -0400
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; 
 h=to:from:subject:message-id:date:user-agent:mime-version:content-type; 
 b=dv3Z4s/GrlJXk7tpHjglW4TWLfwLRiWlTrQ+y/I6ZTn/VKzH6kxJ6d9wq8YXOjlvbd6E81NyhBCN
 6BeREtobDzH30NsRBtG/uyufKekvToPDB2IHMWIIiSpwZtOzHAJe  
Received: from [192.168.0.87] (84-10-171-192.static.chello.pl [84.10.171.192])
 by mx.zohomail.com with SMTPS id 1532535476116915.2593914125774;
 Wed, 25 Jul 2018 09:17:56 -0700 (PDT)
To: bug-gnu-emacs@HIDDEN
From: =?UTF-8?Q?Micha=c5=82_Kondraciuk?= <k.michal@HIDDEN>
Subject: 27.0.50; replace-buffer-contents calls change functions with wrong
 arguments
Message-ID: <96205085-151d-5021-d0bc-44b22df363cf@HIDDEN>
Date: Wed, 25 Jul 2018 18:17:53 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.9.1
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-ZohoMailClient: External
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

When I evaluate the sexp below in emacs -Q, I get unexpected arguments
passed to change functions.

     (with-current-buffer "*scratch*"
       (erase-buffer)
       (insert "foo")

       (add-hook 'before-change-functions
                 (lambda (&rest args) (message "before %s" args)) nil t)
       (add-hook 'after-change-functions
                 (lambda (&rest args) (message "after %s" args)) nil t)

       (with-temp-buffer
         (insert "ffooo")
         (let ((replacement (current-buffer)))
           (with-current-buffer "*scratch*"
             (replace-buffer-contents replacement)))))

The only messages I get are:

     before (4 4)
     after (4 6 0)

I would expect something like:

     before (1 1)  ;before inserting f in front
     after (1 2 0) ;after inserting f in front
     before (5 5)  ;before inserting o at the end
     after (5 6 0) ;after inserting o at the end

Or maybe something like this:

     before (1 4)
     after (1 6 3)

Or anything else that would allow me to incrementally build a buffer
with the same contents as source buffer using just change functions.

Repository revision: c67407e7520a97a92737200bf559c48a927db470





Acknowledgement sent to Michał Kondraciuk <k.michal@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#32278; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 27 Jul 2018 11:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.