all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments
@ 2018-07-25 16:17 Michał Kondraciuk
  2018-07-27 10:06 ` Eli Zaretskii
  2021-08-12 13:30 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: Michał Kondraciuk @ 2018-07-25 16:17 UTC (permalink / raw)
  To: 32278

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






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments
  2018-07-25 16:17 bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments Michał Kondraciuk
@ 2018-07-27 10:06 ` Eli Zaretskii
  2018-07-27 11:24   ` Michał Kondraciuk
  2021-08-12 13:30 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2018-07-27 10:06 UTC (permalink / raw)
  To: Michał Kondraciuk; +Cc: 32278

> From: Michał Kondraciuk <k.michal@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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments
  2018-07-27 10:06 ` Eli Zaretskii
@ 2018-07-27 11:24   ` Michał Kondraciuk
  2018-07-27 12:28     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Michał Kondraciuk @ 2018-07-27 11:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 32278

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)))))))))








^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments
  2018-07-27 11:24   ` Michał Kondraciuk
@ 2018-07-27 12:28     ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2018-07-27 12:28 UTC (permalink / raw)
  To: Michał Kondraciuk; +Cc: 32278

> Cc: 32278@debbugs.gnu.org
> From: Michał Kondraciuk <k.michal@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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments
  2018-07-25 16:17 bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments Michał Kondraciuk
  2018-07-27 10:06 ` Eli Zaretskii
@ 2021-08-12 13:30 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-12 13:30 UTC (permalink / raw)
  To: Michał Kondraciuk; +Cc: 32278

Michał Kondraciuk <k.michal@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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-12 13:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25 16:17 bug#32278: 27.0.50; replace-buffer-contents calls change functions with wrong arguments Michał Kondraciuk
2018-07-27 10:06 ` Eli Zaretskii
2018-07-27 11:24   ` Michał Kondraciuk
2018-07-27 12:28     ` Eli Zaretskii
2021-08-12 13:30 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.