From c9693eddb01c80cd25919b8f45a074235cb02897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 12 Dec 2018 13:53:33 +0000 Subject: [PATCH 1/4] Play nice with further customizations of eldoc-message-function Uses a :before-until advice on the local value of eldoc-message-function instead of setting it directly. Thus, when we give up because of eldoc-box-only-multi-line (or some other future criteria), other :before-until handlers can kick in. * eldoc-box.el (eldoc-box--eldoc-message-function): Control return of t or nil. (eldoc-box-hover-mode): Use add-function and remove-function. --- eldoc-box.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 806d4d1..7fbb356 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -212,10 +212,10 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." "Frontend for eldoc. Display STR in childframe and ARGS works like `message'." (if (stringp str) (let ((doc (apply #'format str args))) - (if (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0)) - (apply #'eldoc-minibuffer-message str args) + (unless (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0)) (eldoc-box--display (apply #'format str args)))) - (eldoc-box-quit-frame))) + (eldoc-box-quit-frame) + t)) (define-minor-mode eldoc-box-hover-mode "Displays hover documentations in a childframe. This mode is buffer local." @@ -228,8 +228,9 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." (unless eldoc-box--cleanup-timer (setq eldoc-box--cleanup-timer (run-with-idle-timer 1 t #'eldoc-box--maybe-cleanup))) (add-to-list 'eldoc-box--enabled-buffer-list (current-buffer)) - (setq-local eldoc-message-function #'eldoc-box--eldoc-message-function)) - (setq-local eldoc-message-function #'eldoc-minibuffer-message) + (add-function :before-until (local 'eldoc-message-function) + #'eldoc-box--eldoc-message-function)) + (remove-function (local 'eldoc-message-function) #'eldoc-box--eldoc-message-function) (delete (current-buffer) eldoc-box--enabled-buffer-list) ;; this function has to be called after the current buffer is ;; removed from buffer list From 8232e5eb60de7ffb224cd4f651b3e271bd2a73e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 12 Dec 2018 14:16:29 +0000 Subject: [PATCH 2/4] Simplify timer management * eldoc-box.el (eldoc-box--maybe-cleanup): Set timer var to nil unconditionally. (eldoc-box--eldoc-message-function): Rescheduler timer here. (eldoc-box-hover-mode): Simplify. (eldoc-box--maybe-cancel-timer, eldoc-box--enabled-buffer-list): Not needed. --- eldoc-box.el | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 7fbb356..bb82bf4 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -196,24 +196,21 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." ;; shut it off. this code can save you ;; this is gold, right here, you know it my friend? (when (frame-parameter eldoc-box--frame 'visibility) - (eldoc-box-quit-frame)))) - -(defvar eldoc-box--enabled-buffer-list nil - "A list of buffers that enabled `eldoc-box-hover-mode'.") - -(defun eldoc-box--maybe-cancel-timer () - "Cancel `eldoc-box--cleanup-timer' there is no live buffer with `eldoc-box-hover-mode' enabled left." - (when (and eldoc-box--cleanup-timer - (eq (cl-count-if #'buffer-live-p eldoc-box--enabled-buffer-list) 0)) - (cancel-timer eldoc-box--cleanup-timer) - (setq eldoc-box--cleanup-timer nil))) + (eldoc-box-quit-frame))) + (setq eldoc-box--cleanup-timer nil)) (defun eldoc-box--eldoc-message-function (str &rest args) "Frontend for eldoc. Display STR in childframe and ARGS works like `message'." (if (stringp str) (let ((doc (apply #'format str args))) (unless (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0)) - (eldoc-box--display (apply #'format str args)))) + (eldoc-box--display (apply #'format str args)) + ;; Why a timer? ElDoc is mainly use in minibuffer, + ;; where the text is constantly being flushed by other commands + ;; so ElDoc doesn't try very hard to cleanup + (when eldoc-box--cleanup-timer (cancel-timer eldoc-box--cleanup-timer)) + (setq eldoc-box--cleanup-timer + (run-with-timer 1 nil #'eldoc-box--maybe-cleanup)))) (eldoc-box-quit-frame) t)) @@ -221,20 +218,9 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." "Displays hover documentations in a childframe. This mode is buffer local." :lighter " ELDOC-BOX" (if eldoc-box-hover-mode - (progn - ;; Why a timer? ElDoc is mainly use in minibuffer, - ;; where the text is constantly being flushed by other commands - ;; so ElDoc doesn't try very hard to cleanup - (unless eldoc-box--cleanup-timer - (setq eldoc-box--cleanup-timer (run-with-idle-timer 1 t #'eldoc-box--maybe-cleanup))) - (add-to-list 'eldoc-box--enabled-buffer-list (current-buffer)) - (add-function :before-until (local 'eldoc-message-function) - #'eldoc-box--eldoc-message-function)) + (add-function :before-until (local 'eldoc-message-function) + #'eldoc-box--eldoc-message-function) (remove-function (local 'eldoc-message-function) #'eldoc-box--eldoc-message-function) - (delete (current-buffer) eldoc-box--enabled-buffer-list) - ;; this function has to be called after the current buffer is - ;; removed from buffer list - (eldoc-box--maybe-cancel-timer) ;; if minor mode is turned off when childframe is visible ;; hide it (eldoc-box-quit-frame))) From ff11ef939202e75d26c2720ac085070467cbde27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 12 Dec 2018 14:21:43 +0000 Subject: [PATCH 3/4] Shoosh compilation warnings * eldoc-box.el (eldoc-box): New group. (eldoc-box-hover-mode, eldoc-box--frame): Move up in file. compilation warning. --- eldoc-box.el | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index bb82bf4..910665c 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -38,6 +38,10 @@ ;;;; Userland ;;;;; Variable +(defgroup eldoc-box nil + "Display Eldoc docs in a pretty child frame." + :prefix "eldoc-box-" + :group 'eldoc) (defface eldoc-box-border '((((background dark)) . (:background "white")) (((background light)) . (:background "black"))) @@ -95,6 +99,9 @@ (eldoc-box--inject-quit-func)) (message "No documentation available")))) +(defvar eldoc-box--frame nil ;; A backstage variable + "The frame to display doc.") + (defun eldoc-box-quit-frame () "Hide childframe used by eglot doc." (interactive) @@ -104,10 +111,6 @@ ;;;; Backstage ;;;;; Variable - -(defvar eldoc-box--frame nil - "The frame to display doc.") - (defvar eldoc-box--buffer "*eldoc-box*" "The buffer used to display eglot doc.") @@ -181,6 +184,17 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." (setq eldoc-box--frame frame))) ;;;;; ElDoc +(define-minor-mode eldoc-box-hover-mode + "Displays hover documentations in a childframe. This mode is buffer local." + :lighter " ELDOC-BOX" + (if eldoc-box-hover-mode + (add-function :before-until (local 'eldoc-message-function) + #'eldoc-box--eldoc-message-function) + (remove-function (local 'eldoc-message-function) #'eldoc-box--eldoc-message-function) + ;; if minor mode is turned off when childframe is visible + ;; hide it + (eldoc-box-quit-frame))) + (defvar eldoc-box--cleanup-timer nil "The timer used to cleanup childframe after ElDoc.") @@ -214,18 +228,6 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." (eldoc-box-quit-frame) t)) -(define-minor-mode eldoc-box-hover-mode - "Displays hover documentations in a childframe. This mode is buffer local." - :lighter " ELDOC-BOX" - (if eldoc-box-hover-mode - (add-function :before-until (local 'eldoc-message-function) - #'eldoc-box--eldoc-message-function) - (remove-function (local 'eldoc-message-function) #'eldoc-box--eldoc-message-function) - ;; if minor mode is turned off when childframe is visible - ;; hide it - (eldoc-box-quit-frame))) - - (provide 'eldoc-box) ;;; eldoc-box.el ends here From 2d6b9c3765b8b40025ad4872697a05cee9bc2512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 12 Dec 2018 14:24:09 +0000 Subject: [PATCH 4/4] Clean up file header a bit * eldoc-box.el (Copyright): Clear up situation. (Maintainer): New field. (Commentary): Add very brief commentary. --- eldoc-box.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eldoc-box.el b/eldoc-box.el index 910665c..b0f378d 100644 --- a/eldoc-box.el +++ b/eldoc-box.el @@ -1,11 +1,11 @@ ;;; eldoc-box.el --- Display documentation in childframe -*- lexical-binding: t; -*- -;; Copyright (C) 2017 Sebastien Chapuis +;; Copyright (C) 2017-2018 Sebastien Chapuis, 2018 Yuan Fu ;; Version: 1.0 ;; Author: Sebastien Chapuis -;; Yuan Fu made a lot of change to use it for ElDoc +;; Maintainer: Yuan Fu ;; URL: https://github.com/casouri/eldoc-box ;; Package-Requires: ((emacs "26.1")) @@ -30,6 +30,7 @@ ;;; Commentary: ;; +;; Made a lot of change to use it for ElDoc ;;; Code: ;;