Subject: Re: bug#56815: 29.0.50; Isearch lazy-highlight highlights too much when truncate-lines is in effect

From: Juri Linkov <[email-masked]>
Date: Mon, 22 Aug 2022 09:48:47 +0300

>> I guess it could be in simple.el.  But what would be a good name?
>> Maybe 'truncate-lines-p'?
>
> lines-truncated-p, I guess.  Or window-lines-truncated-p.  And I think
> it should be in window.el.

To keep the prefix like in all truncate-related names,
truncated-partial-width-window-p could serve as an example:

  (truncated-partial-width-window-p &optional WINDOW)
  (truncated-lines-p &optional window)

Or can truncated-partial-width-window-p be called directly?  By just

  (or truncate-lines (truncated-partial-width-window-p))

Anyway, here is the patch that probably not needed
when truncated-partial-width-window-p can be used instead:

diff --git a/lisp/simple.el b/lisp/simple.el
index d862c0e9a8..8f7440a3bb 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7700,13 +7700,7 @@ line-move
                  ;; Lines are not truncated...
                  (not
                   (and
-                   (or truncate-lines
-                       (and (integerp truncate-partial-width-windows)
-                            (< (window-total-width)
-                               truncate-partial-width-windows))
-                       (and truncate-partial-width-windows
-                            (not (integerp truncate-partial-width-windows))
-                            (not (window-full-width-p))))
+                   (truncated-lines-p)
                    ;; ...or if lines are truncated, this buffer
                    ;; doesn't have very long lines.
                    (long-line-optimizations-p)))
@@ -7716,14 +7710,7 @@ line-move
 	       ;; Display-based column are incompatible with goal-column.
 	       (not goal-column)
                ;; Lines aren't truncated.
-               (not
-                (or truncate-lines
-                    (and (integerp truncate-partial-width-windows)
-                         (< (window-width)
-                            truncate-partial-width-windows))
-                    (and truncate-partial-width-windows
-                         (not (integerp truncate-partial-width-windows))
-                         (not (window-full-width-p)))))
+               (not (truncated-lines-p))
 	       ;; When the text in the window is scrolled to the left,
 	       ;; display-based motion doesn't make sense (because each
 	       ;; logical line occupies exactly one screen line).
diff --git a/lisp/window.el b/lisp/window.el
index 4d88ffa903..aecac8c8d0 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9012,6 +9023,18 @@ shrink-window-horizontally
   (interactive "p")
   (shrink-window delta t))
 
+(defun truncated-lines-p (&optional window)
+  "Return non-nil when lines are truncated.
+This depends on the values of `truncate-lines' and
+`truncate-partial-width-windows'."
+  (or truncate-lines
+      (and (integerp truncate-partial-width-windows)
+           (< (window-total-width window)
+              truncate-partial-width-windows))
+      (and truncate-partial-width-windows
+           (not (integerp truncate-partial-width-windows))
+           (not (window-full-width-p window)))))
+
 (defun count-screen-lines (&optional beg end count-final-newline window)
   "Return the number of screen lines in the region.
 The number of screen lines may be different from the number of actual lines,
@@ -9044,10 +9067,7 @@ count-screen-lines
       ;; vertical-motion returns a number that is 1 larger than it
       ;; should.  We need to fix that.
       (setq end-invisible-p
-            (and (or truncate-lines
-                     (and (natnump truncate-partial-width-windows)
-                          (< (window-total-width window)
-                             truncate-partial-width-windows)))
+            (and (truncated-lines-p window)
                  (save-excursion
                    (goto-char finish)
                    (> (- (current-column) (window-hscroll window))