Subject: bug#76653: 31.0.50; tooltip-delay not honored when tooltip-mode is disabled

From: Eli Zaretskii <[email-masked]>
Date: Sat, 01 Mar 2025 13:29:03 +0200

> From: Dani Moncayo <[email-masked]>
> Date: Fri, 28 Feb 2025 19:17:31 +0100
> 
> >From 'emacs -Q': disable tooltip-mode (M-x tooltip-mode RET) and then
> move the mouse pointer over the buffer ID (in the mode line).
> 
> The tooltip text appears in the echo area immediately (just after the
> mouse pointer enters the "buffer ID area").
> But IIUC, it should wait a little time (tooltip-delay seconds) before
> showing the help text (just like when tooltip-mode is enabled).

Thanks.  Indeed, the current code ignores the delays on text-only
terminals.  Does the patch below give good results?

diff --git a/lisp/tooltip.el b/lisp/tooltip.el
index 482af3b..51a9841 100644
--- a/lisp/tooltip.el
+++ b/lisp/tooltip.el
@@ -251,7 +251,8 @@ tooltip-show
 `use-system-tooltips' is non-nil and Emacs is built with support
 for system tooltips, such as on NS, Haiku, and with the GTK
 toolkit."
-  (if use-echo-area
+  (if (or use-echo-area
+          (not (display-graphic-p)))
       (tooltip-show-help-non-mode text)
     (condition-case error
 	(let ((params (copy-sequence tooltip-frame-parameters))
@@ -285,8 +286,13 @@ tooltip-hide
   "Hide a tooltip, if one is displayed.
 Value is non-nil if tooltip was open."
   (tooltip-cancel-delayed-tip)
-  (when (x-hide-tip)
-    (setq tooltip-hide-time (float-time))))
+  (if (display-graphic-p)
+      (when (x-hide-tip)
+        (setq tooltip-hide-time (float-time)))
+    (let ((msg (current-message)))
+      (message "")
+      (when (not (or (null msg) (equal msg "")))
+        (setq tooltip-hide-time (float-time))))))
 
 
 ;;; Debugger-related functions
@@ -386,11 +392,10 @@ tooltip-show-help-non-mode
 (defun tooltip-show-help (msg)
   "Function installed as `show-help-function'.
 MSG is either a help string to display, or nil to cancel the display."
-  (if (and (display-graphic-p)
-           ;; Tooltips can't be displayed on top of the global menu
-           ;; bar on NS.
-           (or (not (eq window-system 'ns))
-               (not (menu-or-popup-active-p))))
+  (if ;; Tooltips can't be displayed on top of the global menu bar on
+      ;; NS.
+      (not (and (eq window-system 'ns)
+                (menu-or-popup-active-p)))
       (let ((previous-help tooltip-help-message))
 	(setq tooltip-help-message msg)
 	(cond ((null msg)
@@ -408,9 +413,7 @@ tooltip-show-help
 	       ;; A different help.  Remove a previous tooltip, and
 	       ;; display a new one, with some delay.
 	       (tooltip-hide)
-	       (tooltip-start-delayed-tip))))
-    ;; On text-only displays, try `tooltip-show-help-non-mode'.
-    (tooltip-show-help-non-mode msg)))
+	       (tooltip-start-delayed-tip))))))
 
 (defun tooltip-help-tips (_event)
   "Hook function to display a help tooltip.