From f22e9ba9ac64c30d6532a508494b5149c27596e7 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 30 Jan 2022 08:49:34 +0200 Subject: [PATCH] Fix regression in Occur Edit mode * lisp/replace.el (occur-after-change-function): Fix the algorithm to find the smallest change in some corner cases. (Bug#53598) --- lisp/replace.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/replace.el b/lisp/replace.el index 45bd05d41d7..b1cfd7e3f42 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1413,10 +1413,15 @@ To return to ordinary Occur mode, use \\[occur-cease-edit]." (length s1))))) (prefix-len (funcall common-prefix buf-str text)) (suffix-len (funcall common-prefix - (reverse buf-str) (reverse text)))) + (reverse (substring + buf-str prefix-len)) + (reverse (substring + text prefix-len))))) (setq beg-pos (+ beg-pos prefix-len)) (setq end-pos (- end-pos suffix-len)) - (setq text (substring text prefix-len (- suffix-len))) + (setq text (substring text prefix-len + (and (not (zerop suffix-len)) + (- suffix-len)))) (delete-region beg-pos end-pos) (goto-char beg-pos) (insert text))) -- 2.39.2