From 92100b2a2d8ee6c557d10f5f134fd3f4824656f3 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 11 Jun 2022 19:42:56 -0700 Subject: [PATCH] Add 'eldoc-box-help-at-point' * eldoc-box.el (eldoc-box--help-at-point-last-point): New variable (eldoc-box--help-at-point-cleanup): New function. (eldoc-box-help-at-point): New command. --- eldoc-box.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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*"