branch: elpa/eldoc-mouse
commit d1f3ed2a72fe9625644025dfe9fc651a7f0d7773
Author: huangfeiyu <[email protected]>
Commit: GitHub <[email protected]>
improve compatibility to eldoc.
---
eldoc-mouse.el | 109 ++++++++++++++++++---------------------------------------
1 file changed, 34 insertions(+), 75 deletions(-)
diff --git a/eldoc-mouse.el b/eldoc-mouse.el
index b9baba53859..05021f6b060 100644
--- a/eldoc-mouse.el
+++ b/eldoc-mouse.el
@@ -117,19 +117,14 @@ A leading space make the buffer hidden."
(defvar-local eldoc-mouse--doc-identifier "*^eldoc-mouse*^"
"The identifier used for distinguish the doc triggered by eldoc-mouse.")
-(defvar eldoc-mouse--eldoc-documentation-functions
- '(eldoc-mouse--eglot-eldoc-documentation-function
- eldoc-mouse--elisp-eldoc-documentation-function)
+(defvar-local eldoc-mouse--eldoc-documentation-functions
+ (list #'eldoc-mouse--eglot-eldoc-documentation-function
#'eldoc-mouse--elisp-eldoc-documentation-function)
"The `eldoc-documentation-functions' for `eldoc-mouse-mode'.")
-(defvar-local eldoc-mouse--original-documentation-functions nil
- "The original eldoc-documentation-fuctions.")
-
;;;###autoload
(define-minor-mode eldoc-mouse-mode
"Toggle the `eldoc-mouse-mode'."
:lighter " eldoc-mouse"
-
(if eldoc-mouse-mode
(eldoc-mouse-enable)
(eldoc-mouse-disable)))
@@ -139,12 +134,8 @@ A leading space make the buffer hidden."
"Show document at the cursor."
(interactive)
(eldoc-mouse--hide-posframe)
- (when-let* ((symbol-bounds (bounds-of-thing-at-point 'symbol)))
- (setq-local eldoc-mouse--original-documentation-functions
eldoc-documentation-functions)
- (setq-local eldoc-documentation-functions nil)
- (dolist (fun-sym eldoc-mouse--eldoc-documentation-functions)
- (advice-add fun-sym :around #'eldoc-mouse--hover-edloc-function-advise)
- (add-hook 'eldoc-documentation-functions (symbol-function fun-sym) nil
t))
+ (when-let* ((symbol-bounds (bounds-of-thing-at-point 'symbol))
+ (eldoc-documentation-functions
(eldoc-mouse--eldoc-documentation-functions)))
(setq-local eldoc-mouse-last-symbol-bounds symbol-bounds)
(when (not eldoc-mouse-mode)
(unless eldoc-mouse--original-display-functions
@@ -153,10 +144,7 @@ A leading space make the buffer hidden."
(append
eldoc-display-functions
'(eldoc-mouse-display-in-posframe))))
(setq eldoc--last-request-state nil)
- (eldoc-print-current-symbol-info)
- (dolist (fun-sym eldoc-mouse--eldoc-documentation-functions)
- (advice-remove fun-sym #'eldoc-mouse--hover-edloc-function-advise))
- (setq-local eldoc-documentation-functions
eldoc-mouse--original-documentation-functions)))
+ (eldoc-print-current-symbol-info)))
(defun eldoc-mouse-enable ()
"Enable eldoc-mouse in buffers."
@@ -166,22 +154,7 @@ A leading space make the buffer hidden."
(setq-local eldoc-display-functions
(append
eldoc-display-functions '(eldoc-mouse-display-in-posframe)))
- (local-set-key [mouse-movement] #'eldoc-mouse-doc-on-mouse)
-
- ;; Optimization for eglot managed buffers.
- (when (eglot-managed-p)
- ;; Avoid unnecessary document of signatures that clutters the document.
- (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.
- ;; And here, we want to keep the highlight at cursor.
- ;; See details:
- ;;
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=60166a419f601b413db86ddce186cc387e8ec269
- (add-hook 'eldoc-documentation-functions #'eldoc-mouse--eglot-highlight
nil t)))
+ (local-set-key [mouse-movement] #'eldoc-mouse-doc-on-mouse))
(defun eldoc-mouse-disable ()
"Disable eldoc-mouse in buffers."
@@ -189,14 +162,6 @@ A leading space make the buffer hidden."
(setq-local eldoc-display-functions
eldoc-mouse--original-display-functions))
- ;; Optimization for eglot managed buffers.
- (when (eglot-managed-p)
- (remove-hook 'eldoc-documentation-functions #'eldoc-mouse--eglot-highlight
t)
- (unless (memq #'eglot-signature-eldoc-function
eldoc-documentation-functions)
- (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)))
-
(when eldoc-mouse-mouse-timer
(cancel-timer eldoc-mouse-mouse-timer)
(setq eldoc-mouse-mouse-timer nil))
@@ -234,29 +199,22 @@ POS is the buffer position under the mouse cursor."
(when eldoc-mouse-mouse-overlay
(delete-overlay eldoc-mouse-mouse-overlay))
(save-excursion
- (setq-local eldoc-mouse--original-documentation-functions
eldoc-documentation-functions)
- (setq-local eldoc-documentation-functions nil)
- (dolist (fun-sym eldoc-mouse--eldoc-documentation-functions)
- (advice-add fun-sym :around #'eldoc-mouse--hover-edloc-function-advise)
- (add-hook 'eldoc-documentation-functions (symbol-function fun-sym) 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 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))))
- (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 'secondary-selection))
- (dolist (fun-sym eldoc-mouse--eldoc-documentation-functions)
- (advice-remove fun-sym #'eldoc-mouse--hover-edloc-function-advise))
- (setq-local eldoc-documentation-functions
eldoc-mouse--original-documentation-functions))))
+ (let ((eldoc-documentation-functions
(eldoc-mouse--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 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))))
+ (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
'secondary-selection))))))
(defun eldoc-mouse--hide-posframe ()
"Hide the posframe."
@@ -308,14 +266,6 @@ So it won't call `eglot--highlight-piggyback` with `CB`."
(t nil)))
nil))
-(defun eldoc-mouse--eglot-highlight (cb)
- "Wrap eglot's highlight function to check if buffer is managed by eglot.
-Argument CB is the callback function."
- (if (and (fboundp 'eglot--highlight-piggyback) (eglot-managed-p))
- (eglot--highlight-piggyback cb)
- nil)
- )
-
(defun eldoc-mouse--hover-edloc-function-advise (orig-fn fn)
"Wrap FN argument of ORIG-FN so that it append indentifier."
(let ((result (funcall orig-fn
@@ -327,6 +277,18 @@ Argument CB is the callback function."
(concat result eldoc-mouse--doc-identifier)
result)))
+(defun eldoc-mouse--eldoc-documentation-functions ()
+ "Get the eldoc documentation functions defined by eldoc-mouse."
+ (let* ((fun-list1 (seq-filter (lambda (f)
+ (and (not (function-equal f
#'eglot-hover-eldoc-function))
+ (not (function-equal f
#'eglot-signature-eldoc-function))))
+ eldoc-documentation-functions))
+ (fun-list2 (append eldoc-mouse--eldoc-documentation-functions
fun-list1)))
+ (mapcar (lambda (fun) (if (functionp fun)
+ (lambda (&rest args) (apply
#'eldoc-mouse--hover-edloc-function-advise fun args))
+ fun))
+ fun-list2)))
+
(defun eldoc-mouse-is-mouse-hovering-posframe? (posframe-name)
"Check if the mouse is hovering over the given posframe `POSFRAME-NAME'."
(let* ((posframe (get-buffer posframe-name)) ;; Get the posframe buffer
@@ -389,7 +351,4 @@ Argument CB is the callback function."
(provide 'eldoc-mouse)
-;; Local Variables:
-;; indent-tabs-mode: nil
-;; End:
;;; eldoc-mouse.el ends here