|
7 | 7 | ;; Description: Show flycheck errors with sideline |
8 | 8 | ;; Keyword: sideline flycheck |
9 | 9 | ;; Version: 0.1.0 |
10 | | -;; Package-Requires: ((emacs "26.1") (flycheck "0.14") (sideline "0.1.0")) |
| 10 | +;; Package-Requires: ((emacs "26.1") (sideline "0.1.0") (flycheck "0.14")) |
11 | 11 | ;; URL: https://github.com/jcs-elpa/sideline-flycheck |
12 | 12 |
|
13 | 13 | ;; This file is NOT part of GNU Emacs. |
|
34 | 34 |
|
35 | 35 | (require 'cl-lib) |
36 | 36 |
|
37 | | -(require 'flycheck) |
38 | 37 | (require 'sideline) |
| 38 | +(require 'flycheck) |
39 | 39 |
|
40 | 40 | (defgroup sideline-flycheck nil |
41 | 41 | "Show flycheck errors with sideline." |
|
54 | 54 | (defvar-local sideline-flycheck--callback nil |
55 | 55 | "Callback to display errors with sideline.") |
56 | 56 |
|
57 | | -(defun sideline-flycheck--get-candidates (callback &rest _) |
58 | | - "Asynchronous get flycheck errors." |
59 | | - (setq sideline-flycheck--callback callback)) |
60 | | - |
61 | | -(defun sideline-flycheck--show (errors) |
62 | | - "Display ERRORS, using sideline.el library." |
63 | | - (when (and errors |
64 | | - (not (run-hook-with-args-until-success 'sideline-flycheck-inhibit-functions)) |
65 | | - sideline-flycheck--callback) |
66 | | - (funcall sideline-flycheck--callback (mapcar #'flycheck-error-message errors)))) |
| 57 | +(defvar-local sideline-flycheck--cleared-p nil |
| 58 | + "Set to t when ready to do next rendering in sideline.") |
67 | 59 |
|
68 | 60 | ;;;###autoload |
69 | 61 | (defun sideline-flycheck (command) |
70 | 62 | "Backend for sideline. |
71 | 63 |
|
72 | 64 | Argument COMMAND is required in sideline backend." |
73 | 65 | (cl-case command |
74 | | - (`candidates (cons :async #'sideline-flycheck--get-candidates)))) |
| 66 | + (`candidates (cons :async |
| 67 | + (lambda (callback &rest _) |
| 68 | + (setq sideline-flycheck--callback callback)))))) |
| 69 | + |
| 70 | +(defun sideline-flycheck--show (errors) |
| 71 | + "Display ERRORS, using sideline.el library." |
| 72 | + (when (and errors |
| 73 | + (not (run-hook-with-args-until-success 'sideline-flycheck-inhibit-functions)) |
| 74 | + sideline-flycheck--callback |
| 75 | + sideline-flycheck--cleared-p) |
| 76 | + (setq sideline-flycheck--cleared-p nil) |
| 77 | + (funcall sideline-flycheck--callback (mapcar #'flycheck-error-message errors)))) |
| 78 | + |
| 79 | +(defun sideline-flycheck--reset () |
| 80 | + "After sideline is reset." |
| 81 | + (setq sideline-flycheck--cleared-p t)) |
75 | 82 |
|
76 | 83 | ;;;###autoload |
77 | | -(define-minor-mode sideline-flycheck-mode |
78 | | - "A minor mode to show Flycheck error messages in a sideline." |
79 | | - :lighter nil |
80 | | - :group 'sideline-flycheck |
| 84 | +(defun sideline-flycheck-setup () |
| 85 | + "Setup for `flycheck-mode'." |
81 | 86 | (cond |
82 | | - ;; Use our display function and remember the old one but only if we haven't |
83 | | - ;; yet configured it, to avoid activating twice. |
84 | | - ((and sideline-flycheck-mode |
85 | | - (not (eq flycheck-display-errors-function #'sideline-flycheck--show))) |
| 87 | + (flycheck-mode |
86 | 88 | (setq sideline-flycheck--old-display-function flycheck-display-errors-function) |
87 | | - (setq-local flycheck-display-errors-function #'sideline-flycheck--show)) |
88 | | - ;; Reset the display function and remove ourselves from all hooks but only |
89 | | - ;; if the mode is still active. |
90 | | - ((and (not sideline-flycheck-mode) |
91 | | - (eq flycheck-display-errors-function #'sideline-flycheck--show)) |
| 89 | + (setq-local flycheck-display-errors-function #'sideline-flycheck--show) |
| 90 | + (add-hook 'sideline-reset-hook #'sideline-flycheck--reset nil t)) |
| 91 | + (t |
92 | 92 | (setq-local flycheck-display-errors-function sideline-flycheck--old-display-function) |
93 | | - (setq sideline-flycheck--old-display-function nil)))) |
| 93 | + (setq sideline-flycheck--old-display-function nil) |
| 94 | + (remove-hook 'sideline-reset-hook #'sideline-flycheck--reset t) |
| 95 | + (sideline-render)))) ; rerender sideline once |
94 | 96 |
|
95 | 97 | (provide 'sideline-flycheck) |
96 | 98 | ;;; sideline-flycheck.el ends here |
0 commit comments