From: Ren Victor <victorhge@gmail.com>
To: 42424@debbugs.gnu.org
Subject: bug#42424: 27.0.90; replace-match: point is NOT left at the end of replacement
Date: Sun, 19 Jul 2020 13:50:51 +0800 [thread overview]
Message-ID: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 4485 bytes --]
I attach an ert case to show the recipe.
This issue happens when modification hooks modify the text before the
end of replacement text.
`replace-match' calls `replace_range' to do the actual replacement,
which can trigger modification hooks. Before calling `replace_range',
the position of the end of replacement is saved. After `replace_range',
the point is moved to the saved position.
But the end of replacement might be changed inside of
`replace_range'. So the final movement of point may end up to a wrong
place.
Other types of modification (insert or delete) do not have this issue.
`point' is adjusted before running modification hooks.
In `replace_range', the point is also relocated. I am not sure why it has
to be moved again just before returning from `replace-match'.
This is not a new issue. It is in Emacs24 at least.
In GNU Emacs 27.0.90 (build 1, x86_64-pc-cygwin)
of 2020-03-04 built on moufang2
Repository revision: afff43a72e96fcccabe77ff63226cddd540e068d
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.19041
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Quit
ert
next-line: End of buffer [3 times]
test-replace-match
Ran 1 tests, 0 results were as expected, 1 unexpected
next-line: End of buffer
previous-line: Beginning of buffer [13 times]
previous-line: Beginning of buffer
Configured using:
'configure
--srcdir=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/src/emacs-27.0.90
--prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc
--docdir=/usr/share/doc/emacs --htmldir=/usr/share/doc/emacs/html -C
--with-w32 'CFLAGS=-ggdb -O2 -pipe -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong
--param=ssp-buffer-size=4
-fdebug-prefix-map=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/build=/usr/src/debug/emacs-27.0.90-1
-fdebug-prefix-map=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/src/emacs-27.0.90=/usr/src/debug/emacs-27.0.90-1'
CPPFLAGS= LDFLAGS='
Configured features:
XPM JPEG TIFF GIF PNG SOUND DBUS GLIB NOTIFY GFILENOTIFY ACL GNUTLS
LIBXML2 HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS XIM MODULES THREADS JSON
PDUMPER LCMS2 GMP
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: Emacs-Lisp
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search time-date subr-x
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils cl-seq cl-extra seq byte-opt bytecomp byte-compile cconv
cl-macs gv ert pp ewoc debug backtrace help-mode find-func vc-git
diff-mode easymenu easy-mmode cl-loaddefs cl-lib tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic 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 charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
gfilenotify w32 lcms2 multi-tty make-network-process emacs)
Memory information:
((conses 16 62659 8699)
(symbols 48 7750 1)
(strings 32 21627 1406)
(string-bytes 1 668356)
(vectors 16 12971)
(vector-slots 8 156156 9450)
(floats 8 40 94)
(intervals 56 307 1)
(buffers 1000 14))
[-- Attachment #2: test_replace_match.el --]
[-- Type: application/octet-stream, Size: 525 bytes --]
(require 'ert)
(ert-deftest test-replace-match ()
"Test for bug."
(let ((check-point nil)
(ov-set nil))
(with-temp-buffer
(insert "a abc")
(setq ov-set (make-overlay 3 5))
(overlay-put
ov-set 'modification-hooks
(list (lambda (o after &rest _args)
(when after
(let ((inhibit-modification-hooks t))
(save-excursion
(goto-char 2)
(insert "bcd")))))))
(goto-char 3)
(if (search-forward "bc")
(replace-match "bcd"))
(should (eq (point) 10)))))
next reply other threads:[~2020-07-19 5:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-19 5:50 Ren Victor [this message]
2020-10-17 9:49 ` bug#42424: 27.0.90; replace-match: point is NOT left at the end of replacement Lars Ingebrigtsen
2020-10-17 17:25 ` Eli Zaretskii
2020-10-18 8:24 ` Lars Ingebrigtsen
2021-07-31 14:03 ` Lars Ingebrigtsen
2021-07-31 14:20 ` Eli Zaretskii
2021-07-31 14:28 ` Lars Ingebrigtsen
2021-07-31 14:49 ` Lars Ingebrigtsen
2021-07-31 15:10 ` Eli Zaretskii
2021-07-31 15:45 ` Lars Ingebrigtsen
2024-04-09 15:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@mail.gmail.com' \
--to=victorhge@gmail.com \
--cc=42424@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).