Subject: bug#69248: [PATCH] Fix flymake lighter tool-tip from generating errors

From: Robert Burks <[email-masked]>
Date: Fri, 16 Feb 2024 19:07:12 -0500

With a non-flymake window selected, hovering over the flymake line lighter
of an inactive window generates errors.  This also occurs where the
indicators are shown in describe mode help.

The attached patch corrects this issue.

Robert A. Burks
From 7d9baf7a782b3f569c51c3533798df6cc00b1acd Mon Sep 17 00:00:00 2001
From: "Robert A. Burks" <[email-masked]>
Date: Fri, 16 Feb 2024 18:17:52 -0500
Subject: [PATCH] Fix flymake lighter tool-tip from generating errors

Flymake tool-tip was generating errors on mouse over of
mode-line lighter on inactive windows and on the minor mode
indicator in the describe-mode Help page.
* lisp/progmodes/flymake.el (flymake--mode-line-title):
help-echo now uses buffer local state and makes null check.
---
 lisp/progmodes/flymake.el | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index bb062753d39..23c6d9cf85d 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1401,13 +1401,19 @@ flymake--mode-line-title
     ,flymake-mode-line-lighter
     mouse-face mode-line-highlight
     help-echo
-    ,(lambda (&rest _)
-       (concat
-        (format "%s known backends\n" (hash-table-count flymake--state))
-        (format "%s running\n" (length (flymake-running-backends)))
-        (format "%s disabled\n" (length (flymake-disabled-backends)))
-        "mouse-1: Display minor mode menu\n"
-        "mouse-2: Show help for minor mode"))
+    ,(lambda (w &rest _)
+       (with-current-buffer (window-buffer w)
+         ;; Mouse can activate tool-tip without window being active.
+         ;; `flymake--state' is buffer local and is null when line
+         ;; lighter appears in *Help* `describe-mode'.
+         (concat
+          (unless (null flymake--state)
+            (concat
+             (format "%s known backends\n"  (hash-table-count flymake--state))
+             (format "%s running\n" (length (flymake-running-backends)))
+             (format "%s disabled\n" (length (flymake-disabled-backends)))))
+          "mouse-1: Display minor mode menu\n"
+          "mouse-2: Show help for minor mode")))
     keymap
     ,(let ((map (make-sparse-keymap)))
        (define-key map [mode-line down-mouse-1]
-- 
2.34.1