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

Previous Next

Package: emacs;

Reported by: Michał Kondraciuk <k.michal <at> zoho.com>

Date: Thu, 26 Jul 2018 12:06:02 UTC

Severity: normal

Found in version 27.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32278 in the body.
You can then email your comments to 32278 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32278; Package emacs. (Thu, 26 Jul 2018 12:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michał Kondraciuk <k.michal <at> zoho.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 26 Jul 2018 12:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michał Kondraciuk <k.michal <at> zoho.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; replace-buffer-contents calls change functions with wrong
 arguments
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.

Repository revision: c67407e7520a97a92737200bf559c48a927db470





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32278; Package emacs. (Fri, 27 Jul 2018 10:07:01 GMT) Full text and rfc822 format available.

Message #8 received at 32278 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michał Kondraciuk <k.michal <at> zoho.com>
Cc: 32278 <at> debbugs.gnu.org
Subject: Re: bug#32278: 27.0.50;
 replace-buffer-contents calls change functions with wrong arguments
Date: Fri, 27 Jul 2018 13:06:13 +0300
> From: Michał Kondraciuk <k.michal <at> zoho.com>
> 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 <at> gnu.org:
bug#32278; Package emacs. (Fri, 27 Jul 2018 11:26:01 GMT) Full text and rfc822 format available.

Message #11 received at 32278 <at> debbugs.gnu.org (full text, mbox):

From: Michał Kondraciuk <k.michal <at> zoho.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32278 <at> debbugs.gnu.org
Subject: Re: bug#32278: 27.0.50; replace-buffer-contents calls change
 functions with wrong arguments
Date: Fri, 27 Jul 2018 13:24:30 +0200
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 <at> gnu.org:
bug#32278; Package emacs. (Fri, 27 Jul 2018 12:30:02 GMT) Full text and rfc822 format available.

Message #14 received at 32278 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michał Kondraciuk <k.michal <at> zoho.com>
Cc: 32278 <at> debbugs.gnu.org
Subject: Re: bug#32278: 27.0.50; replace-buffer-contents calls change
 functions with wrong arguments
Date: Fri, 27 Jul 2018 15:28:57 +0300
> Cc: 32278 <at> debbugs.gnu.org
> From: Michał Kondraciuk <k.michal <at> zoho.com>
> Date: Fri, 27 Jul 2018 13:24:30 +0200
> 
> 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.

It looks so, yes.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32278; Package emacs. (Thu, 12 Aug 2021 13:31:02 GMT) Full text and rfc822 format available.

Message #17 received at 32278 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Michał Kondraciuk <k.michal <at> zoho.com>
Cc: 32278 <at> debbugs.gnu.org
Subject: Re: bug#32278: 27.0.50; replace-buffer-contents calls change
 functions with wrong arguments
Date: Thu, 12 Aug 2021 15:30:12 +0200
Michał Kondraciuk <k.michal <at> zoho.com> writes:

> Or maybe something like this:
>
>     before (1 4)
>     after (1 6 3)

Looks like Eli fixed this at the time (and then suggested that somebody
fix this in a possibly different way), but as far as I can tell, the fix
is fine (it works as expected on the current trunk), so I'm closing this
bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 32278 <at> debbugs.gnu.org and Michał Kondraciuk <k.michal <at> zoho.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 12 Aug 2021 13:31:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 10 Sep 2021 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 286 days ago.

Previous Next


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