├── README.md ├── doc └── screenshots.png └── flycheck-indicator.el /README.md: -------------------------------------------------------------------------------- 1 | # flycheck-indicator 2 | 3 | [![MELPA](https://melpa.org/packages/flycheck-indicator-badge.svg)](https://melpa.org/#/flycheck-indicator) 4 | 5 | An Emacs minor-mode to get a fancy mode line indicator 6 | for [Flycheck](https://github.com/flycheck/flycheck). 7 | 8 | # Configuration 9 | 10 | ## Manual 11 | 12 | ``` 13 | (require 'flycheck-indicator) 14 | 15 | (eval-after-load "flycheck" 16 | '(add-hook 'flycheck-mode-hook 'flycheck-indicator-mode)) 17 | ``` 18 | 19 | ## With use-package 20 | 21 | ``` 22 | (use-package flycheck-indicator 23 | :hook (flycheck-mode . flycheck-indicator-mode)) 24 | ``` 25 | 26 | # Customization 27 | 28 | The icons and faces can be customized in the customization group `flycheck-indicator`: 29 | 30 | ``` 31 | M-x customize-group 32 | flycheck-indicator 33 | ``` 34 | 35 | # Examples 36 | 37 | Here are some screenshots of the indicator in all the possible statuses with default (left) and customized (right) status icon 38 | with [Solarized theme](https://ethanschoonover.com/solarized/). 39 | 40 | ![Fancy indicators](doc/screenshots.png) 41 | -------------------------------------------------------------------------------- /doc/screenshots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gexplorer/flycheck-indicator/e00d9a20cbc21d6814c27cc9206296da394478e8/doc/screenshots.png -------------------------------------------------------------------------------- /flycheck-indicator.el: -------------------------------------------------------------------------------- 1 | ;;; flycheck-indicator.el --- A fancy mode line indicator for `flycheck-mode' 2 | 3 | ;; Author: Eder Elorriaga 4 | ;; URL: https://github.com/gexplorer/flycheck-indicator 5 | ;; Keywords: convenience language tools 6 | ;; Version: 1.1 7 | ;; Package-Requires: ((flycheck "0.15")) 8 | 9 | ;; This program is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Commentary: 23 | 24 | ;; Colorized mode line indicator with icons to display the `flycheck-mode' status. 25 | ;; 26 | ;; This package provides the `flycheck-indicator-mode' minor mode which 27 | ;; displays a colorized mode line with icons for `flycheck-mode' status. 28 | ;; 29 | ;; To enable this mode in Flycheck, add it to `flycheck-mode-hook': 30 | ;; 31 | ;; (add-hook 'flycheck-mode-hook 'flycheck-indicator-mode) 32 | 33 | ;;; Code: 34 | 35 | (require 'flycheck) 36 | 37 | ;;; Customization 38 | 39 | (defgroup flycheck-indicator nil 40 | "A fancy mode line indicator for `flycheck-mode'." 41 | :prefix "flycheck-indicator-" 42 | :group 'flycheck) 43 | 44 | (defgroup flycheck-indicator-faces nil 45 | "Faces used by `flycheck-indicator-mode'." 46 | :prefix "flycheck-indicator-" 47 | :group 'flycheck-indicator) 48 | 49 | (defface flycheck-indicator-disabled '((t :inherit font-lock-comment-face)) 50 | "Disabled indicator face." 51 | :group 'flycheck-indicator-faces) 52 | 53 | (defface flycheck-indicator-running '((t :inherit font-lock-keyword-face)) 54 | "Running indicator face." 55 | :group 'flycheck-indicator-faces) 56 | 57 | (defface flycheck-indicator-success'((t :inherit font-lock-builtin-face)) 58 | "Success indicator face." 59 | :group 'flycheck-indicator-faces) 60 | 61 | (defface flycheck-indicator-error '((t :inherit flycheck-error-list-error)) 62 | "Error indicator face." 63 | :group 'flycheck-indicator-faces) 64 | 65 | (defface flycheck-indicator-warning '((t :inherit flycheck-error-list-warning)) 66 | "Warning indicator face." 67 | :group 'flycheck-indicator-faces) 68 | 69 | (defface flycheck-indicator-info '((t :inherit flycheck-error-list-checker-name)) 70 | "Info indicator face." 71 | :group 'flycheck-indicator-faces) 72 | 73 | (defcustom flycheck-indicator-icon-error ?· 74 | "The character used for errors indicator." 75 | :group 'flycheck-indicator 76 | :type 'character) 77 | 78 | (defcustom flycheck-indicator-icon-warning ?· 79 | "The character used for warnings indicator." 80 | :group 'flycheck-indicator 81 | :type 'character) 82 | 83 | (defcustom flycheck-indicator-icon-info ?· 84 | "The character used for info indicator." 85 | :group 'flycheck-indicator 86 | :type 'character) 87 | 88 | (defcustom flycheck-indicator-status-icons nil 89 | "The characters used for status icons." 90 | :group 'flycheck-indicator 91 | :type '(alist :key-type (choice 92 | (const :tag "Not checked" not-checked) 93 | (const :tag "No checker" no-checker) 94 | (const :tag "Running" running) 95 | (const :tag "Errored" errored) 96 | (const :tag "Finished" finished) 97 | (const :tag "Interrupted" interrupted) 98 | (const :tag "Suspicious" suspicious)) 99 | :value-type string) 100 | :package-version '(flycheck-indicator-mode . "1.1")) 101 | 102 | (defvar flycheck-indicator-status-help 103 | '((not-checked . "The current buffer was not checked.") 104 | (no-checker . "Automatic syntax checker selection did not find a suitable syntax checker.") 105 | (running . "A syntax check is now running in the current buffer.") 106 | (errored . "The current syntax check has errored.") 107 | (finished . "The current syntax check was finished normally.") 108 | (interrupted . "The current syntax check was interrupted.") 109 | (suspicious . "The last syntax check had a suspicious result."))) 110 | 111 | (defvar flycheck-indicator-status-faces 112 | '((not-checked . flycheck-indicator-disabled) 113 | (no-checker . flycheck-indicator-disabled) 114 | (running . flycheck-indicator-running) 115 | (finished . flycheck-indicator-success) 116 | (errored . flycheck-indicator-error) 117 | (interrupted . flycheck-indicator-error) 118 | (suspicious . flycheck-indicator-error))) 119 | 120 | (defvar flycheck-indicator-old-mode-line nil 121 | "The former value of `flycheck-mode-line'.") 122 | 123 | (defvar flycheck-indicator--mode-line 124 | '(:eval (flycheck-indicator--mode-line)) 125 | "The fancy value of `flycheck-mode-line'.") 126 | 127 | (defun flycheck-indicator--mode-line () 128 | "The fancy formatter of `flycheck-mode-line'." 129 | (let-alist (flycheck-count-errors flycheck-current-errors) 130 | (let* ((status flycheck-last-status-change) 131 | (info (or .info 0)) 132 | (warnings (or .warning 0)) 133 | (errors (or .error 0))) 134 | (flycheck-indicator--formatter info warnings errors status)))) 135 | 136 | ;;; Utility functions 137 | (defun flycheck-indicator--formatter (info warnings errors status) 138 | "Get a colorized text for STATUS with INFO WARNINGS and ERRORS." 139 | (if (or (not (equal status 'finished)) 140 | (= 0 (+ info warnings errors))) 141 | (flycheck-indicator--status-formatter status) 142 | (flycheck-indicator--icons-formatter info warnings errors))) 143 | 144 | (defun flycheck-indicator--status-formatter (status) 145 | "Get a colorized text for STATUS." 146 | (let ((icon (alist-get status flycheck-indicator-status-icons (symbol-name status))) 147 | (help-message (alist-get status flycheck-indicator-status-help)) 148 | (face (alist-get status flycheck-indicator-status-faces))) 149 | (propertize 150 | (format " %s" icon) 151 | 'font-lock-face face 152 | 'help-echo (concat help-message "\nmouse-1: Check Show the error list for the current buffer.") 153 | 'local-map (let ((map (make-sparse-keymap))) 154 | (define-key map [mode-line mouse-1] 155 | 'flycheck-list-errors) 156 | map) 157 | 'mouse-face 'mode-line-highlight))) 158 | 159 | (defun flycheck-indicator--icons-formatter (info warnings errors) 160 | "Get colorized icons for INFO WARNINGS and ERRORS." 161 | (propertize (concat 162 | (when (> info 0) 163 | (propertize (format " %c%s" flycheck-indicator-icon-info info) 164 | 'font-lock-face 'flycheck-indicator-info)) 165 | (when (> warnings 0) 166 | (propertize (format " %c%s" flycheck-indicator-icon-warning warnings) 167 | 'font-lock-face 'flycheck-indicator-warning)) 168 | (when (> errors 0) 169 | (propertize (format " %c%s" flycheck-indicator-icon-error errors) 170 | 'font-lock-face 'flycheck-indicator-error))) 171 | 'help-echo (concat (when (> errors 0) (format "%s errors\n" errors)) 172 | (when (> warnings 0) (format "%s warnings\n" warnings)) 173 | (when (> info 0) (format "%s infos\n" info)) 174 | "mouse-1: Check whether Flycheck can be used in this buffer.") 175 | 'local-map (let ((map (make-sparse-keymap))) 176 | (define-key map [mode-line mouse-1] 177 | 'flycheck-verify-setup) 178 | map) 179 | 'mouse-face 'mode-line-highlight)) 180 | 181 | ;;;###autoload 182 | (define-minor-mode flycheck-indicator-mode 183 | "Minor mode to get a fancy mode line indicator for `flycheck-mode'. 184 | 185 | When called interactively, toggle 186 | `flycheck-indicator-mode'. With prefix ARG, enable 187 | `flycheck-indicator-mode' if ARG is positive, otherwise 188 | disable it. 189 | 190 | When called from Lisp, enable `flycheck-indicator-mode' if ARG is omitted, 191 | nil or positive. If ARG is `toggle', toggle `flycheck-indicator-mode'. 192 | Otherwise behave as if called interactively." 193 | :init-value nil 194 | :keymap nil 195 | :lighter nil 196 | :group 'flycheck-indicator 197 | :global t 198 | (cond 199 | ((and flycheck-indicator-mode 200 | (not (eq flycheck-mode-line flycheck-indicator--mode-line))) 201 | (setq flycheck-indicator-old-mode-line flycheck-mode-line) 202 | (setq flycheck-mode-line flycheck-indicator--mode-line)) 203 | ((and (not flycheck-indicator-mode) 204 | (eq flycheck-mode-line flycheck-indicator--mode-line)) 205 | (setq flycheck-mode-line flycheck-indicator-old-mode-line) 206 | (setq flycheck-indicator-old-mode-line nil)))) 207 | 208 | (provide 'flycheck-indicator) 209 | ;;; flycheck-indicator.el ends here 210 | --------------------------------------------------------------------------------