From cee5266af554ac18a47a77f355a8839ed650f3f8 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Fri, 29 Jul 2022 10:44:11 +0200 Subject: [PATCH] Fix slowness of the 'follow-cursor' feature * eldoc-box.el (eldoc-box--inhibit-childframe-timer): Remove variable. (eldoc-box--inhibit-childframe-for): Refactor to use 'run-with-idle-timer' instead of 'run-with-timer' (eldoc-box--follow-cursor): Don't do anything if the timer is set --- eldoc-box.el | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 7f7c8da..f563e57 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -317,29 +317,24 @@ FRAME is the childframe, WINDOW is the primary window." ;; move position (set-frame-position frame (car pos) (cdr pos)))) -(defvar eldoc-box--inhibit-childframe-timer nil - "When this timer is on, inhibit childframe display. -Intended for follow-cursor to disable display when moving cursor.") - (defun eldoc-box--inhibit-childframe-for (sec) - "Inhibit display of childframe for SEC seconds." - (when eldoc-box--inhibit-childframe-timer - (cancel-timer eldoc-box--inhibit-childframe-timer)) - (eldoc-box-quit-frame) - (setq eldoc-box--inhibit-childframe t - eldoc-box--inhibit-childframe-timer - (run-with-timer sec nil - (lambda () - (setq eldoc-box--inhibit-childframe nil))))) + "Inhibit display of childframe for SEC seconds after Emacs is idle again." + (unless eldoc-box--inhibit-childframe + (setq eldoc-box--inhibit-childframe t) + (eldoc-box-quit-frame) + (run-with-idle-timer sec nil + (lambda () + (setq eldoc-box--inhibit-childframe nil))))) (defun eldoc-box--follow-cursor () "Make childframe follow cursor in at-point mode." - (if (member this-command eldoc-box-self-insert-command-list) - (progn (when (frame-live-p eldoc-box--frame) - (eldoc-box--update-childframe-geometry - eldoc-box--frame (frame-selected-window eldoc-box--frame)))) - ;; if not typing, inhibit display - (eldoc-box--inhibit-childframe-for 0.2))) + (unless eldoc-box--inhibit-childframe + (if (member this-command eldoc-box-self-insert-command-list) + (progn (when (frame-live-p eldoc-box--frame) + (eldoc-box--update-childframe-geometry + eldoc-box--frame (frame-selected-window eldoc-box--frame)))) + ;; if not typing, inhibit display + (eldoc-box--inhibit-childframe-for 0.5)))) (defun eldoc-box--get-frame (buffer) "Return a childframe displaying BUFFER.