tools/flycheck: refactor popup-tip minor mode

Less code, fewer problems.
This commit is contained in:
Henrik Lissner 2019-02-26 18:25:52 -05:00
parent 11a528be04
commit 7361e05582
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395
2 changed files with 18 additions and 43 deletions

View File

@ -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)))

View File

@ -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