From 7361e05582e3ee13dd8ca55a5ddaa02d85470b65 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 26 Feb 2019 18:25:52 -0500 Subject: [PATCH] tools/flycheck: refactor popup-tip minor mode Less code, fewer problems. --- modules/tools/flycheck/autoload.el | 50 +++++++----------------------- modules/tools/flycheck/config.el | 11 ++++--- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/modules/tools/flycheck/autoload.el b/modules/tools/flycheck/autoload.el index 0d4e3e54e..bfc65a51f 100644 --- a/modules/tools/flycheck/autoload.el +++ b/modules/tools/flycheck/autoload.el @@ -1,52 +1,24 @@ ;;; tools/flycheck/autoload.el -*- lexical-binding: t; -*- -(defun +flycheck-show-popup (errors) - "TODO" - (if (and EMACS26+ - (featurep! +childframe) - (display-graphic-p)) - (flycheck-posframe-show-posframe errors) - (flycheck-popup-tip-show-popup errors))) - -(defun +flycheck-cleanup-popup () +;;;###autoload +(defun +flycheck*popup-tip-delete-popup (orig-fn) "TODO" (when (display-graphic-p) - (flycheck-popup-tip-delete-popup))) + (funcall orig-fn))) ;;;###autoload -(define-minor-mode +flycheck-popup-mode +(defun +flycheck*popup-tip-show-popup (orig-fn errors) "TODO" - :lighter nil - :group 'doom - (require 'flycheck-popup-tip) - (let ((hooks '(post-command-hook focus-out-hook))) - (cond - ;; Use our display function and remember the old one but only if we haven't - ;; yet configured it, to avoid activating twice. - ((and +flycheck-popup-mode - (not (eq flycheck-display-errors-function - #'+flycheck-show-popup))) - (setq flycheck-popup-tip-old-display-function - flycheck-display-errors-function - flycheck-display-errors-function - #'+flycheck-show-popup) - (dolist (hook hooks) - (add-hook hook #'+flycheck-cleanup-popup nil t))) - ;; Reset the display function and remove ourselves from all hooks but only - ;; if the mode is still active. - ((and (not +flycheck-popup-mode) - (eq flycheck-display-errors-function - #'+flycheck-show-popup)) - (setq flycheck-display-errors-function - flycheck-popup-tip-old-display-function - flycheck-popup-tip-old-display-function nil) - (dolist (hook hooks) - (remove-hook hook '+flycheck-cleanup-popup t)))))) + (if (and EMACS26+ + (featurep 'flycheck-posframe) + (display-graphic-p)) + (flycheck-posframe-show-posframe errors) + (funcall orig-fn errors))) ;;;###autoload -(defun +flycheck|disable-popup-mode-for-lsp () +(defun +flycheck|disable-popup-tip-for-lsp () "Disable `+flycheck-popup-mode' if `lsp-ui-mode' and `lsp-ui-sideline-enable' are non-nil." (when (and (bound-and-true-p lsp-ui-mode) lsp-ui-sideline-enable) - (+flycheck-popup-mode -1))) + (flycheck-popup-tip-mode -1))) diff --git a/modules/tools/flycheck/config.el b/modules/tools/flycheck/config.el index 0c080c363..c3983261a 100644 --- a/modules/tools/flycheck/config.el +++ b/modules/tools/flycheck/config.el @@ -32,11 +32,14 @@ (def-package! flycheck-popup-tip :commands (flycheck-popup-tip-show-popup flycheck-popup-tip-delete-popup) - :init - (add-hook 'flycheck-mode-hook #'+flycheck-popup-mode) - (add-hook 'lsp-ui-mode-hook #'+flycheck|disable-popup-mode-for-lsp) + :hook (flycheck-mode . flycheck-popup-tip-mode) + :init (add-hook 'lsp-ui-mode-hook #'+flycheck|disable-popup-tip-for-lsp) :config - (setq flycheck-popup-tip-error-prefix "✕ ")) + (setq flycheck-popup-tip-error-prefix "✕ ") + ;; Allow `flycheck-posframe' or `flycheck-popup-tip' to co-exist + ;; interchangibly, depending on the display device (terminal or GUI Emacs). + (advice-add #'flycheck-popup-tip-show-popup :around #'+flycheck*popup-tip-show-popup) + (advice-add #'flycheck-popup-tip-delete-popup :around #'+flycheck*popup-tip-delete-popup)) (def-package! flycheck-posframe