Emacs 26.2 - Scroll command breaks if allowed during Isearch

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Emacs 26.2 - Scroll command breaks if allowed during Isearch

Andrea Greselin
Hello,

I noticed that a command that uses `set-window-hscroll' doesn't work the
same way during an isearch if `isearch-allow-scroll' is non nil and the
command has the properties `scroll-command' or `isearch-scroll'.

To reproduce, run `emacs -Q' and evaluate
--------------------------------------------------------------------------------
;;
0123456789

;; Set up the window and enable scrolling during isearch.
(set-frame-width nil 80)
(setq hscroll-margin 5)
(toggle-truncate-lines)
(setq isearch-allow-scroll t)

(defun h-scroll ()
  (interactive)
  (set-window-hscroll (selected-window) 10))

(defun h-not-so-scroll ()
  (interactive)
  (set-window-hscroll (selected-window) 10))

;; Even if you comment out one of these two settings the behaviour is the
same
(put 'h-scroll 'scroll-command t)
(put 'h-scroll 'isearch-scroll t)

(global-set-key (kbd "C-S-l") #'h-scroll)
(global-set-key (kbd "C-S-k") #'h-not-so-scroll)
--------------------------------------------------------------------------------
Now `h-scroll' (C-S-l) never quits isearch but
 - when I search for 0 in the first line and type C-S-l nothing happens
(`window-hscroll' remains 0);
 - if I search for 1 <= n <= 5 (columns 74 to 78, within `hscroll-margin'
from the right edge), isearch scrolls the window left, C-S-l then brings it
back all the way to the right (`window-hscroll' is brought back to 0);
 - if I search for n >= 6 then type C-S-l, `window-hscroll' is set to 10,
as expected.
C-S-k always sets `window-hscroll' to 10, but it exits isearch. Outside of
isearch both commands always work correctly.

What's the reason for this behaviour? Can I change it so that `h-scroll'
always sets the `window-hscroll' to 10 without exiting isearch?

Thanks,
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Emacs 26.2 - Scroll command breaks if allowed during Isearch

Eli Zaretskii
> From: Andrea Greselin <[hidden email]>
> Date: Wed, 13 Nov 2019 17:06:33 +0100
>
> What's the reason for this behaviour?

The reason is that you have Isearch fighting you: it itself calls
set-window-hscroll, trying to preserve the value it saw at the
beginning of the search command, as much as possible.  See
isearch-update in isearch.el.

> Can I change it so that `h-scroll' always sets the `window-hscroll'
> to 10 without exiting isearch?

Why do you want to do that?  Is there some problem with the hscrolling
Isearch does by default?