diff --git a/modules/feature/syntax-checker/autoload.el b/modules/feature/syntax-checker/autoload.el new file mode 100644 index 000000000..6a2d310ae --- /dev/null +++ b/modules/feature/syntax-checker/autoload.el @@ -0,0 +1,41 @@ +;;; feature/syntax-checker/autoload.el -*- lexical-binding: t; -*- + +(defun +syntax-checker-show-popup (errors) + "TODO" + (if (and EMACS26+ (display-graphic-p)) + (flycheck-posframe-show-posframe errors) + (flycheck-popup-tip-show-popup errors))) + +(defun +syntax-checker-cleanup-popup () + "TODO" + (when (display-graphic-p) + (flycheck-popup-tip-delete-popup))) + +;;;###autoload +(define-minor-mode +syntax-checker-popup-mode + "TODO" + :lighter nil + :group 'doom + (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 +syntax-checker-popup-mode + (not (eq flycheck-display-errors-function + #'+syntax-checker-show-popup))) + (setq flycheck-popup-tip-old-display-function + flycheck-display-errors-function + flycheck-display-errors-function + #'+syntax-checker-show-popup) + (dolist (hook hooks) + (add-hook hook #'+syntax-checker-cleanup-popup nil t))) + ;; Reset the display function and remove ourselves from all hooks but only + ;; if the mode is still active. + ((and (not +syntax-checker-popup-mode) + (eq flycheck-display-errors-function + #'+syntax-checker-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 '+syntax-checker-cleanup-popup t)))))) diff --git a/modules/feature/syntax-checker/config.el b/modules/feature/syntax-checker/config.el index 2bb95189b..a0e14074e 100644 --- a/modules/feature/syntax-checker/config.el +++ b/modules/feature/syntax-checker/config.el @@ -10,6 +10,9 @@ ;; Emacs feels snappier without checks on newline (setq flycheck-check-syntax-automatically '(save idle-change mode-enabled)) + ;; Popup + (add-hook 'flycheck-mode-hook #'+syntax-checker-popup-mode) + (after! evil (defun +syntax-checkers|flycheck-buffer () "Flycheck buffer on ESC in normal mode." @@ -25,26 +28,10 @@ (delq 'idle-change flycheck-check-syntax-automatically))) -;; Long story short, `flycheck-popup-tip' works everywhere but only looks *ok*. -;; `flycheck-pos-tip' looks great, but only in GUI Emacs on Linux. So we want: -;; -;; + GUI Emacs (Linux): pos-tip -;; + GUI Emacs (MacOS): popup-tip -;; + tty Emacs (anywhere): popup-tip - -(def-package! flycheck-pos-tip - :unless IS-MAC - :after flycheck - :config - (setq flycheck-pos-tip-timeout 10 - ;; fallback to flycheck-popup-tip in terminal Emacs - flycheck-pos-tip-display-errors-tty-function - #'flycheck-popup-tip-show-popup - flycheck-display-errors-delay 0.7) - (flycheck-pos-tip-mode)) - (def-package! flycheck-popup-tip - :commands (flycheck-popup-tip-mode flycheck-popup-tip-show-popup) - :after flycheck - :config (if IS-MAC (flycheck-popup-tip-mode))) + :commands (flycheck-popup-tip-show-popup flycheck-popup-tip-delete-popup)) + +(def-package! flycheck-posframe + :when EMACS26+ + :commands flycheck-posframe-show-posframe) diff --git a/modules/feature/syntax-checker/packages.el b/modules/feature/syntax-checker/packages.el index 46532dabd..d80746c82 100644 --- a/modules/feature/syntax-checker/packages.el +++ b/modules/feature/syntax-checker/packages.el @@ -2,5 +2,6 @@ ;;; feature/syntax-checker/packages.el (package! flycheck) -(package! flycheck-pos-tip) (package! flycheck-popup-tip) +(when EMACS26+ + (package! flycheck-posframe))