GNU bug report logs - #46469
27.1; `isearch-del-char' should move point further back

Previous Next

Package: emacs;

Reported by: Augusto Stoffel <arstoffel <at> gmail.com>

Date: Fri, 12 Feb 2021 19:23:02 UTC

Severity: normal

Found in version 27.1

Full log


Message #59 received at 46469 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 46469 <at> debbugs.gnu.org
Subject: Re: bug#46469: 27.1; `isearch-del-char' should move point further back
Date: Tue, 27 Apr 2021 20:44:32 +0200
[Message part 1 (text/plain, inline)]
For the record, the search ring advance/retreat commands suffer from a
bug similar to the `isearch-del-char' one described here.

Namely, `C-s M-p M-p M-p' presumably takes you to the first match, after
the starting point, of the third history element.  It would be very
strange to expect that the result of this key sequence depends on the
first and second history elements, or on the contents of the buffer
beyond the first match of the third history element.

And, in fact, everything is fine when `search-ring-update' is nil.
However:
  
(progn
  (setq search-ring-update t
        search-ring '("1" "2" "3")
        search-ring-yank-pointer nil)
  (save-excursion
    (insert "expect point here -> 3 2 1 2 3 <- but instead get here"))
  (isearch-mode t)
  (isearch-ring-retreat)
  (isearch-ring-retreat)
  (isearch-ring-retreat))

On Sun, 14 Feb 2021 at 19:45, Juri Linkov <juri <at> linkov.net> wrote:

> I tried again, but your patch still doesn't work.  With
>
> (progn
>   (define-key isearch-mode-map (kbd "DEL") 'isearch-del-char)
>   (execute-kbd-macro [?\C-s ?y backspace ?x ?1]))
> x1yx2
>
> It signals the error "Keyboard macro terminated by a command ringing the bell".

Now I see, my old patch only worked in regexp mode (which is `C-s' for
me).  The attached one seems to work (but this is subtle stuff, there
may be edge cases).

[0001-Make-isearch-del-char-backtrack-the-search-more-aggr.patch (text/x-patch, inline)]
From a29f3c0b2b43af6b9c283205643a1e2ac43030b7 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel <at> gmail.com>
Date: Fri, 12 Feb 2021 19:37:14 +0100
Subject: [PATCH] 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): Go to barrier before updating
the search.
---
 lisp/isearch.el | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 9f3cfd70fb..f6a55c7918 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2505,13 +2505,12 @@ 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))
+  ;; Go to `isearch-barrier' to be able to find an earlier occurrence
+  ;; of the remaining part of the search string.
+  (if isearch-regexp
+      (isearch-fallback nil nil t)
+    (goto-char isearch-barrier)
+    (setq isearch-adjusted t))
   (isearch-search)
   (isearch-push-state)
   (isearch-update))
-- 
2.30.2


This bug report was last modified 4 years and 107 days ago.

Previous Next


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