From b90780c93c6af45b3cf30caa8817d96e0e30e36e Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 5 May 2022 17:22:23 -0700 Subject: [PATCH] Do not require eglot at compile time This fixes #46, reverts c18023132d223e78408db519bedd00d41bcfbed9. Moved eglot-related functions into a (eval-and-compile (when (require 'eglot nil t))) form. * eldoc-box.el (require): Remove eglot requires. --- eldoc-box.el | 72 +++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 9c99aa2..f770e01 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -40,11 +40,6 @@ (require 'cl-lib) (require 'seq) -;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Compiling-Macros.html -(eval-when-compile - (require 'jsonrpc) - (require 'eglot)) - ;;;; Userland ;;;;; Variable (defgroup eldoc-box nil @@ -451,43 +446,46 @@ You can use \[keyboard-quit] to hide the doc." ;;;; Eglot helper -(defvar eldoc-box-eglot-help-at-point-last-point 0 - "This point cache is used by clean up function. +(eval-and-compile + (require 'jsonrpc) + (when (require 'eglot nil t) + (defvar eldoc-box-eglot-help-at-point-last-point 0 + "This point cache is used by clean up function. If (point) != last point, cleanup frame.") -(defun eldoc-box--eglot-help-at-point-cleanup () - "Try to clean up the childframe made by eldoc-box hack." - (if (or (eq (point) eldoc-box-eglot-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--eglot-help-at-point-cleanup) - (eldoc-box-quit-frame))) + (defun eldoc-box--eglot-help-at-point-cleanup () + "Try to clean up the childframe made by eldoc-box hack." + (if (or (eq (point) eldoc-box-eglot-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--eglot-help-at-point-cleanup) + (eldoc-box-quit-frame))) -(defvar eglot--managed-mode) -(declare-function eglot--dbind "eglot.el") -(declare-function eglot--hover-info "eglot.el") -(declare-function eglot--current-server-or-lose "eglot.el") -(declare-function eglot--TextDocumentPositionParams "eglot.el") -(declare-function eglot--error "eglot.el") -(declare-function jsonrpc-request "jsonrpc") + (defvar eglot--managed-mode) + (declare-function eglot--dbind "eglot.el") + (declare-function eglot--hover-info "eglot.el") + (declare-function eglot--current-server-or-lose "eglot.el") + (declare-function eglot--TextDocumentPositionParams "eglot.el") + (declare-function eglot--error "eglot.el") + (declare-function jsonrpc-request "jsonrpc") -(defun eldoc-box-eglot-help-at-point () - "Display documentation of the symbol at point." - (interactive) - (when eglot--managed-mode - (let ((eldoc-box-position-function #'eldoc-box--default-at-point-position-function)) - (let ((hover-info - (eglot--dbind ((Hover) contents range) - (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover - (eglot--TextDocumentPositionParams)) - (when (seq-empty-p contents) (eglot--error "No hover info here")) - (eglot--hover-info contents range)))) - (if hover-info - (eldoc-box--display hover-info) - (eglot--error "No hover info here")))) - (setq eldoc-box-eglot-help-at-point-last-point (point)) - (run-with-timer 0.1 nil #'eldoc-box--eglot-help-at-point-cleanup))) + (defun eldoc-box-eglot-help-at-point () + "Display documentation of the symbol at point." + (interactive) + (when eglot--managed-mode + (let ((eldoc-box-position-function #'eldoc-box--default-at-point-position-function)) + (let ((hover-info + (eglot--dbind ((Hover) contents range) + (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover + (eglot--TextDocumentPositionParams)) + (when (seq-empty-p contents) (eglot--error "No hover info here")) + (eglot--hover-info contents range)))) + (if hover-info + (eldoc-box--display hover-info) + (eglot--error "No hover info here")))) + (setq eldoc-box-eglot-help-at-point-last-point (point)) + (run-with-timer 0.1 nil #'eldoc-box--eglot-help-at-point-cleanup))))) ;;;; Comany compatibility ;;