From 112afa113782c08f7565506e60c0d8d3c15be3ca Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Tue, 18 Dec 2018 12:34:48 -0500 Subject: [PATCH] Abstract timer interval as a variable 1 second is a bit too long, but old machines might want a longer interval, I set it to 0.2 on my machine and CPU looks ok. --- README.org | 1 + eldoc-box.el | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index f663f1a..52d2d90 100644 --- a/README.org +++ b/README.org @@ -18,6 +18,7 @@ Get the file, add to load path, and ** Variable - =eldoc-box-max-pixel-width= & =eldoc-box-max-pixel-height= :: Set them according to the screen resolution of your machine. - =eldoc-box-only-multi-line= :: Set this to non-nil and eldoc-box only display multi-line message in childframe. One line messages are left in minibuffer. +- =eldoc-box-cleanup-interval= :: After this amount of seconds will eldoc-box attempt to cleanup the childframe. E.g. if it is set to 1, the childframe is cleared 1 second after you moved the point to somewhere else (that doesn't have a doc to show). ** Use with eglot As of writing this README, eglot doesn't have a public mode hook, use this hook: #+BEGIN_SRC emacs-lisp diff --git a/eldoc-box.el b/eldoc-box.el index 19afb2d..579fbe8 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -54,6 +54,11 @@ (defvar eldoc-box-only-multi-line nil "If non-nil, only use childframe when there are more than one line.") +(defvar eldoc-box-cleanup-interval 1 + "After this amount of seconds will eldoc-box attempt to cleanup the childframe. +E.g. if it is set to 1, the childframe is cleared 1 second after +you moved the point to somewhere else (that doesn't have a doc to show)") + (defvar eldoc-box-frame-parameters '( ;; (left . -1) @@ -219,7 +224,7 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." ;; setup another one to make sure the doc frame is cleared ;; once the condition above it met (setq eldoc-box--cleanup-timer - (run-with-timer 1 nil #'eldoc-box--maybe-cleanup)))) + (run-with-timer eldoc-box-cleanup-interval nil #'eldoc-box--maybe-cleanup)))) (defun eldoc-box--eldoc-message-function (str &rest args) "Front-end for eldoc. Display STR in childframe and ARGS works like `message'." @@ -236,7 +241,7 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." ;; in `pre-command-hook', which means the timer is reset before every ;; command if `eldoc-box-hover-mode' is on and `eldoc-last-message' is not nil. (setq eldoc-box--cleanup-timer - (run-with-timer 1 nil #'eldoc-box--maybe-cleanup)))) + (run-with-timer eldoc-box-cleanup-interval nil #'eldoc-box--maybe-cleanup)))) t)) (provide 'eldoc-box)