unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42424: 27.0.90; replace-match: point is NOT left at the end of replacement
@ 2020-07-19  5:50 Ren Victor
  2020-10-17  9:49 ` Lars Ingebrigtsen
  2024-04-09 15:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 11+ messages in thread
From: Ren Victor @ 2020-07-19  5:50 UTC (permalink / raw)
  To: 42424

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

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

end of thread, other threads:[~2024-04-09 15:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-19  5:50 bug#42424: 27.0.90; replace-match: point is NOT left at the end of replacement Ren Victor
2020-10-17  9:49 ` 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

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