branch: elpa/eldoc-mouse
commit 3920ab0063c2c62bed764d88115d70ce774b99e0
Merge: 53c23bfeee2 90735214ca2
Author: huangfeiyu <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #10 from ideasman42/pr-de-duplicate-thing-at-point
    
    Cleanup: remove redundant thing-at-point calls, let bind temporary hook
---
 eldoc-mouse.el | 73 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 37 insertions(+), 36 deletions(-)

diff --git a/eldoc-mouse.el b/eldoc-mouse.el
index e61d886e040..3425c811cae 100644
--- a/eldoc-mouse.el
+++ b/eldoc-mouse.el
@@ -108,31 +108,32 @@ By default, posframe will not used by eldoc.")
   "Show document at the cursor."
   (interactive)
   (eldoc-mouse--hide-posframe)
-  (when (thing-at-point 'symbol)
-    (if eldoc-mouse-mode
-        (let ((eldoc-documentation-functions
-               (cons #'eldoc-mouse-hover-eldoc-function 
eldoc-documentation-functions)))
-          (setq-local eldoc-mouse-last-symbol-bounds (bounds-of-thing-at-point 
'symbol))
-          (setq-local eldoc-mouse-unsupress-posframe t)
-
-          ;; make sure eldoc always send the request to get doc.
-          (setq eldoc--last-request-state nil)
-
-          (eldoc-print-current-symbol-info))
-      (progn
-        (remove-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function t)
-        (setq-local eldoc-mouse-last-symbol-bounds (bounds-of-thing-at-point 
'symbol))
-        (unless eldoc-mouse--original-display-functions
-          (setq-local eldoc-mouse--original-display-functions 
eldoc-display-functions))
-        (setq-local eldoc-display-functions
-                    (append eldoc-display-functions 
'(eldoc-mouse-display-in-posframe)))
+  (when-let* ((symbol-bounds (bounds-of-thing-at-point 'symbol)))
+    (cond
+     (eldoc-mouse-mode
+      (let ((eldoc-documentation-functions
+             (cons #'eldoc-mouse-hover-eldoc-function 
eldoc-documentation-functions)))
+        (setq-local eldoc-mouse-last-symbol-bounds symbol-bounds)
         (setq-local eldoc-mouse-unsupress-posframe t)
 
         ;; make sure eldoc always send the request to get doc.
         (setq eldoc--last-request-state nil)
 
-        (eldoc-print-current-symbol-info)
-        (add-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function nil t)))))
+        (eldoc-print-current-symbol-info)))
+     (t
+      (remove-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function t)
+      (setq-local eldoc-mouse-last-symbol-bounds symbol-bounds)
+      (unless eldoc-mouse--original-display-functions
+        (setq-local eldoc-mouse--original-display-functions 
eldoc-display-functions))
+      (setq-local eldoc-display-functions
+                  (append eldoc-display-functions 
'(eldoc-mouse-display-in-posframe)))
+      (setq-local eldoc-mouse-unsupress-posframe t)
+
+      ;; make sure eldoc always send the request to get doc.
+      (setq eldoc--last-request-state nil)
+
+      (eldoc-print-current-symbol-info)
+      (add-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function nil t)))))
 (defun eldoc-mouse-enable ()
   "Enable eldoc-mouse in all `eglot-managed-p' buffers."
   (when (eglot-managed-p)
@@ -201,22 +202,22 @@ POS is the buffer position under the mouse cursor."
     (when eldoc-mouse-mouse-overlay
       (delete-overlay eldoc-mouse-mouse-overlay))
     (save-excursion
-      (add-hook 'eldoc-documentation-functions 
#'eldoc-mouse-hover-eldoc-function nil t)
-      (goto-char pos)
-      (setq-local eldoc-mouse-last-symbol-bounds (bounds-of-thing-at-point 
'symbol))
-      ;; use (nth 4 (syntax-ppss)) to check if the mouse is overing code 
comment.
-      ;; based on the answer from
-      ;; https://emacs.stackexchange.com/questions/14269/14270#14270
-      (when (and (not (eolp)) (not (nth 4 (syntax-ppss))) (thing-at-point 
'symbol))
-        (setq-local eldoc-mouse-unsupress-posframe t)
-        (eldoc-print-current-symbol-info)
-        (setq-local eldoc-mouse-mouse-overlay
-                    (make-overlay
-                     (car eldoc-mouse-last-symbol-bounds) (cdr 
eldoc-mouse-last-symbol-bounds)))
-        (overlay-put eldoc-mouse-mouse-overlay 'face 'highlight))
-      (remove-hook 'eldoc-documentation-functions 
#'eldoc-mouse-hover-eldoc-function t)
-      (when (fboundp 'eglot--highlight-piggyback)
-        (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback 
nil t)))))
+      (let ((eldoc-documentation-functions
+             (cons #'eldoc-mouse-hover-eldoc-function 
eldoc-documentation-functions)))
+        (goto-char pos)
+        (setq-local eldoc-mouse-last-symbol-bounds (bounds-of-thing-at-point 
'symbol))
+        ;; use (nth 4 (syntax-ppss)) to check if the mouse is overing code 
comment.
+        ;; based on the answer from
+        ;; https://emacs.stackexchange.com/questions/14269/14270#14270
+        (when (and (not (eolp)) (not (nth 4 (syntax-ppss))) 
eldoc-mouse-last-symbol-bounds)
+          (setq-local eldoc-mouse-unsupress-posframe t)
+          (eldoc-print-current-symbol-info)
+          (setq-local eldoc-mouse-mouse-overlay
+                      (make-overlay
+                       (car eldoc-mouse-last-symbol-bounds) (cdr 
eldoc-mouse-last-symbol-bounds)))
+          (overlay-put eldoc-mouse-mouse-overlay 'face 'highlight))
+        (when (fboundp 'eglot--highlight-piggyback)
+          (add-hook 'eldoc-documentation-functions 
#'eglot--highlight-piggyback nil t))))))
 
 (defun eldoc-mouse--hide-posframe ()
   "Hide the posframe."

Reply via email to