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
This commit is contained in:
Thomas Letan 2022-07-29 10:44:11 +02:00
parent 39b44c99a0
commit cee5266af5

View File

@ -317,29 +317,24 @@ FRAME is the childframe, WINDOW is the primary window."
;; move position ;; move position
(set-frame-position frame (car pos) (cdr pos)))) (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) (defun eldoc-box--inhibit-childframe-for (sec)
"Inhibit display of childframe for SEC seconds." "Inhibit display of childframe for SEC seconds after Emacs is idle again."
(when eldoc-box--inhibit-childframe-timer (unless eldoc-box--inhibit-childframe
(cancel-timer eldoc-box--inhibit-childframe-timer)) (setq eldoc-box--inhibit-childframe t)
(eldoc-box-quit-frame) (eldoc-box-quit-frame)
(setq eldoc-box--inhibit-childframe t (run-with-idle-timer sec nil
eldoc-box--inhibit-childframe-timer (lambda ()
(run-with-timer sec nil (setq eldoc-box--inhibit-childframe nil)))))
(lambda ()
(setq eldoc-box--inhibit-childframe nil)))))
(defun eldoc-box--follow-cursor () (defun eldoc-box--follow-cursor ()
"Make childframe follow cursor in at-point mode." "Make childframe follow cursor in at-point mode."
(if (member this-command eldoc-box-self-insert-command-list) (unless eldoc-box--inhibit-childframe
(progn (when (frame-live-p eldoc-box--frame) (if (member this-command eldoc-box-self-insert-command-list)
(eldoc-box--update-childframe-geometry (progn (when (frame-live-p eldoc-box--frame)
eldoc-box--frame (frame-selected-window eldoc-box--frame)))) (eldoc-box--update-childframe-geometry
;; if not typing, inhibit display eldoc-box--frame (frame-selected-window eldoc-box--frame))))
(eldoc-box--inhibit-childframe-for 0.2))) ;; if not typing, inhibit display
(eldoc-box--inhibit-childframe-for 0.5))))
(defun eldoc-box--get-frame (buffer) (defun eldoc-box--get-frame (buffer)
"Return a childframe displaying BUFFER. "Return a childframe displaying BUFFER.