diff --git a/eldoc-box.el b/eldoc-box.el index 813a3e5..769f39f 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -178,6 +178,32 @@ Intended for internal use." (delete-frame eldoc-box--frame) (setq eldoc-box--frame nil))) +;;;;; Help at point + +(defvar eldoc-box--help-at-point-last-point 0 + "This point cache is used by clean up function. +If (point) != last point, cleanup frame.") + +(defun eldoc-box--help-at-point-cleanup () + "Try to clean up the childframe made by eldoc-box hack." + (if (or (eq (point) eldoc-box--help-at-point-last-point) + ;; don't clean up when the user clicks childframe + (eq (selected-frame) eldoc-box--frame)) + (run-with-timer 0.1 nil #'eldoc-box--help-at-point-cleanup) + (eldoc-box-quit-frame) + (kill-local-variable 'eldoc-display-functions))) + +(defun eldoc-box-help-at-point () + "Display documentation of the symbol at point." + (interactive) + (let ((eldoc-box-position-function + #'eldoc-box--default-at-point-position-function)) + (eldoc-box--display + (with-current-buffer eldoc--doc-buffer + (buffer-string)))) + (setq eldoc-box--help-at-point-last-point (point)) + (run-with-timer 0.1 nil #'eldoc-box--help-at-point-cleanup)) + ;;;; Backstage ;;;;; Variable (defvar eldoc-box--buffer " *eldoc-box*"