branch: elpa/eldoc-mouse
commit 3c4fc15ee43d13a3959679e2c689108d802f3bc8
Author: huangfeiyu <[email protected]>
Commit: GitHub <[email protected]>

    Ask user whether stop mouse tracking when user toggle off eldoc-mouse-mode
---
 eldoc-mouse.el | 98 +++++++++++++++++-----------------------------------------
 1 file changed, 29 insertions(+), 69 deletions(-)

diff --git a/eldoc-mouse.el b/eldoc-mouse.el
index d92d2abe5bd..02320b9b50c 100644
--- a/eldoc-mouse.el
+++ b/eldoc-mouse.el
@@ -111,9 +111,7 @@ By default, posframe will not used by eldoc.")
   (when-let* ((symbol-bounds (bounds-of-thing-at-point 'symbol)))
     (cond
      (eldoc-mouse-mode
-      (add-hook
-       'eldoc-documentation-functions #'eldoc-mouse-hover-eldoc-function
-       nil t)
+      (add-hook 'eldoc-documentation-functions 
#'eldoc-mouse-hover-eldoc-function nil t)
       (setq-local eldoc-mouse-last-symbol-bounds symbol-bounds)
       (setq-local eldoc-mouse-unsupress-posframe t)
 
@@ -121,29 +119,21 @@ By default, posframe will not used by eldoc.")
       (setq eldoc--last-request-state nil)
 
       (eldoc-print-current-symbol-info)
-      (remove-hook
-       'eldoc-documentation-functions #'eldoc-mouse-hover-eldoc-function
-       t))
+      (remove-hook 'eldoc-documentation-functions 
#'eldoc-mouse-hover-eldoc-function t))
      (t
-      (remove-hook
-       'eldoc-documentation-functions #'eglot-signature-eldoc-function
-       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-mouse--original-display-functions 
eldoc-display-functions))
       (setq-local eldoc-display-functions
-                  (append
-                   eldoc-display-functions '(eldoc-mouse-display-in-posframe)))
+                  (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)))))
+      (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)
@@ -151,43 +141,33 @@ By default, posframe will not used by eldoc.")
     (setq track-mouse t)
     (setq-local eldoc-mouse--original-display-functions 
eldoc-display-functions)
     (setq-local eldoc-display-functions
-                (append
-                 eldoc-display-functions '(eldoc-mouse-display-in-posframe)))
+                (append eldoc-display-functions 
'(eldoc-mouse-display-in-posframe)))
     ;; Avoid unnecessary document of signatures that clutters the document.
-    (remove-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function
-                 t)
+    (remove-hook 'eldoc-documentation-functions 
#'eglot-signature-eldoc-function t)
     ;; Avoid show document for the cursor.
     (remove-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function t)
     ;; Enable highlight symbol under the cursor.
     ;; In the future the following line is no longer necessary,
-    ;; as emacs use a specific function `eglot-highlight-eldoc-function'
-    ;; for highlighting.
+    ;; as emacs use a specific function `eglot-highlight-eldoc-function' for 
highlighting.
     ;; And here, we want to keep the highlight at cursor.
-    ;; See details:
-    ;; 
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=60166a419f601b413db86ddce186cc387e8ec269
+    ;; see details: 
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=60166a419f601b413db86ddce186cc387e8ec269
     (when (fboundp 'eglot--highlight-piggyback)
-      (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback
-                nil
-                t))
+      (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback 
nil t))
     (local-set-key [mouse-movement] #'eldoc-mouse-doc-on-mouse)))
 
 (defun eldoc-mouse-disable ()
   "Disable eldoc-mouse in all `eglot-managed-p' buffers."
-  (setq track-mouse nil)
+  (when (y-or-n-p "Disable mouse-tracking (may impact other modes)?")
+    (setq track-mouse nil))
   (when eldoc-mouse--original-display-functions
-    (setq-local eldoc-display-functions
-                eldoc-mouse--original-display-functions))
+    (setq-local eldoc-display-functions 
eldoc-mouse--original-display-functions))
   (when (fboundp 'eglot--highlight-piggyback)
     (remove-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback 
t))
 
   (unless (memq #'eglot-signature-eldoc-function eldoc-documentation-functions)
-    (add-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function
-              nil
-              t))
+    (add-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function 
nil t))
   (unless (memq #'eglot-hover-eldoc-function eldoc-documentation-functions)
-    (add-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function
-              nil
-              t))
+    (add-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function nil 
t))
 
   (when eldoc-mouse-mouse-timer
     (cancel-timer eldoc-mouse-mouse-timer)
@@ -214,45 +194,32 @@ Support close the popup when user switch buffer."
 POS is the buffer position under the mouse cursor."
   (when (and pos
              (number-or-marker-p pos)
-             (not
-              (eldoc-mouse-is-mouse-hovering-posframe?
-               eldoc-mouse-posframe-buffer-name))
+             (not (eldoc-mouse-is-mouse-hovering-posframe? 
eldoc-mouse-posframe-buffer-name))
              (or (null eldoc-mouse-last-symbol-bounds)
                  (< pos (car eldoc-mouse-last-symbol-bounds))
                  (> pos (cdr eldoc-mouse-last-symbol-bounds))))
     (eldoc-mouse--hide-posframe)
     (when (fboundp 'eglot--highlight-piggyback)
-      (remove-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback
-                   t))
+      (remove-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback 
t))
     (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)
+      (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))
+      (setq-local eldoc-mouse-last-symbol-bounds (bounds-of-thing-at-point 
'symbol))
       ;; Use (nth 4 (syntax-ppss)) to check if the mouse is over a code 
comment.
       ;; based on the answer from
       ;; https://emacs.stackexchange.com/questions/14269/14270#14270
-      (when (and eldoc-mouse-last-symbol-bounds
-                 (not (eolp))
-                 (not (nth 4 (syntax-ppss))))
+      (when (and eldoc-mouse-last-symbol-bounds (not (eolp)) (not (nth 4 
(syntax-ppss))))
         (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)))
+                     (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)
+      (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)))))
+        (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback 
nil t)))))
 
 (defun eldoc-mouse--hide-posframe ()
   "Hide the posframe."
@@ -270,9 +237,7 @@ POS is the buffer position under the mouse cursor."
       (when eldoc-mouse-mouse-timer
         (cancel-timer eldoc-mouse-mouse-timer))
       (setq eldoc-mouse-mouse-timer
-            (run-with-idle-timer
-             eldoc-mouse-idle-time nil #'eldoc-mouse-show-doc-at
-             pos)))))
+            (run-with-idle-timer eldoc-mouse-idle-time nil 
#'eldoc-mouse-show-doc-at pos)))))
 
 (defun eldoc-mouse-hover-eldoc-function (cb)
   "Modify the `eglot-hover-eldoc-function'.
@@ -288,11 +253,9 @@ So it won't call `eglot--highlight-piggyback` with `CB`."
 Remove all eglot hooks and keep highlighting on cursor,
 add eldoc-mouse's `eldoc-display-functions'."
   (setq-local eldoc-display-functions
-              (append
-               eldoc-display-functions '(eldoc-mouse-display-in-posframe)))
+              (append eldoc-display-functions 
'(eldoc-mouse-display-in-posframe)))
   ;; Avoid unnecessary document of signatures that clutters the document.
-  (remove-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function
-               t)
+  (remove-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function 
t)
   ;; Avoid show document for the cursor.
   (remove-hook 'eldoc-documentation-functions #'eglot-hover-eldoc-function t)
   ;; Enable highlight symbol under the cursor.
@@ -300,12 +263,9 @@ add eldoc-mouse's `eldoc-display-functions'."
   ;; as emacs use a specific function eglot-highlight-eldoc-function
   ;; for highlighting.
   ;; And here, we want to keep the highlight at cursor.
-  ;; See details:
-  ;; 
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=60166a419f601b413db86ddce186cc387e8ec269
+  ;; see details: 
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=60166a419f601b413db86ddce186cc387e8ec269
   (when (fboundp 'eglot--highlight-piggyback)
-    (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback
-              nil
-              t)))
+    (add-hook 'eldoc-documentation-functions #'eglot--highlight-piggyback nil 
t)))
 
 (defun eldoc-mouse-is-mouse-hovering-posframe? (posframe-name)
   "Check if the mouse is hovering over the given posframe `POSFRAME-NAME'."

Reply via email to