Subject: bug#78074: isearch not respecting point when changing direction after scrolling

From: Juri Linkov <[email-masked]>
Date: Mon, 28 Apr 2025 18:12:46 +0300

> 1. emacs -Q
> 2. M-: (setq isearch-allow-scroll 'unlimited)
> 3. M-: (setq isearch-repeat-on-direction-change t)
> 3. we need enough text in the buffer to be able to scroll, so C-x h M-w C-y
> several times.
> 3. At some point A, start a search with C-s.
> 4. Use C-v and/or M-v any number of times to move the point while remaining
> in isearch-mode.
> 5. C-s will move to the next match after point, but using C-r instead will
> move to the first match before point A.
>
> I think in this situation C-r should move to the first match before the
> current point, instead of the first match before the point where
> isearch-forward was last invoked.
>
> Likewise starting with isearch-backward: after using C-r then C-v/M-v, C-s
> matches the first occurrence after the point where C-r was last invoked,
> instead of the first occurrence after the current point.
>
> I think this is a bug because it doesn't happen when
> `isearch-repeat-on-direction-change' has its default value of nil.

Thanks for the bug report.  Maybe we don't need these lines
in 'isearch-repeat' after all:

    (if (and isearch-other-end isearch-repeat-on-direction-change)
        (goto-char isearch-other-end))

Could you please try to remove these 2 lines and see whether this
improves the behavior of changing the direction.