GNU bug report logs - #77607
31.0.50; replace-region-contents moves point

Previous Next

Package: emacs;

Reported by: "Paul D. Nelson" <ultrono <at> gmail.com>

Date: Mon, 7 Apr 2025 12:10:02 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#77607: closed (31.0.50; replace-region-contents moves point)
Date: Mon, 07 Apr 2025 15:55:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 07 Apr 2025 11:54:22 -0400
with message-id <jwvecy4nf2h.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#77607: 31.0.50; replace-region-contents moves point
has caused the debbugs.gnu.org bug report #77607,
regarding 31.0.50; replace-region-contents moves point
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
77607: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77607
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: "Paul D. Nelson" <ultrono <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; replace-region-contents moves point
Date: Mon, 07 Apr 2025 14:09:12 +0200
The info docs for replace-region-contents say that it attempts to
preserve point.  With the latest update, it fails to preserve point in
cases where it did before.  I fixed my use case with save-excursion, and
the docs are vague enough that this issue might not qualify as a bug,
but I figured I'd report it just in case it was unintentional, or in
case others come across it.

For example:

(with-temp-buffer
  (insert "abc")
  (replace-region-contents (- (point) 3) (- (point) 2) (lambda () "A"))
  (char-to-string (char-before)))

now returns "A", but I believe that it previously returned "c".


In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin24.1.0, NS
 appkit-2575.20 Version 15.1.1 (Build 24B91)) of 2025-04-06 built on
 d51735
Repository revision: 8ae7224b8fae59229b186853b300822bd70a8ec4
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2575
System Description:  macOS 15.1.1

Configured using:
 'configure --with-ns --with-native-compilation --with-tree-sitter
 --with-gif --with-png --with-jpeg --with-rsvg --with-tiff
 --with-imagemagick --with-x-toolkit=gtk3 --with-xwidgets'

Configured features:
ACL DBUS GLIB GNUTLS IMAGEMAGICK LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XIM XWIDGETS ZLIB

Important settings:
  value of $LC_CTYPE: UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  savehist-mode: t
  recentf-mode: t
  repeat-mode: t
  display-time-mode: t
  save-place-mode: t
  global-auto-revert-mode: t
  minibuffer-depth-indicate-mode: t
  electric-pair-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-history-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config
gnus-util text-property-search mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils thingatpt llm vc-git diff-mode
track-changes files-x vc-dispatcher foldout noutline outline imenu
dired-aux hl-line dired dired-loaddefs time-date pcase savehist recentf
tree-widget repeat time saveplace autorevert filenotify mb-depth
elec-pair comp comp-cstr warnings subr-x comp-run comp-common rx edmacro
kmacro byte-opt cl-macs gv cl-extra help-mode use-package-bind-key
bind-key easy-mmode use-package-ensure cl-seq use-package-core bytecomp
byte-compile cus-edit pp cus-start cus-load icons wid-edit cl-loaddefs
cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads xwidget-internal dbusbind
kqueue cocoa ns lcms2 multi-tty make-network-process tty-child-frames
native-compile emacs)

Memory information:
((conses 16 201000 24284) (symbols 48 23072 1) (strings 32 56478 4127)
 (string-bytes 1 1440313) (vectors 16 25713)
 (vector-slots 8 1044292 203938) (floats 8 70 20)
 (intervals 56 1876 41) (buffers 992 17))


[Message part 3 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 77607-done <at> debbugs.gnu.org, "Paul D. Nelson" <ultrono <at> gmail.com>
Subject: Re: bug#77607: 31.0.50; replace-region-contents moves point
Date: Mon, 07 Apr 2025 11:54:22 -0400
>>> (with-temp-buffer
>>>   (insert "abc")
>>>   (replace-region-contents (- (point) 3) (- (point) 2) (lambda () "A"))
>>>   (char-to-string (char-before)))
>>>
>>> now returns "A", but I believe that it previously returned "c".

I installed the patch below which should fix it.


        Stefan


diff --git a/src/editfns.c b/src/editfns.c
index 9590b49dc25..669d3cdb140 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1968,6 +1968,7 @@ DEFUN ("replace-region-contents", Freplace_region_contents,
   if (FUNCTIONP (source))
     {
       specpdl_ref count = SPECPDL_INDEX ();
+      record_unwind_protect_excursion ();
       record_unwind_protect (save_restriction_restore,
 			     save_restriction_save ());
       Fnarrow_to_region (beg, end);
@@ -2119,7 +2120,6 @@ DEFUN ("replace-region-contents", Freplace_region_contents,
 
   Fundo_boundary ();
   bool modification_hooks_inhibited = false;
-  record_unwind_protect_excursion ();
 
   /* We are going to make a lot of small modifications, and having the
      modification hooks called for each of them will slow us down.



This bug report was last modified 43 days ago.

Previous Next


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