Subject: 27.1; `isearch-del-char' should move point further back

From: Augusto Stoffel <[email-masked]>
Date: Fri, 12 Feb 2021 19:56:36 +0100

Suppose my buffer contains the text "x1yx2" right after point, and that
`isearch-del-char' is bound to DEL in Isearch mode.  If I type

   C-s y DEL x1

then I would expect the search to succeed: the cursor would first go
after "y", then return to the starting point of search after pressing
DEL – this is how `isearch-delete-char' behaves, anyway.

Instead, the cursor remains after "y" after pressing DEL, and the search
fails with the cursor after the second "x".  I have attached a patch to
fix this.

I have also attached a second trivial patch for an unrelated, very tiny
bug.

Best,
Augusto

>From 1b1fad0d106390d907a805c9e8c81dd9831b5e1e Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Fri, 12 Feb 2021 19:37:14 +0100
Subject: [PATCH 2/2] Make `isearch-del-char' backtrack the search more
 aggressively

This allows to always find the first occurrence of the search string
after the last `isearch-repeat' or the start of search.
* lisp/isearch.el (isearch-del-char): Call `isearch-fallback' before
updating the search.
---
 lisp/isearch.el | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index aae4aeb261..b9c4cd2a65 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2475,13 +2475,9 @@ isearch-del-char
                                      isearch-string "")))
   ;; Do the following before moving point.
   (funcall (or isearch-message-function #'isearch-message) nil t)
-  ;; Use the isearch-other-end as new starting point to be able
-  ;; to find the remaining part of the search string again.
-  ;; This is like what `isearch-search-and-update' does,
-  ;; but currently it doesn't support deletion of characters
-  ;; for the case where unsuccessful search may become successful
-  ;; by deletion of characters.
-  (if isearch-other-end (goto-char isearch-other-end))
+  ;; Use `isearch-fallback' to be able to find an earlier occurrence
+  ;; of the remaining part of the search string.
+  (isearch-fallback nil nil t)
   (isearch-search)
   (isearch-push-state)
   (isearch-update))
-- 
2.29.2

>From 3707102e4a87ae31105ca1dc71f0f1c349ed806f Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Fri, 12 Feb 2021 19:29:54 +0100
Subject: [PATCH 1/2] Small correction to
 `isearch-lazy-highlight-buffer-update'

The value of point is now read after a potential change of buffer.
* lisp/isearch.el (isearch-lazy-highlight-buffer-update): move call
to `point' after `select-window'.
---
 lisp/isearch.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index b58ca8a6f7..aae4aeb261 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -4127,13 +4127,13 @@ isearch-lazy-highlight-buffer-update
   "Update highlighting of other matches in the full buffer."
   (let ((max lazy-highlight-buffer-max-at-a-time)
         (looping t)
-        nomore window-start window-end
-        (opoint (point)))
+        nomore window-start window-end opoint)
     (with-local-quit
       (save-selected-window
 	(if (and (window-live-p isearch-lazy-highlight-window)
 		 (not (memq (selected-window) isearch-lazy-highlight-window-group)))
 	    (select-window isearch-lazy-highlight-window))
+        (setq opoint (point))
 	(setq window-start (window-group-start))
 	(setq window-end (window-group-end))
 	(save-excursion
-- 
2.29.2