branch: elpa/helm
commit 9d7d513727971b6f685ce98c0f10ff04d3316ec2
Author: Thierry Volpiatto <thie...@posteo.net>
Commit: Thierry Volpiatto <thie...@posteo.net>

    Avoid deleting and creating timer needlessly
    
    Previously we cancelled the timer and initialized it again at each
    call of move-selection, now we create a timer that cancel itself and
    check at each call if the timer is alive before creating a new one.
    
    As a result, for example when keeping C-n pressed and passing e.g. 10
    candidates, previously 10 timers were cancelled and created, now only
    one timer is created.
---
 helm-utils.el | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/helm-utils.el b/helm-utils.el
index 13432efbcd2..d2150dbc5d1 100644
--- a/helm-utils.el
+++ b/helm-utils.el
@@ -1080,9 +1080,6 @@ Assume regexp is a pcre based regexp."
                 'face 'helm-tooltip)))
 
 (defun helm-maybe-show-help-echo ()
-  (when helm--show-help-echo-timer
-    (cancel-timer helm--show-help-echo-timer)
-    (setq helm--show-help-echo-timer nil))
   (when helm--maybe-show-help-echo-overlay
     (delete-overlay helm--maybe-show-help-echo-overlay))
   (let* ((src (helm-get-current-source))
@@ -1090,24 +1087,27 @@ Assume regexp is a pcre based regexp."
     (when (and helm-alive-p
                helm-popup-tip-mode
                popup-info-fn)
-      (setq helm--show-help-echo-timer
-            (run-with-idle-timer
-             1 nil
-             (lambda ()
-               ;; We may have an error (wrong-type-argument window-live-p nil)
-               ;; when switching to help window, the error may occur in the
-               ;; small lap of time where the helm-window is deleted and the
-               ;; help buffer not already displayed.
-               (ignore-error wrong-type-argument
-                 (save-selected-window
-                   (with-helm-window
-                     (let ((pos (save-excursion (end-of-visual-line) (point)))
-                           (str (and popup-info-fn
-                                     (funcall popup-info-fn 
(helm-get-selection)))))
-                       (when (and str (not (string= str "")))
-                         (helm-tooltip-show
-                          (concat " " str)
-                          pos))))))))))))
+      (unless (timerp helm--show-help-echo-timer)
+        (setq helm--show-help-echo-timer
+              (run-with-idle-timer
+               1 nil
+               (lambda ()
+                 (cancel-timer helm--show-help-echo-timer)
+                 (setq helm--show-help-echo-timer nil)
+                 ;; We may have an error (wrong-type-argument window-live-p 
nil)
+                 ;; when switching to help window, the error may occur in the
+                 ;; small lap of time where the helm-window is deleted and the
+                 ;; help buffer not already displayed.
+                 (ignore-error wrong-type-argument
+                   (save-selected-window
+                     (with-helm-window
+                       (let ((pos (save-excursion (end-of-visual-line) 
(point)))
+                             (str (and popup-info-fn
+                                       (funcall popup-info-fn 
(helm-get-selection)))))
+                         (when (and str (not (string= str "")))
+                           (helm-tooltip-show
+                            (concat " " str)
+                            pos)))))))))))))
 
 ;;;###autoload
 (define-minor-mode helm-popup-tip-mode

Reply via email to